├── jdave-core ├── src │ ├── test │ │ └── jdave │ │ │ ├── runner │ │ │ ├── dir with spaces │ │ │ │ └── hack-to-get-maven-copy-this-dir │ │ │ ├── dummies │ │ │ │ ├── Dummy2.java │ │ │ │ ├── sub │ │ │ │ │ └── Dummy3.java │ │ │ │ ├── Dummy1.java │ │ │ │ └── Other.java │ │ │ ├── DummyBehaviorResults.java │ │ │ └── SpecRunnerVisitTest.java │ │ │ ├── tools │ │ │ ├── StackSpec.java │ │ │ ├── SentenceTest.java │ │ │ ├── SpecdoxTest.java │ │ │ └── FileStoreTest.java │ │ │ ├── ByNameComparator.java │ │ │ ├── util │ │ │ ├── CollectionsTest.java │ │ │ └── PrimitivesTest.java │ │ │ ├── containment │ │ │ ├── ContainmentTest.java │ │ │ ├── AllContainmentTest.java │ │ │ ├── ObjectContainmentTest.java │ │ │ └── DuplicatesValuesInExpectedCollectionExactContainmentTest.java │ │ │ ├── ResultsAdapter.java │ │ │ ├── equality │ │ │ └── PrimitiveEqualityTest.java │ │ │ ├── injection │ │ │ └── FieldTest.java │ │ │ ├── contract │ │ │ └── SerializableContractTest.java │ │ │ └── mock │ │ │ ├── ConcreteClassMockingTest.java │ │ │ └── DummyTest.java │ ├── scripts │ │ └── dox2html.sh │ └── java │ │ └── jdave │ │ ├── injection │ │ ├── IFieldInjector.java │ │ ├── ReflectionException.java │ │ └── Field.java │ │ ├── IContract.java │ │ ├── runner │ │ ├── IFileHandler.java │ │ ├── IAnnotatedSpecHandler.java │ │ ├── ISpecVisitor.java │ │ ├── ISpecIntrospection.java │ │ ├── IntrospectionStrategy.java │ │ ├── LineNumberStrategy.java │ │ ├── IBehaviorResults.java │ │ ├── VisitingBehavior.java │ │ ├── Groups.java │ │ ├── ClassLineNumberComparator.java │ │ └── Behavior.java │ │ ├── tools │ │ ├── IDoxStore.java │ │ ├── DoxStoreException.java │ │ ├── IDoxFormat.java │ │ ├── Formats.java │ │ ├── FileStore.java │ │ ├── SpecdoxRunner.java │ │ └── PlainTextFormat.java │ │ ├── IStringComparisonFailure.java │ │ ├── IEqualityCheck.java │ │ ├── util │ │ ├── FluentMap.java │ │ ├── Maps.java │ │ ├── Collections.java │ │ ├── Primitives.java │ │ └── Fields.java │ │ ├── EqualityCheck.java │ │ ├── IContainment.java │ │ ├── ExpectationFailedStringComparisonFailure.java │ │ ├── IContextObjectFactory.java │ │ ├── ExpectationFailedException.java │ │ ├── Group.java │ │ ├── DefaultLifecycleListener.java │ │ ├── ExactExpectedException.java │ │ ├── Where.java │ │ ├── support │ │ └── Assert.java │ │ ├── ExactExpectedExceptionWithMessage.java │ │ ├── ExpectedNoThrow.java │ │ ├── Block.java │ │ ├── mock │ │ └── JDaveErrorTranslator.java │ │ ├── equality │ │ ├── EqualsEqualityCheck.java │ │ ├── NotEqualsEqualityCheck.java │ │ ├── DeltaEqualityCheck.java │ │ └── LongEqualsEqualityCheck.java │ │ ├── NotDeltaEqualityCheck.java │ │ ├── containment │ │ ├── AllContainment.java │ │ ├── NotContainment.java │ │ ├── AnyContainment.java │ │ ├── ObjectContainment.java │ │ ├── ExactContainment.java │ │ └── MapContainment.java │ │ ├── DefaultContextObjectFactory.java │ │ ├── contract │ │ ├── NotContract.java │ │ └── SerializableContract.java │ │ ├── BaseMatcherContainment.java │ │ ├── ExpectedException.java │ │ ├── StringEqualsEqualityCheck.java │ │ └── ILifecycleListener.java └── pom.xml ├── jdave-parent ├── bin │ ├── mvn-assembly │ └── prepare-release.sh ├── RELEASE.txt └── src │ └── assemble │ └── bin.xml ├── jdave-wicket-1.5 └── src │ ├── test │ └── jdave │ │ └── wicket │ │ ├── EmptyPanel.html │ │ ├── PageWithItems.html │ │ ├── EmptyPanel.java │ │ ├── GenerifiedComponentSpec.java │ │ └── EmptyPanelSpec.java │ └── java │ └── jdave │ └── wicket │ ├── Container.html │ ├── AnyModelMatcher.java │ ├── WicketIdEqualsTo.java │ ├── Container.java │ └── ComponentsModelMatchesTo.java ├── jdave-wicket └── src │ ├── test │ └── jdave │ │ └── wicket │ │ ├── EmptyPanel.html │ │ ├── PageWithItems.html │ │ ├── EmptyPanel.java │ │ ├── GenerifiedComponentSpec.java │ │ └── EmptyPanelSpec.java │ └── java │ └── jdave │ └── wicket │ ├── Container.html │ ├── AnyModelMatcher.java │ ├── WicketIdEqualsTo.java │ ├── Container.java │ └── ComponentsModelMatchesTo.java ├── .gitignore ├── jdave-report-plugin ├── src │ └── resources │ │ └── jdave-report.properties ├── .settings │ └── org.eclipse.jdt.core.prefs └── pom.xml ├── README.markdown ├── jdave-wicket-webdriver └── src │ ├── java │ └── jdave │ │ └── webdriver │ │ ├── testapplication │ │ ├── ChildPage.html │ │ ├── WebDriverTestPage.html │ │ ├── ChildPage.java │ │ └── WebDriverApplication.java │ │ ├── elements │ │ ├── Link.java │ │ ├── Count.java │ │ ├── Find.java │ │ ├── WebElements.java │ │ ├── TextBox.java │ │ └── CheckBox.java │ │ ├── WicketWebDriver.java │ │ ├── Sleep.java │ │ ├── WebDriverFactory.java │ │ ├── WebDriverGroupRunner.java │ │ ├── Retry.java │ │ ├── Browser.java │ │ └── WebDriverSpecRunner.java │ ├── test │ ├── log4j.properties │ └── jdave │ │ └── webdriver │ │ ├── testapplication │ │ └── SpecSuite.java │ │ ├── elements │ │ ├── LinkSpec.java │ │ └── WebElementsSpec.java │ │ └── RetrySpec.java │ └── main │ └── webapp │ └── WEB-INF │ └── web.xml ├── jdave-unfinalizer ├── .settings │ └── org.eclipse.jdt.ui.prefs ├── sample-project │ ├── src │ │ ├── test │ │ │ └── java │ │ │ │ └── jdave │ │ │ │ └── unfinalizer │ │ │ │ └── AardvarkTest.java │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── example │ │ │ ├── AClass.java │ │ │ └── AClassWithAMethod.java │ └── buildfile └── src │ ├── java │ └── jdave │ │ └── unfinalizer │ │ ├── internal │ │ ├── JVMHelper.java │ │ ├── UnfinalizingClassVisitorDelegator.java │ │ ├── Filter.java │ │ └── ClassVisitorDelegator.java │ │ └── agent │ │ └── InstrumentationAgent.java │ └── test │ └── jdave │ └── unfinalizer │ ├── fake │ ├── FinalClass.java │ └── ClassWithFinalMethod.java │ └── agent │ └── InstrumentationAgentSpec.java ├── jdave-examples └── src │ ├── java │ └── jdave │ │ └── examples │ │ ├── wicket │ │ ├── DictionaryPanel.html │ │ └── IDictionaryService.java │ │ ├── StackOverflowException.java │ │ └── observer │ │ ├── Observer.java │ │ └── Observable.java │ └── test │ └── jdave │ └── examples │ ├── SuiteForBasicSpecs.java │ ├── SuiteForNonBasicSpecs.java │ ├── ApproximationSampleSpec.java │ ├── Person.java │ └── ObservableSpec.java ├── jdave-junit4 ├── src │ ├── test │ │ └── jdave │ │ │ └── junit4 │ │ │ ├── StackOverflowException.java │ │ │ ├── specs │ │ │ └── DiverseSpec.java │ │ │ └── StringComparisonFailureTest.java │ └── java │ │ └── jdave │ │ └── junit4 │ │ ├── SpecDirs.java │ │ ├── CodeSource.java │ │ └── ResultsAdapter.java └── pom.xml ├── jdave-junit3 ├── pom.xml └── src │ └── test │ └── jdave │ └── junit3 │ ├── JDaveSuiteTest.java │ └── ResultAdapterTest.java └── jdave-guice ├── src └── main │ └── java │ ├── jdave │ └── guice │ │ ├── InterestedInGuice.java │ │ ├── GuiceMock.java │ │ └── InjectorCreator.java │ └── org │ └── mockito │ └── configuration │ └── MockitoConfiguration.java ├── README └── buildfile /jdave-core/src/test/jdave/runner/dir with spaces/hack-to-get-maven-copy-this-dir: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /jdave-parent/bin/mvn-assembly: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | mvn clean package assembly:assembly 4 | -------------------------------------------------------------------------------- /jdave-wicket-1.5/src/test/jdave/wicket/EmptyPanel.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /jdave-wicket/src/test/jdave/wicket/EmptyPanel.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | *.iml 3 | *.iws 4 | *.ipr 5 | .classpath 6 | .project 7 | release.properties 8 | 9 | -------------------------------------------------------------------------------- /jdave-wicket/src/java/jdave/wicket/Container.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /jdave-wicket-1.5/src/java/jdave/wicket/Container.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /jdave-parent/bin/prepare-release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export JAVA_HOME=/usr/java/jdk1.5 4 | export PATH=$JAVA_HOME/bin:$PATH 5 | 6 | mvn release:prepare 7 | -------------------------------------------------------------------------------- /jdave-report-plugin/src/resources/jdave-report.properties: -------------------------------------------------------------------------------- 1 | report.jdave.name=JDave specifications 2 | report.jdave.description=Specifications for the project. 3 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | [JDave][1] is a BDD framework for Java. It is inspired by rspec and integrates JMock 2 as mocking framework and Hamcrest as matching library. It uses JUnit adapter to launch JDave specifications. 2 | 3 | [1]: http://jdave.org/ 4 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/testapplication/ChildPage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Sulje 4 | 5 | -------------------------------------------------------------------------------- /jdave-unfinalizer/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Sun Feb 15 12:50:25 EET 2009 2 | eclipse.preferences.version=1 3 | formatter_profile=_Tuomaisc 4 | formatter_settings_version=11 5 | instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true 6 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/test/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger = ERROR, CONSOLE 2 | 3 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 4 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 6 | 7 | 8 | -------------------------------------------------------------------------------- /jdave-wicket/src/test/jdave/wicket/PageWithItems.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | item 4 | item 5 |
6 |
7 |
8 | 9 | -------------------------------------------------------------------------------- /jdave-wicket-1.5/src/test/jdave/wicket/PageWithItems.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | item 4 | item 5 |
6 |
7 |
8 | 9 | -------------------------------------------------------------------------------- /jdave-report-plugin/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Sat Nov 10 12:15:29 GMT 2007 2 | eclipse.preferences.version=1 3 | instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 5 | org.eclipse.jdt.core.compiler.compliance=1.5 6 | org.eclipse.jdt.core.compiler.source=1.5 7 | -------------------------------------------------------------------------------- /jdave-examples/src/java/jdave/examples/wicket/DictionaryPanel.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | Word:
4 | 5 |
6 | 7 | 8 | 9 | 10 |
11 | -------------------------------------------------------------------------------- /jdave-wicket/src/java/jdave/wicket/AnyModelMatcher.java: -------------------------------------------------------------------------------- 1 | package jdave.wicket; 2 | 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | 6 | /** 7 | * @author Timo Rantalaiho 8 | */ 9 | public class AnyModelMatcher extends BaseMatcher { 10 | public boolean matches(Object o) { 11 | return true; 12 | } 13 | 14 | public void describeTo(Description description) { 15 | description.appendText(" can be any model, even null"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /jdave-wicket-1.5/src/java/jdave/wicket/AnyModelMatcher.java: -------------------------------------------------------------------------------- 1 | package jdave.wicket; 2 | 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | 6 | /** 7 | * @author Timo Rantalaiho 8 | */ 9 | public class AnyModelMatcher extends BaseMatcher { 10 | public boolean matches(Object o) { 11 | return true; 12 | } 13 | 14 | public void describeTo(Description description) { 15 | description.appendText(" can be any model, even null"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /jdave-unfinalizer/sample-project/src/test/java/jdave/unfinalizer/AardvarkTest.java: -------------------------------------------------------------------------------- 1 | package jdave.unfinalizer; 2 | 3 | import jdave.Specification; 4 | import jdave.junit4.JDaveRunner; 5 | 6 | import org.example.AClass; 7 | import org.junit.runner.RunWith; 8 | 9 | @RunWith(JDaveRunner.class) 10 | public class AardvarkTest extends Specification { 11 | public class SomethingThatUsesAFinalClass { 12 | public void beforeUnfinalizerIsRun() { 13 | new AClass(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/elements/Link.java: -------------------------------------------------------------------------------- 1 | package jdave.webdriver.elements; 2 | 3 | import jdave.webdriver.Channel; 4 | 5 | import org.openqa.selenium.WebElement; 6 | 7 | /** 8 | * @author Juha Karemo 9 | */ 10 | public class Link { 11 | private WebElement webElement; 12 | private Channel channel = new Channel(); 13 | 14 | public Link(WebElement webElement) { 15 | this.webElement = webElement; 16 | } 17 | 18 | public void click() { 19 | webElement.click(); 20 | channel.waitForAjax(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jdave-core/src/scripts/dox2html.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Script for converting specdox generated XML documents to html. 4 | # This script uses Saxon 8 but any tool which supports XSLT 2 should work. 5 | # 6 | # Usage: dox2html.sf 7 | # 8 | 9 | if [ -z "$SAXON_HOME" ] ; then 10 | echo "Please set environment variable SAXON_HOME to point to saxon installation dir." 11 | exit 1 12 | fi 13 | 14 | if [ -z "$1" ] ; then 15 | echo "Please give path to directory where XML files are." 16 | exit 1 17 | fi 18 | 19 | PRGDIR=`dirname "$0"` 20 | 21 | echo '' | java -jar $SAXON_HOME/saxon8.jar - $PRGDIR/specdox.xsl spec-file-dir=$1 22 | -------------------------------------------------------------------------------- /jdave-unfinalizer/src/java/jdave/unfinalizer/internal/JVMHelper.java: -------------------------------------------------------------------------------- 1 | package jdave.unfinalizer.internal; 2 | 3 | import java.lang.management.ManagementFactory; 4 | import java.lang.management.RuntimeMXBean; 5 | import java.util.List; 6 | 7 | import com.sun.tools.attach.VirtualMachine; 8 | import com.sun.tools.attach.VirtualMachineDescriptor; 9 | 10 | public class JVMHelper { 11 | public List virtualMachines() { 12 | return VirtualMachine.list(); 13 | } 14 | 15 | public String getCurrentRuntimeName() { 16 | final RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); 17 | final String currentRuntimeName = runtimeMxBean.getName(); 18 | return currentRuntimeName; 19 | } 20 | } -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/elements/Count.java: -------------------------------------------------------------------------------- 1 | package jdave.webdriver.elements; 2 | 3 | import javax.swing.text.html.HTML.Tag; 4 | 5 | import jdave.webdriver.WebDriverHolder; 6 | 7 | import org.openqa.selenium.By; 8 | import org.openqa.selenium.WebElement; 9 | 10 | /** 11 | * @author Juha Karemo 12 | */ 13 | public class Count { 14 | private Tag tag; 15 | 16 | Count(Tag tag) { 17 | this.tag = tag; 18 | } 19 | 20 | public int fromParent(By by) { 21 | WebElement parent = WebDriverHolder.get().findElement(by); 22 | return parent.findElements(By.tagName(tag.toString())).size(); 23 | } 24 | 25 | public static Count of(Tag tag) { 26 | return new Count(tag); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jdave-unfinalizer/sample-project/src/main/java/org/example/AClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package org.example; 17 | 18 | public final class AClass { 19 | } 20 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/runner/dummies/Dummy2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner.dummies; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | @Other 22 | public class Dummy2 { 23 | } 24 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/runner/dummies/sub/Dummy3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner.dummies.sub; 17 | 18 | 19 | /** 20 | * @author Joni Freeman 21 | */ 22 | public class Dummy3 { 23 | } 24 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/testapplication/WebDriverTestPage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | foo 4 | testLabel 5 | testLink 6 | testLink2 7 | 8 | 9 | 10 | 11 |
foo
foo
12 | 13 |
14 | 15 |
16 | 17 | 21 | 22 | open page 23 | 24 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/injection/IFieldInjector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.injection; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public interface IFieldInjector { 22 | void inject(Field field); 23 | } 24 | -------------------------------------------------------------------------------- /jdave-junit4/src/test/jdave/junit4/StackOverflowException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.junit4; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public class StackOverflowException extends RuntimeException { 22 | } 23 | -------------------------------------------------------------------------------- /jdave-examples/src/java/jdave/examples/StackOverflowException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.examples; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public class StackOverflowException extends RuntimeException { 22 | } 23 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/IContract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public interface IContract { 22 | void isSatisfied(Object obj) throws ExpectationFailedException; 23 | } 24 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/runner/IFileHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | import java.io.File; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | interface IFileHandler { 24 | void handle(File file); 25 | } 26 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/tools/IDoxStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.tools; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public interface IDoxStore { 22 | void store(String doxName, String suffix, String content); 23 | } 24 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/runner/dummies/Dummy1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner.dummies; 17 | 18 | import jdave.Group; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | @Group({"group1", "group2"}) 24 | public class Dummy1 { 25 | } 26 | -------------------------------------------------------------------------------- /jdave-examples/src/java/jdave/examples/observer/Observer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.examples.observer; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public interface Observer { 22 | void onAction(Observable observable); 23 | } 24 | -------------------------------------------------------------------------------- /jdave-unfinalizer/src/test/jdave/unfinalizer/fake/FinalClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package jdave.unfinalizer.fake; 17 | 18 | /** 19 | * 20 | * I am final. 21 | * 22 | * @author Tuomas Karkkainen 23 | */ 24 | public final class FinalClass { 25 | } 26 | -------------------------------------------------------------------------------- /jdave-wicket-1.5/src/java/jdave/wicket/WicketIdEqualsTo.java: -------------------------------------------------------------------------------- 1 | package jdave.wicket; 2 | 3 | import org.apache.wicket.Component; 4 | import org.hamcrest.BaseMatcher; 5 | import org.hamcrest.Description; 6 | 7 | /** 8 | * @author Timo Rantalaiho 9 | */ 10 | public class WicketIdEqualsTo extends BaseMatcher { 11 | private final String wicketId; 12 | 13 | public WicketIdEqualsTo(String wicketId) { 14 | this.wicketId = wicketId; 15 | } 16 | 17 | @SuppressWarnings({"unchecked"}) 18 | public final boolean matches(Object o) { 19 | T component = (T) o; 20 | return matches(component); 21 | } 22 | 23 | protected boolean matches(T component) { 24 | return (wicketId.equals(component.getId())); 25 | } 26 | 27 | public void describeTo(Description description) { 28 | description.appendText(wicketId); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jdave-wicket/src/java/jdave/wicket/WicketIdEqualsTo.java: -------------------------------------------------------------------------------- 1 | package jdave.wicket; 2 | 3 | import org.apache.wicket.Component; 4 | import org.hamcrest.BaseMatcher; 5 | import org.hamcrest.Description; 6 | 7 | /** 8 | * @author Timo Rantalaiho 9 | */ 10 | public class WicketIdEqualsTo extends BaseMatcher { 11 | private final String wicketId; 12 | 13 | public WicketIdEqualsTo(String wicketId) { 14 | this.wicketId = wicketId; 15 | } 16 | 17 | @SuppressWarnings({"unchecked"}) 18 | public final boolean matches(Object o) { 19 | T component = (T) o; 20 | return matches(component); 21 | } 22 | 23 | protected boolean matches(T component) { 24 | return (wicketId.equals(component.getId())); 25 | } 26 | 27 | public void describeTo(Description description) { 28 | description.appendText(wicketId); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/runner/IAnnotatedSpecHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public interface IAnnotatedSpecHandler { 22 | void handle(String name, String... groups); 23 | } 24 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/IStringComparisonFailure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public interface IStringComparisonFailure { 22 | void fail(String message, String expected, String actual); 23 | } 24 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/runner/ISpecVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | public interface ISpecVisitor { 19 | void onContext(Context context); 20 | void afterContext(Context context); 21 | void onBehavior(Behavior behavior); 22 | } -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/IEqualityCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public interface IEqualityCheck { 22 | void verify(Object actual); 23 | boolean matches(Object actual); 24 | String error(Object actual); 25 | } 26 | -------------------------------------------------------------------------------- /jdave-examples/src/java/jdave/examples/wicket/IDictionaryService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.examples.wicket; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public interface IDictionaryService { 24 | List lookup(String word); 25 | } 26 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/testapplication/ChildPage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver.testapplication; 17 | 18 | import org.apache.wicket.markup.html.WebPage; 19 | 20 | /** 21 | * @author Marko Sibakov 22 | */ 23 | public class ChildPage extends WebPage { 24 | } 25 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/tools/DoxStoreException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.tools; 17 | 18 | 19 | /** 20 | * @author Joni Freeman 21 | */ 22 | public class DoxStoreException extends RuntimeException { 23 | public DoxStoreException(Exception e) { 24 | super(e); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | TestApp 8 | 9 | 10 | TestApplications 11 | org.apache.wicket.protocol.http.WicketFilter 12 | 13 | applicationClassName 14 | jdave.webdriver.testapplication.WebDriverApplication 15 | 16 | 17 | configuration 18 | deployment 19 | 20 | 21 | 22 | 23 | TestApplications 24 | /* 25 | 26 | 27 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/injection/ReflectionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.injection; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public class ReflectionException extends RuntimeException { 22 | public ReflectionException(Exception cause) { 23 | super(cause); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /jdave-wicket/src/java/jdave/wicket/Container.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.wicket; 17 | 18 | import org.apache.wicket.markup.html.panel.Panel; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public class Container extends Panel { 24 | public Container(String id) { 25 | super(id); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jdave-wicket-1.5/src/java/jdave/wicket/Container.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.wicket; 17 | 18 | import org.apache.wicket.markup.html.panel.Panel; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public class Container extends Panel { 24 | public Container(String id) { 25 | super(id); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jdave-wicket/src/test/jdave/wicket/EmptyPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.wicket; 17 | 18 | import org.apache.wicket.markup.html.panel.Panel; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public class EmptyPanel extends Panel { 24 | public EmptyPanel(String id) { 25 | super(id); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jdave-wicket-1.5/src/test/jdave/wicket/EmptyPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.wicket; 17 | 18 | import org.apache.wicket.markup.html.panel.Panel; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public class EmptyPanel extends Panel { 24 | public EmptyPanel(String id) { 25 | super(id); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/util/FluentMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.util; 17 | 18 | import java.util.HashMap; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public class FluentMap extends HashMap { 24 | public FluentMap map(K key, V value) { 25 | put(key, value); 26 | return this; 27 | } 28 | } -------------------------------------------------------------------------------- /jdave-junit3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | org.jdave 6 | jdave-parent 7 | 1.2-SNAPSHOT 8 | 9 | 10 | jdave-junit3 11 | jdave-junit3 12 | jar 13 | 14 | 15 | 16 | ${project.groupId} 17 | jdave-core 18 | ${project.version} 19 | 20 | 21 | junit 22 | junit 23 | 3.8.1 24 | compile 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /jdave-junit4/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.jdave 7 | jdave-parent 8 | 1.5-SNAPSHOT 9 | 10 | 11 | jdave-junit4 12 | jdave-junit4 13 | jar 14 | 15 | 16 | 17 | ${project.groupId} 18 | jdave-core 19 | ${project.version} 20 | 21 | 22 | junit 23 | junit-dep 24 | 4.5 25 | compile 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/runner/ISpecIntrospection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public interface ISpecIntrospection { 24 | boolean isBehavior(Method method); 25 | boolean isContextClass(Class specType, Class possibleContext); 26 | } 27 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/util/Maps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.util; 17 | 18 | 19 | /** 20 | * @author Joni Freeman 21 | */ 22 | public class Maps { 23 | public static FluentMap map(K key, V value) { 24 | FluentMap map = new FluentMap(); 25 | map.put(key, value); 26 | return map; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/WicketWebDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver; 17 | 18 | import org.openqa.selenium.JavascriptExecutor; 19 | import org.openqa.selenium.WebDriver; 20 | 21 | /** 22 | * @author Juha Karemo 23 | */ 24 | public interface WicketWebDriver extends WebDriver, JavascriptExecutor { 25 | } 26 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/EqualityCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public abstract class EqualityCheck implements IEqualityCheck { 22 | public void verify(Object actual) { 23 | if (!matches(actual)) { 24 | throw new ExpectationFailedException(error(actual)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/IContainment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | import java.util.Collection; 19 | import org.hamcrest.Matcher; 20 | 21 | /** 22 | * @author Joni Freeman 23 | */ 24 | public interface IContainment extends Matcher> { 25 | boolean matches(Collection actual); 26 | 27 | String error(Collection actual); 28 | } 29 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/tools/StackSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.tools; 17 | 18 | import jdave.Specification; 19 | 20 | public class StackSpec extends Specification { 21 | public class FullStack { 22 | public void create() { 23 | } 24 | 25 | public void complainsOnPush() { 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /jdave-unfinalizer/sample-project/src/main/java/org/example/AClassWithAMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package org.example; 17 | 18 | public class AClassWithAMethod { 19 | /** 20 | * I'm final. I can't be mocked. 21 | */ 22 | public final void finalMethod() { 23 | throw new RuntimeException("This method should be mocked."); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/ByNameComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | import java.lang.reflect.Method; 19 | import java.util.Comparator; 20 | 21 | /** 22 | * @author Pekka Enberg 23 | */ 24 | public class ByNameComparator implements Comparator { 25 | public int compare(Method o1, Method o2) { 26 | return o1.getName().compareTo(o2.getName()); 27 | } 28 | } -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/ExpectationFailedStringComparisonFailure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public class ExpectationFailedStringComparisonFailure implements IStringComparisonFailure { 22 | public void fail(String message, String expected, String actual) { 23 | throw new ExpectationFailedException(message); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/elements/Find.java: -------------------------------------------------------------------------------- 1 | package jdave.webdriver.elements; 2 | 3 | import java.util.List; 4 | 5 | import jdave.webdriver.WebDriverHolder; 6 | 7 | import org.openqa.selenium.By; 8 | 9 | /** 10 | * @author Juha Karemo 11 | * @author Marko Sibakov 12 | */ 13 | public class Find { 14 | public static Link link(By by) { 15 | return new Link(WebDriverHolder.get().findElement(by)); 16 | } 17 | 18 | public static List links(By by) { 19 | return WebElements.asLinks(WebDriverHolder.get().findElements(by)); 20 | } 21 | 22 | public static TextBox textBox(By by) { 23 | return new TextBox(WebDriverHolder.get().findElement(by)); 24 | } 25 | 26 | public static CheckBox checkBox(By by) { 27 | return new CheckBox(WebDriverHolder.get().findElement(by)); 28 | } 29 | 30 | public static DropDownChoice dropDownChoice(By by) { 31 | return new DropDownChoice(WebDriverHolder.get().findElement(by)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/Sleep.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver; 17 | 18 | /** 19 | * @author Juha Karemo 20 | */ 21 | public class Sleep { 22 | public static void milliSecs(int millis) { 23 | try { 24 | Thread.sleep(millis); 25 | } catch (InterruptedException e) { 26 | throw new RuntimeException(e); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /jdave-junit4/src/java/jdave/junit4/SpecDirs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.junit4; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | @Retention(RetentionPolicy.RUNTIME) 24 | @Target(ElementType.TYPE) 25 | public @interface SpecDirs { 26 | public String[] value(); 27 | } 28 | -------------------------------------------------------------------------------- /jdave-unfinalizer/src/test/jdave/unfinalizer/fake/ClassWithFinalMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package jdave.unfinalizer.fake; 17 | 18 | /** 19 | * @author Tuomas Karkkainen 20 | */ 21 | public class ClassWithFinalMethod { 22 | /** 23 | * I'm final. I can't be mocked. 24 | */ 25 | public final void finalMethod() { 26 | throw new RuntimeException("This method should be mocked."); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jdave-wicket/src/java/jdave/wicket/ComponentsModelMatchesTo.java: -------------------------------------------------------------------------------- 1 | package jdave.wicket; 2 | 3 | import org.apache.wicket.Component; 4 | import org.hamcrest.BaseMatcher; 5 | import org.hamcrest.Description; 6 | import org.hamcrest.Matcher; 7 | 8 | /** 9 | * @author Timo Rantalaiho 10 | */ 11 | public class ComponentsModelMatchesTo extends BaseMatcher { 12 | private final Matcher matcher; 13 | 14 | public ComponentsModelMatchesTo(Matcher matcher) { 15 | this.matcher = matcher; 16 | } 17 | 18 | @SuppressWarnings({"unchecked"}) 19 | public final boolean matches(Object o) { 20 | T component = (T) o; 21 | return matches(component); 22 | } 23 | 24 | protected boolean matches(T component) { 25 | if (matcher instanceof AnyModelMatcher) { 26 | return true; 27 | } 28 | return (matcher.matches(component.getDefaultModelObject())); 29 | } 30 | 31 | public void describeTo(Description description) { 32 | matcher.describeTo(description); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jdave-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | org.jdave 6 | jdave-parent 7 | 1.5-SNAPSHOT 8 | 9 | 10 | jdave-core 11 | jdave-core 12 | jar 13 | 14 | 15 | 16 | 17 | src/scripts 18 | 19 | **/*.xsl 20 | 21 | 22 | 23 | 24 | 25 | src/test 26 | 27 | **/hack-to-get-maven-copy-this-dir 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /jdave-wicket-1.5/src/java/jdave/wicket/ComponentsModelMatchesTo.java: -------------------------------------------------------------------------------- 1 | package jdave.wicket; 2 | 3 | import org.apache.wicket.Component; 4 | import org.hamcrest.BaseMatcher; 5 | import org.hamcrest.Description; 6 | import org.hamcrest.Matcher; 7 | 8 | /** 9 | * @author Timo Rantalaiho 10 | */ 11 | public class ComponentsModelMatchesTo extends BaseMatcher { 12 | private final Matcher matcher; 13 | 14 | public ComponentsModelMatchesTo(Matcher matcher) { 15 | this.matcher = matcher; 16 | } 17 | 18 | @SuppressWarnings({"unchecked"}) 19 | public final boolean matches(Object o) { 20 | T component = (T) o; 21 | return matches(component); 22 | } 23 | 24 | protected boolean matches(T component) { 25 | if (matcher instanceof AnyModelMatcher) { 26 | return true; 27 | } 28 | return (matcher.matches(component.getDefaultModelObject())); 29 | } 30 | 31 | public void describeTo(Description description) { 32 | matcher.describeTo(description); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/IContextObjectFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * A factory which will be used to create new context objects 20 | * 21 | * @see Specification#setContextObjectFactory(IContextObjectFactory) 22 | * 23 | * @author Janne Hietamäki 24 | */ 25 | public interface IContextObjectFactory { 26 | public T newContextObject(Object context) throws Exception; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/ExpectationFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public class ExpectationFailedException extends Error { 22 | public ExpectationFailedException(String message) { 23 | super(message); 24 | } 25 | 26 | public ExpectationFailedException(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/WebDriverFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver; 17 | 18 | import org.openqa.selenium.WebDriver; 19 | import org.openqa.selenium.firefox.FirefoxDriver; 20 | 21 | /** 22 | * @author Juha Karemo 23 | */ 24 | public class WebDriverFactory { 25 | public WebDriver createFireFoxDriver() { 26 | return new FirefoxDriver(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/runner/dummies/Other.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner.dummies; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * @author Joni Freeman 25 | */ 26 | @Retention(RetentionPolicy.RUNTIME) 27 | @Target(ElementType.TYPE) 28 | public @interface Other { 29 | } 30 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/Group.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * @author Joni Freeman 25 | */ 26 | @Retention(RetentionPolicy.RUNTIME) 27 | @Target(ElementType.TYPE) 28 | public @interface Group { 29 | public String[] value(); 30 | } 31 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/runner/IntrospectionStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | import java.lang.annotation.Inherited; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | 22 | /** 23 | * @author Joni Freeman 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Inherited 27 | public @interface IntrospectionStrategy { 28 | Class value(); 29 | } 30 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/tools/IDoxFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.tools; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public interface IDoxFormat { 22 | void newSpec(String specName, String fqn); 23 | void endSpec(String specName); 24 | void newContext(String contextName); 25 | void endContext(String name); 26 | void newBehavior(String behaviorName); 27 | String suffix(); 28 | String toString(); 29 | } 30 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/test/jdave/webdriver/testapplication/SpecSuite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver.testapplication; 17 | 18 | import jdave.runner.Groups; 19 | import jdave.webdriver.WebDriverGroupRunner; 20 | 21 | import org.junit.runner.RunWith; 22 | 23 | /** 24 | * @author Juha Karemo 25 | */ 26 | @RunWith(WebDriverGroupRunner.class) 27 | @Groups(include = { "lulz" }) 28 | public class SpecSuite { 29 | } 30 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/DefaultLifecycleListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Mikko Peltonen 20 | */ 21 | public class DefaultLifecycleListener implements ILifecycleListener { 22 | public void afterContextCreation(Object contextInstance, Object createdContext) {} 23 | 24 | public void afterContextDestroy(Object contextInstance) {} 25 | 26 | public void afterContextInstantiation(Object contextInstance) {} 27 | } 28 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/ExactExpectedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Lasse Koskela 20 | */ 21 | public class ExactExpectedException extends ExpectedException { 22 | public ExactExpectedException(Class expected) { 23 | super(expected); 24 | } 25 | 26 | @Override 27 | public boolean matchesType(Class actual) { 28 | return expected.equals(actual); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jdave-guice/src/main/java/jdave/guice/InterestedInGuice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package jdave.guice; 17 | 18 | import com.google.inject.Binder; 19 | 20 | /** 21 | *

22 | * Have your testclass implement this. 23 | *

24 | *

25 | * Then call new InjectorCreator().createInjector(this); before you need the 26 | * mocks. 27 | *

28 | */ 29 | public interface InterestedInGuice { 30 | void addBindings(Binder binder); 31 | } 32 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/runner/LineNumberStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package jdave.runner; 18 | 19 | import java.lang.reflect.Method; 20 | 21 | /** 22 | * @author Esko Luontola 23 | * @since 14.2.2008 24 | */ 25 | public interface LineNumberStrategy { 26 | static LineNumberStrategy CURRENT_STRATEGY = new AsmLineNumberStrategy(); 27 | 28 | int firstLineNumber(Class clazz, int defaultValue); 29 | int firstLineNumber(Method method, int defaultValue); 30 | } 31 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/util/CollectionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.util; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import java.util.Arrays; 21 | 22 | import org.junit.Test; 23 | 24 | /** 25 | * @author Joni Freeman 26 | */ 27 | public class CollectionsTest { 28 | @Test 29 | public void testConvertsIteratorToList() { 30 | assertEquals(Arrays.asList(1, 2, 3), Collections.list(Arrays.asList(1, 2, 3).iterator())); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/containment/ContainmentTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.containment; 17 | 18 | import jdave.IContainment; 19 | import org.junit.Test; 20 | 21 | /** 22 | * @author Joni Freeman 23 | */ 24 | public abstract class ContainmentTest { 25 | protected IContainment containment; 26 | 27 | @Test 28 | public void testShouldNotThrowNullPointerExceptionIfActualIsNull() throws Exception { 29 | containment.matches(null); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/Where.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | class Where { 22 | private final Each each; 23 | 24 | public Where(Each each) { 25 | this.each = each; 26 | } 27 | 28 | void match(T realItem, int index) { 29 | each.match(realItem, index); 30 | } 31 | 32 | public void areAllMatchersUsed(int index) { 33 | each.areAllMatchersUsed(index); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/runner/IBehaviorResults.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import jdave.ExpectationFailedException; 21 | 22 | /** 23 | * Used for reporting result of a behavior. 24 | * 25 | * @author Pekka Enberg 26 | */ 27 | public interface IBehaviorResults { 28 | void expected(Method method); 29 | void unexpected(Method method, ExpectationFailedException e); 30 | void error(Method method, Throwable t); 31 | } -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/testapplication/WebDriverApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver.testapplication; 17 | 18 | import org.apache.wicket.Page; 19 | import org.apache.wicket.protocol.http.WebApplication; 20 | 21 | /** 22 | * @author Marko Sibakov 23 | */ 24 | public class WebDriverApplication extends WebApplication { 25 | @Override 26 | public Class getHomePage() { 27 | return WebDriverTestPage.class; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/runner/VisitingBehavior.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | final class VisitingBehavior extends Behavior { 24 | VisitingBehavior(Method method, Class contextType) { 25 | super(contextType, method); 26 | } 27 | 28 | @Override 29 | public void run(IBehaviorResults results) { 30 | throw new UnsupportedOperationException(); 31 | } 32 | } -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/tools/Formats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.tools; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public class Formats { 22 | public IDoxFormat formatFor(String formatName) { 23 | if (formatName.equals("txt")) { 24 | return new PlainTextFormat(); 25 | } else if (formatName.equals("xml")) { 26 | return new XmlFormat(); 27 | } 28 | throw new RuntimeException("unknown format '" + formatName + "'"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jdave-examples/src/test/jdave/examples/SuiteForBasicSpecs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.examples; 17 | 18 | import jdave.junit4.JDaveGroupRunner; 19 | import jdave.runner.Groups; 20 | 21 | import org.junit.runner.RunWith; 22 | 23 | /** 24 | * A sample suite which runs all specifications which are annotated with 25 | * @Group("basic") annotation. 26 | * 27 | * @author Joni Freeman 28 | */ 29 | @RunWith(JDaveGroupRunner.class) 30 | @Groups(include={ "basic" }) 31 | public class SuiteForBasicSpecs { 32 | } 33 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/ResultsAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import jdave.runner.IBehaviorResults; 21 | 22 | /** 23 | * @author Joni Freeman 24 | */ 25 | public class ResultsAdapter implements IBehaviorResults { 26 | public void expected(Method method) { 27 | } 28 | 29 | public void unexpected(Method method, ExpectationFailedException e) { 30 | } 31 | 32 | public void error(Method method, Throwable t) { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/util/PrimitivesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.util; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import java.util.Arrays; 21 | 22 | import org.junit.Test; 23 | 24 | /** 25 | * @author Joni Freeman 26 | */ 27 | public class PrimitivesTest { 28 | @Test 29 | public void testShouldConvertPrimitiveArrayToList() { 30 | int[] array = new int[] { 1, 2, 3 }; 31 | assertEquals(Arrays.asList(1, 2, 3), Primitives.asList(array)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/util/Collections.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.util; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Iterator; 20 | import java.util.List; 21 | 22 | /** 23 | * @author Joni Freeman 24 | */ 25 | public class Collections { 26 | public static List list(final Iterator iterator) { 27 | final List list = new ArrayList(); 28 | while (iterator.hasNext()) { 29 | list.add(iterator.next()); 30 | } 31 | return list; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/support/Assert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.support; 17 | 18 | 19 | /** 20 | * @author Joni Freeman 21 | */ 22 | public class Assert { 23 | public static void notNull(Object obj, String message) { 24 | if (obj == null) { 25 | throw new IllegalArgumentException(message); 26 | } 27 | } 28 | 29 | public static void isTrue(boolean b, String message) { 30 | if (!b) { 31 | throw new IllegalArgumentException(message); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/ExactExpectedExceptionWithMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public class ExactExpectedExceptionWithMessage extends ExpectedExceptionWithMessage { 22 | public ExactExpectedExceptionWithMessage(Class type, String message) { 23 | super(type, message); 24 | } 25 | 26 | @Override 27 | public boolean matchesType(Class actual) { 28 | return expected.equals(actual); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/runner/DummyBehaviorResults.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import jdave.ExpectationFailedException; 21 | 22 | /** 23 | * @author Joni Freeman 24 | */ 25 | public class DummyBehaviorResults implements IBehaviorResults { 26 | public void error(Method method, Throwable t) { 27 | } 28 | 29 | public void expected(Method method) { 30 | } 31 | 32 | public void unexpected(Method method, ExpectationFailedException e) { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jdave-examples/src/test/jdave/examples/SuiteForNonBasicSpecs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.examples; 17 | 18 | import jdave.junit4.JDaveGroupRunner; 19 | import jdave.runner.Groups; 20 | 21 | import org.junit.runner.RunWith; 22 | 23 | /** 24 | * A sample suite which runs all specifications which are not annotated with 25 | * @Group("basic") annotation. 26 | * 27 | * @author Joni Freeman 28 | */ 29 | @RunWith(JDaveGroupRunner.class) 30 | @Groups(include={ Groups.ALL }, exclude={ "basic" }) 31 | public class SuiteForNonBasicSpecs { 32 | } 33 | -------------------------------------------------------------------------------- /jdave-guice/README: -------------------------------------------------------------------------------- 1 | JDave Guice 2 | ----------- 3 | Mockito allows you to inject mocks into your test class when you annotate them with @Mock and then call 4 | MockitoAnnotations.initMocks(testClassInstance); 5 | 6 | JDave Guice expands on this by binding those same mocks into a Guice injector. 7 | 8 | Here's an example with jdave-wicket and wicket, wicket-ioc, wicket-guice: 9 | 10 | public abstract class GuiceInterestedComponentSpecification extends ComponentSpecification implements InterestedInGuice { 11 | @Override 12 | protected final void onCreate() { 13 | final Injector injector = new InjectorCreator().createInjector(this); 14 | wicket.getApplication().setMetaData(GuiceInjectorHolder.INJECTOR_KEY, new GuiceInjectorHolder(injector)); 15 | final GuiceComponentInjector guiceComponentInjector = new GuiceComponentInjector(wicket.getApplication()); 16 | wicket.getApplication().addComponentInstantiationListener(guiceComponentInjector); 17 | } 18 | 19 | public void addBindings(final Binder binder) { 20 | } 21 | } 22 | 23 | Also have a look at: 24 | http://code.google.com/p/mycila/wiki/PluginGuice1 -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/util/Primitives.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.util; 17 | 18 | import java.lang.reflect.Array; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | * @author Joni Freeman 24 | */ 25 | public class Primitives { 26 | public static List asList(final Object object) { 27 | final int size = Array.getLength(object); 28 | final List list = new ArrayList(); 29 | 30 | for (int i = 0; i < size; i++) { 31 | list.add(Array.get(object, i)); 32 | } 33 | return list; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /jdave-examples/src/java/jdave/examples/observer/Observable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.examples.observer; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * @author Joni Freeman 23 | */ 24 | public class Observable { 25 | private List observers = new ArrayList(); 26 | 27 | public void register(Observer observer) { 28 | observers.add(observer); 29 | } 30 | 31 | public void significantEvent() { 32 | for (Observer observer : observers) { 33 | observer.onAction(this); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/ExpectedNoThrow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Pekka Enberg 20 | */ 21 | public class ExpectedNoThrow { 22 | private final ExpectedException expectation; 23 | 24 | public ExpectedNoThrow(ExpectedException expectation) { 25 | this.expectation = expectation; 26 | } 27 | 28 | public boolean matches(Throwable t) { 29 | return !expectation.matches(t); 30 | } 31 | 32 | public String error(Throwable t) { 33 | throw new ExpectationFailedException("The specified block threw " + t.getClass().getName(), t); 34 | } 35 | } -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/runner/Groups.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * @author Joni Freeman 25 | */ 26 | @Retention(RetentionPolicy.RUNTIME) 27 | @Target(ElementType.TYPE) 28 | public @interface Groups { 29 | public static final String ALL = "__all_groups"; 30 | static final String DEFAULT = "__default_group"; 31 | 32 | public String[] include(); 33 | public String[] exclude() default {}; 34 | } 35 | -------------------------------------------------------------------------------- /jdave-guice/buildfile: -------------------------------------------------------------------------------- 1 | ENV["JAVA_OPTIONS"] = "-Xms40m -Xmx256m -XX:+UseParallelGC -XX:PermSize=128M " + (ENV["JAVA_OPTIONS"] or "") 2 | 3 | basedir = File.dirname(__FILE__) 4 | require "buildr" 5 | 6 | repositories.remote << "http://repo1.maven.org/maven2" 7 | repositories.remote << "http://maven.laughingpanda.org/maven2" 8 | repositories.remote << "http://maven.laughingpanda.org/maven2/snapshots" 9 | 10 | jdave_version="1.2-SNAPSHOT" 11 | 12 | define "jdave-guice", :version=>jdave_version, :group=>"org.jdave" do 13 | package_with_sources 14 | package_with_javadoc 15 | compile.options.other = ["-encoding", "utf-8", "-target", "1.5"] 16 | test.with("org.jdave:jdave-core:jar:#{jdave_version}") 17 | test.with("org.jdave:jdave-junit4:jar:#{jdave_version}") 18 | test.with("junit:junit:jar:4.5") 19 | test.with("org.jmock:jmock-legacy:jar:2.4.0") 20 | test.with("org.jmock:jmock:jar:2.4.0") 21 | test.with("org.objenesis:objenesis:jar:1.1") 22 | test.with("org.hamcrest:hamcrest-core:jar:1.1") 23 | test.with("org.hamcrest:hamcrest-library:jar:1.1") 24 | test.with("cglib:cglib-nodep:jar:2.1_3") 25 | compile.with("org.mockito:mockito-all:jar:1.7") 26 | compile.with("com.google.code.guice:guice:jar:1.0") 27 | package(:jar) 28 | end 29 | -------------------------------------------------------------------------------- /jdave-examples/src/test/jdave/examples/ApproximationSampleSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.examples; 17 | 18 | import jdave.junit4.JDaveRunner; 19 | 20 | import org.junit.runner.RunWith; 21 | 22 | /** 23 | * @author Joni Freeman 24 | */ 25 | @RunWith(JDaveRunner.class) 26 | public class ApproximationSampleSpec extends ExtendedSpecification { 27 | public class Sample { 28 | public void create() {} 29 | 30 | public void sampleWhichUsesExtensionMethod() { 31 | specify(1.5, should.approximate(1.5005)); 32 | specify(1.5, should.not().approximate(1.6)); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/elements/WebElements.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver.elements; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import org.openqa.selenium.WebElement; 22 | 23 | /** 24 | * @author Juha Karemo 25 | */ 26 | public class WebElements { 27 | public static List asLinks(List webeElments) { 28 | List links = new ArrayList(); 29 | for (WebElement webElement : webeElments) { 30 | links.add(new Link(webElement)); 31 | } 32 | return links; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/Block.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * A block is a group of statements that must be evaluated lazily. In other 20 | * words, a block is an approximation of a lambda function for JDave. 21 | * 22 | * @see Specification#specify(Block, ExpectedException) 23 | * @see Specification#specify(Block, ExpectedNoThrow) 24 | * 25 | * @author Joni Freeman 26 | * @author Pekka Enberg 27 | */ 28 | public interface Block { 29 | /** 30 | * Evaluate this block. 31 | * 32 | * @throws Throwable if an exception is thrown during block evaluation. 33 | */ 34 | void run() throws Throwable; 35 | } 36 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/mock/JDaveErrorTranslator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.mock; 17 | 18 | import jdave.ExpectationFailedException; 19 | 20 | import org.hamcrest.StringDescription; 21 | import org.jmock.api.ExpectationError; 22 | import org.jmock.api.ExpectationErrorTranslator; 23 | 24 | /** 25 | * @author Joni Freeman 26 | */ 27 | public class JDaveErrorTranslator implements ExpectationErrorTranslator { 28 | public static final JDaveErrorTranslator INSTANCE = new JDaveErrorTranslator(); 29 | 30 | public Error translate(ExpectationError e) { 31 | return new ExpectationFailedException(StringDescription.toString(e)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /jdave-unfinalizer/src/java/jdave/unfinalizer/internal/UnfinalizingClassVisitorDelegator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package jdave.unfinalizer.internal; 17 | 18 | import jdave.org.objectweb.asm.ClassWriter; 19 | 20 | /** 21 | * Delegate class file in byte array to an UnfinalizingClassVisitor and returns 22 | * transformed byte array. 23 | * 24 | * @author Tuomas Karkkainen 25 | */ 26 | public class UnfinalizingClassVisitorDelegator extends ClassVisitorDelegator { 27 | @Override 28 | protected UnfinalizingClassVisitor createClassVisitor(final ClassWriter writer) { 29 | return new UnfinalizingClassVisitor(writer); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /jdave-parent/RELEASE.txt: -------------------------------------------------------------------------------- 1 | > Update docs (version numbers, examples, documentation, front page news). 2 | ##### does not work: ./bin/prepare-release.sh (note, this fails for svn: '/home/inhuman/workspace' is not a working copy') 3 | > update pom version and commit 4 | mvn clean install (export PATH=$PATH:/usr/lib/firefox) 5 | mvn deploy 6 | svn copy https://svn.laughingpanda.org/svn/jdave/trunk/ https://svn.laughingpanda.org/svn/jdave/tags/0.5.0 -m "tag release" 7 | mvn-no-tests clean package assembly:assembly (in jdave-parent) 8 | scp ~/workspace/jdave-core/site/*[.html,.xml,.css] inhuman@www.laughingpanda.org:/var/www/localhost/htdocs/projects/jdave/ 9 | scp ~/workspace/jdave-core/site/specdox-sample/*.html inhuman@www.laughingpanda.org:/var/www/localhost/htdocs/projects/jdave/specdox-sample/ 10 | scp ~/workspace/jdave-core/site/images/*[.jpg,.gif,.png] inhuman@www.laughingpanda.org:/var/www/localhost/htdocs/projects/jdave/images/ 11 | scp target/jdave-parent-0.5.0.zip inhuman@www.laughingpanda.org:/var/www/localhost/htdocs/projects/jdave/bin/ 12 | cd jdave-core; mvn javadoc:javadoc 13 | mv target/site/apidocs target/site/api 14 | scp -r target/site/api inhuman@www.laughingpanda.org:/var/www/localhost/htdocs/projects/jdave/ 15 | > update pom versions to be x.x.x-SNAPSHOT 16 | 17 | Test: 18 | - gets downloaded with maven 19 | - links in site work 20 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/runner/ClassLineNumberComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | import java.util.Comparator; 19 | 20 | /** 21 | * Sorts (inner) classes according to the order in which they have been declared in the source code. 22 | * 23 | * @author Esko Luontola 24 | * @since 4.1.2008 25 | */ 26 | public class ClassLineNumberComparator implements Comparator> { 27 | private final LineNumberStrategy strategy = LineNumberStrategy.CURRENT_STRATEGY; 28 | 29 | public int compare(Class c1, Class c2) { 30 | int line1 = strategy.firstLineNumber(c1, 0); 31 | int line2 = strategy.firstLineNumber(c2, 0); 32 | return line1 - line2; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jdave-unfinalizer/sample-project/buildfile: -------------------------------------------------------------------------------- 1 | ENV["JAVA_OPTIONS"] = "-Xms512m -Xmx1024m -XX:+UseParallelGC -XX:PermSize=128M " + (ENV["JAVA_OPTIONS"] or "") 2 | 3 | basedir = File.dirname(__FILE__) 4 | require "buildr" 5 | 6 | repositories.remote << "http://repo1.maven.org/maven2" 7 | repositories.remote << "http://maven.laughingpanda.org/maven2" 8 | repositories.remote << "http://maven.laughingpanda.org/maven2/snapshots" 9 | 10 | define "sample-project" do 11 | compile.options.other = ["-encoding", "utf-8", "-target", "1.6"] 12 | jdave_version="1.2-SNAPSHOT" 13 | test.with("#{ENV["JAVA_HOME"]}/lib/tools.jar") 14 | test.with("junit:junit:jar:4.5") 15 | test.with("org.jdave:jdave-core:jar:#{jdave_version}") 16 | test.with("org.jdave:jdave-junit4:jar:#{jdave_version}") 17 | test.with("org.jdave:jdave-unfinalizer:jar:#{jdave_version}") 18 | test.with("org.jmock:jmock-legacy:jar:2.4.0") 19 | test.with("org.jmock:jmock:jar:2.4.0") 20 | test.with("org.objenesis:objenesis:jar:1.1") 21 | test.with("org.hamcrest:hamcrest-core:jar:1.1") 22 | test.with("org.hamcrest:hamcrest-library:jar:1.1") 23 | test.with("cglib:cglib-nodep:jar:2.1_3") 24 | ENV["JAVA_OPTIONS"] += "-javaagent:\"#{Artifact::lookup("org.jdave:jdave-unfinalizer:jar:#{jdave_version}").to_s}\" " 25 | test.using :java_args => Array(ENV["JAVA_OPTIONS"].split(' ')) 26 | end -------------------------------------------------------------------------------- /jdave-examples/src/test/jdave/examples/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.examples; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public class Person { 22 | private final String firstname; 23 | private final String surname; 24 | private final int age; 25 | 26 | public Person(String firstname, String surname, int age) { 27 | this.firstname = firstname; 28 | this.surname = surname; 29 | this.age = age; 30 | } 31 | 32 | public String getFirstname() { 33 | return firstname; 34 | } 35 | 36 | public String getSurname() { 37 | return surname; 38 | } 39 | 40 | public int getAge() { 41 | return age; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/equality/EqualsEqualityCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.equality; 17 | 18 | import jdave.EqualityCheck; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public class EqualsEqualityCheck extends EqualityCheck { 24 | protected final Object expected; 25 | 26 | public EqualsEqualityCheck(Object expected) { 27 | this.expected = expected; 28 | } 29 | 30 | public boolean matches(Object actual) { 31 | if (expected == null) { 32 | return actual == null; 33 | } 34 | return expected.equals(actual); 35 | } 36 | 37 | public String error(Object actual) { 38 | return "Expected: " + expected + ", but was: " + actual; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /jdave-guice/src/main/java/jdave/guice/GuiceMock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package jdave.guice; 17 | 18 | import static java.lang.annotation.ElementType.FIELD; 19 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 20 | 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | *

26 | * Annotate fields in your test class with this. 27 | *

28 | *

29 | * Annotated fields will be injected with a Mockito mock, and they will be 30 | * bound in the Guice injector. 31 | *

32 | *

33 | * You can also use BindingAnnotations, i.e. @Named on your fields. 34 | *

35 | */ 36 | @Target(FIELD) 37 | @Retention(RUNTIME) 38 | public @interface GuiceMock { 39 | } -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/equality/NotEqualsEqualityCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.equality; 17 | 18 | import jdave.EqualityCheck; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public class NotEqualsEqualityCheck extends EqualityCheck { 24 | private final Object expected; 25 | 26 | public NotEqualsEqualityCheck(Object expected) { 27 | this.expected = expected; 28 | } 29 | 30 | public boolean matches(Object actual) { 31 | if (expected == null) { 32 | return actual != null; 33 | } 34 | return !expected.equals(actual); 35 | } 36 | 37 | public String error(Object actual) { 38 | return "Did not expect: " + expected + ", but was: " + actual; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/NotDeltaEqualityCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public class NotDeltaEqualityCheck extends EqualityCheck { 22 | private final Number expectedNumber; 23 | private final double delta; 24 | 25 | public NotDeltaEqualityCheck(Number expectedNumber, double delta) { 26 | this.expectedNumber = expectedNumber; 27 | this.delta = delta; 28 | } 29 | 30 | public boolean matches(Object actual) { 31 | return (Math.abs(((Number) actual).doubleValue() - expectedNumber.doubleValue()) > delta); 32 | } 33 | 34 | public String error(Object actual) { 35 | return "Did not expect: " + expectedNumber + ", but was: " + actual; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/containment/AllContainment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.containment; 17 | 18 | import java.util.Collection; 19 | import java.util.Iterator; 20 | 21 | /** 22 | * @author Joni Freeman 23 | */ 24 | public class AllContainment extends CollectionContainment { 25 | public AllContainment(final Collection elements) { 26 | super(elements); 27 | } 28 | 29 | public AllContainment(final Iterator elements) { 30 | super(elements); 31 | } 32 | 33 | public AllContainment(final Iterable elements) { 34 | super(elements); 35 | } 36 | 37 | @Override 38 | public boolean nullSafeMatches(final Collection actual) { 39 | return actual.containsAll(elements); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /jdave-guice/src/main/java/org/mockito/configuration/MockitoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package org.mockito.configuration; 17 | 18 | import jdave.guice.internal.GuiceAnnotationEngine; 19 | import org.mockito.ReturnValues; 20 | import org.mockito.internal.returnvalues.SmartNullReturnValues; 21 | 22 | /** 23 | * This is how Mockito is configured. 24 | */ 25 | public class MockitoConfiguration implements IMockitoConfiguration { 26 | public AnnotationEngine getAnnotationEngine() { 27 | return new GuiceAnnotationEngine(); 28 | } 29 | 30 | // FIXME this should be configurable even when using jdave-guice 31 | public ReturnValues getReturnValues() { 32 | return new SmartNullReturnValues(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/DefaultContextObjectFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import jdave.runner.DefaultSpecIntrospection; 21 | 22 | /** 23 | * Default implementation of IContextFactory 24 | * 25 | * @author Janne Hietamäki 26 | */ 27 | public class DefaultContextObjectFactory implements IContextObjectFactory { 28 | @SuppressWarnings("unchecked") 29 | public T newContextObject(Object context) throws Exception { 30 | try { 31 | Method method = context.getClass().getMethod(DefaultSpecIntrospection.INITIALIZER_NAME); 32 | return (T) method.invoke(context); 33 | } catch (NoSuchMethodException e) { 34 | return null; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jdave-parent/src/assemble/bin.xml: -------------------------------------------------------------------------------- 1 | 2 | bin 3 | 4 | zip 5 | 6 | true 7 | 8 | 9 | dist/ 10 | 11 | false 12 | runtime 13 | 14 | 15 | 16 | 17 | 18 | org.jdave:jdave-core 19 | org.jdave:jdave-junit4 20 | 21 | 22 | 23 | org.jdave:jdave-examples 24 | 25 | 26 | org.jdave:jdave-unfinalizer 27 | 28 | 29 | 30 | lib/ 31 | false 32 | 33 | 34 | src/${artifactId} 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /jdave-unfinalizer/src/java/jdave/unfinalizer/internal/Filter.java: -------------------------------------------------------------------------------- 1 | package jdave.unfinalizer.internal; 2 | 3 | import java.util.List; 4 | import java.util.Properties; 5 | 6 | import com.sun.tools.attach.VirtualMachineDescriptor; 7 | 8 | public class Filter { 9 | public VirtualMachineDescriptor getCurrentJvm(final JVMHelper jvmHelper) { 10 | final List jvms = jvmHelper.virtualMachines(); 11 | for (final VirtualMachineDescriptor virtualMachineDescriptor : jvms) { 12 | if (jvmHelper.getCurrentRuntimeName().startsWith(virtualMachineDescriptor.id())) { 13 | return virtualMachineDescriptor; 14 | } 15 | } 16 | throw new RuntimeException("could not find current virtual machine."); 17 | } 18 | 19 | public String getUnfinalizerJarPath(final Properties properties) { 20 | final String classPath = properties.getProperty("java.class.path"); 21 | final String pathSeparator = properties.getProperty("path.separator"); 22 | final String[] classPathItems = classPath.split(pathSeparator); 23 | for (final String classPathItem : classPathItems) { 24 | if (classPathItem.matches("(.*)jdave-unfinalizer(.*).jar")) { 25 | return classPathItem; 26 | } 27 | } 28 | throw new RuntimeException("cannot find jdave unfinalizer in class path"); 29 | } 30 | } -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/equality/DeltaEqualityCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.equality; 17 | 18 | import jdave.EqualityCheck; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public class DeltaEqualityCheck extends EqualityCheck { 24 | private final Number expectedNumber; 25 | private final double delta; 26 | 27 | public DeltaEqualityCheck(Number expectedNumber, double delta) { 28 | this.expectedNumber = expectedNumber; 29 | this.delta = delta; 30 | } 31 | 32 | public boolean matches(Object actual) { 33 | return (Math.abs(((Number) actual).doubleValue() - expectedNumber.doubleValue()) <= delta); 34 | } 35 | 36 | public String error(Object actual) { 37 | return "Expected: " + expectedNumber + ", but was: " + actual; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/contract/NotContract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.contract; 17 | 18 | import jdave.ExpectationFailedException; 19 | import jdave.IContract; 20 | 21 | /** 22 | * @author Joni Freeman 23 | */ 24 | public class NotContract implements IContract { 25 | private final IContract contract; 26 | 27 | public NotContract(IContract contract) { 28 | this.contract = contract; 29 | } 30 | 31 | public void isSatisfied(Object obj) throws ExpectationFailedException { 32 | try { 33 | contract.isSatisfied(obj); 34 | } catch (ExpectationFailedException e) { 35 | return; 36 | } 37 | throw new ExpectationFailedException("should not satisfy " + 38 | contract.getClass().getSimpleName() + " contract"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /jdave-junit3/src/test/jdave/junit3/JDaveSuiteTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.junit3; 17 | 18 | import jdave.Specification; 19 | import junit.framework.TestCase; 20 | 21 | /** 22 | * @author Joni Freeman 23 | */ 24 | public class JDaveSuiteTest extends TestCase { 25 | public void testShouldAddTestSuiteForEachContextInSpecification() throws Exception { 26 | JDaveSuite suite = new JDaveSuite(TestSpec.class); 27 | assertEquals(2, suite.testCount()); 28 | } 29 | 30 | public class TestSpec extends Specification { 31 | public class C1 { 32 | public void specMethod() { 33 | } 34 | } 35 | public class C2 { 36 | public void specMethod() { 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/WebDriverGroupRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver; 17 | 18 | import jdave.junit4.JDaveGroupRunner; 19 | 20 | /** 21 | * @author Juha Karemo 22 | */ 23 | public class WebDriverGroupRunner extends JDaveGroupRunner { 24 | private Browser browser = new Browser(); 25 | private WebDriverFactory webDriverFactory = new WebDriverFactory(); 26 | 27 | public WebDriverGroupRunner(Class suite) { 28 | super(suite); 29 | } 30 | 31 | @Override 32 | protected void onBeforeRun() { 33 | WebDriverHolder.set(webDriverFactory.createFireFoxDriver()); 34 | browser.open(); 35 | } 36 | 37 | @Override 38 | protected void onAfterRun() { 39 | browser.close(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/runner/Behavior.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | /** 21 | * @author Joni Freeman 22 | * @author Pekka Enberg 23 | */ 24 | public abstract class Behavior { 25 | private final Class contextType; 26 | protected final Method method; 27 | 28 | public Behavior(Class contextType, Method method) { 29 | this.contextType = contextType; 30 | this.method = method; 31 | } 32 | 33 | public String getName() { 34 | return method.getName(); 35 | } 36 | 37 | public Method getMethod() { 38 | return method; 39 | } 40 | 41 | public Class getContextType() { 42 | return contextType; 43 | } 44 | 45 | public abstract void run(final IBehaviorResults results); 46 | } 47 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/tools/SentenceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.tools; 17 | 18 | import static jdave.tools.Sentence.fromCamelCase; 19 | import static org.junit.Assert.assertEquals; 20 | 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Tommi Reiman 25 | */ 26 | public class SentenceTest { 27 | 28 | @Test 29 | public void camelCaseTestFormatsCorrectly() { 30 | assertEquals(fromCamelCase("camelCaseTest").toString(), "camel case test"); 31 | } 32 | 33 | @Test 34 | public void initialUpperCaseLetterStaysUp() { 35 | assertEquals(fromCamelCase("KissMe").toString(), "Kiss me"); 36 | } 37 | 38 | @Test 39 | public void numbersFormatCorrectly() { 40 | assertEquals(fromCamelCase("12camelsAreWorth100Euros").toString(), 41 | "12 camels are worth 100 euros"); 42 | } 43 | } -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/containment/NotContainment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.containment; 17 | 18 | import java.util.Collection; 19 | 20 | import jdave.BaseMatcherContainment; 21 | import jdave.IContainment; 22 | 23 | /** 24 | * @author Pekka Enberg 25 | */ 26 | public class NotContainment extends BaseMatcherContainment { 27 | private final IContainment containment; 28 | 29 | public NotContainment(final IContainment containment) { 30 | this.containment = containment; 31 | } 32 | 33 | public boolean matches(final Collection actual) { 34 | this.actual = actual; 35 | return !containment.matches(actual); 36 | } 37 | 38 | public String error(final Collection actual) { 39 | return "The specified collection '" + actual + "' contains '" + containment + "'"; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/BaseMatcherContainment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | import java.util.Collection; 19 | import org.hamcrest.BaseMatcher; 20 | import org.hamcrest.Description; 21 | 22 | /** 23 | * @author Tuomas Karkkainen 24 | */ 25 | public abstract class BaseMatcherContainment extends BaseMatcher> implements 26 | IContainment { 27 | 28 | protected Collection actual; 29 | 30 | @SuppressWarnings("unchecked") 31 | public final boolean matches(final Object item) { 32 | if (item instanceof Collection) { 33 | actual = (Collection) item; 34 | return matches(actual); 35 | } 36 | return false; 37 | 38 | } 39 | 40 | public final void describeTo(final Description description) { 41 | description.appendText(error(actual)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/elements/TextBox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver.elements; 17 | 18 | import jdave.webdriver.Channel; 19 | 20 | import org.openqa.selenium.WebElement; 21 | 22 | /** 23 | * @author Juha Karemo 24 | */ 25 | public class TextBox { 26 | private WebElement webElement; 27 | private Channel channel = new Channel(); 28 | 29 | public TextBox(WebElement webElement) { 30 | this.webElement = webElement; 31 | } 32 | 33 | public void clear() { 34 | webElement.clear(); 35 | channel.waitForAjax(); 36 | } 37 | 38 | public void type(String value) { 39 | webElement.sendKeys(value); 40 | channel.waitForAjax(); 41 | } 42 | 43 | public String getText() { 44 | return webElement.getValue(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/equality/PrimitiveEqualityTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.equality; 17 | 18 | import jdave.Specification; 19 | 20 | import org.junit.Test; 21 | 22 | /** 23 | * @author Joni Freeman 24 | */ 25 | public class PrimitiveEqualityTest { 26 | private Specification spec = new Specification() {}; 27 | 28 | @Test 29 | public void longEqualsInt() { 30 | spec.specify(1, spec.equal(1L)); 31 | spec.specify(1L, spec.equal(1)); 32 | } 33 | 34 | @Test 35 | public void longEqualsByte() { 36 | byte b = 1; 37 | spec.specify(b, spec.equal(1L)); 38 | spec.specify(1L, spec.equal(b)); 39 | } 40 | 41 | @Test 42 | public void intEqualsByte() { 43 | byte b = 1; 44 | spec.specify(b, spec.equal(1)); 45 | spec.specify(1, spec.equal(b)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/injection/FieldTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.injection; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import org.junit.Test; 21 | 22 | /** 23 | * @author Joni Freeman 24 | */ 25 | public class FieldTest { 26 | @Test 27 | public void testSetsValueOfField() { 28 | TestClass object = new TestClass(); 29 | Field field = field(object); 30 | field.set("test"); 31 | assertEquals("test", field.get()); 32 | } 33 | 34 | private Field field(TestClass object) { 35 | try { 36 | return new Field(object, TestClass.class.getDeclaredField("field")); 37 | } catch (Exception e) { 38 | throw new RuntimeException(e); 39 | } 40 | } 41 | 42 | class TestClass { 43 | @SuppressWarnings("unused") 44 | private String field; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jdave-junit4/src/java/jdave/junit4/CodeSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.junit4; 17 | 18 | import java.net.URL; 19 | 20 | import jdave.support.Assert; 21 | 22 | public class CodeSource { 23 | private URL location; 24 | private String dir; 25 | 26 | private CodeSource(Class clazz) { 27 | String resource = clazz.getName().replace('.', '/').concat(".class"); 28 | location = clazz.getClassLoader().getResource(resource); 29 | Assert.notNull(location, "can't find suite '" + clazz.getName() + "' with classloader"); 30 | String path = location.getPath(); 31 | dir = path.substring(0, path.lastIndexOf(resource)); 32 | } 33 | 34 | public String getDirectory() { 35 | return dir; 36 | } 37 | 38 | public static CodeSource of(Class clazz) { 39 | return new CodeSource(clazz); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/containment/AnyContainment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.containment; 17 | 18 | import java.util.Collection; 19 | import java.util.Iterator; 20 | 21 | /** 22 | * @author Joni Freeman 23 | */ 24 | public class AnyContainment extends CollectionContainment { 25 | public AnyContainment(final Collection elements) { 26 | super(elements); 27 | } 28 | 29 | public AnyContainment(final Iterator elements) { 30 | super(elements); 31 | } 32 | 33 | public AnyContainment(final Iterable elements) { 34 | super(elements); 35 | } 36 | 37 | @Override 38 | public boolean nullSafeMatches(final Collection actual) { 39 | for (final Object object : elements) { 40 | if (actual.contains(object)) { 41 | return true; 42 | } 43 | } 44 | return false; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/Retry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver; 17 | 18 | 19 | /** 20 | * @author Juha Karemo 21 | */ 22 | public class Retry { 23 | private int maxRetries = 2; 24 | 25 | public Retry(int maxRetries) { 26 | this.maxRetries = maxRetries; 27 | } 28 | 29 | public static Retry maximumTimesOf(int maxRetries) { 30 | return new Retry(maxRetries); 31 | } 32 | 33 | public void with(WaitForCondition waitForCondition) { 34 | for (int i = 0; i < maxRetries; ++i) { 35 | if (waitForCondition.isSatisfied()) { 36 | return; 37 | } else { 38 | Sleep.milliSecs(100); 39 | } 40 | } 41 | throw new RuntimeException("Condition was never satisfied!"); 42 | } 43 | 44 | public interface WaitForCondition { 45 | boolean isSatisfied(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /jdave-unfinalizer/src/java/jdave/unfinalizer/internal/ClassVisitorDelegator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package jdave.unfinalizer.internal; 17 | 18 | import jdave.org.objectweb.asm.ClassReader; 19 | import jdave.org.objectweb.asm.ClassVisitor; 20 | import jdave.org.objectweb.asm.ClassWriter; 21 | 22 | /** 23 | * Delegate class file in byte array to an ASM ClassVisitor and returns 24 | * transformed byte array. 25 | * 26 | * @author Tuomas Karkkainen 27 | */ 28 | public abstract class ClassVisitorDelegator { 29 | public byte[] transform(final byte[] originalClass) { 30 | final ClassReader reader = new ClassReader(originalClass); 31 | final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); 32 | reader.accept(createClassVisitor(writer), ClassReader.SKIP_FRAMES); 33 | return writer.toByteArray(); 34 | } 35 | 36 | protected abstract ClassVisitor createClassVisitor(final ClassWriter writer); 37 | } 38 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/equality/LongEqualsEqualityCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.equality; 17 | 18 | import jdave.EqualityCheck; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public class LongEqualsEqualityCheck extends EqualityCheck { 24 | private final long expected; 25 | 26 | public LongEqualsEqualityCheck(long expected) { 27 | this.expected = expected; 28 | } 29 | 30 | public boolean matches(Object actual) { 31 | if (actual instanceof Long) { 32 | return expected == (Long) actual; 33 | } 34 | if (actual instanceof Integer) { 35 | return expected == (Integer) actual; 36 | } 37 | if (actual instanceof Byte) { 38 | return expected == (Byte) actual; 39 | } 40 | return false; 41 | } 42 | 43 | public String error(Object actual) { 44 | return "Expected: " + expected + ", but was: " + actual; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jdave-wicket/src/test/jdave/wicket/GenerifiedComponentSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.wicket; 17 | 18 | import jdave.junit4.JDaveRunner; 19 | import org.apache.wicket.markup.html.WebMarkupContainer; 20 | import org.apache.wicket.model.IModel; 21 | import org.junit.runner.RunWith; 22 | 23 | /** 24 | * @author Joni Freeman 25 | */ 26 | @RunWith(JDaveRunner.class) 27 | public class GenerifiedComponentSpec extends ComponentSpecification, Void> { 28 | public class Any { 29 | public void startComponentDoesNotThrowExceptionBugFix() { 30 | startComponent(); 31 | } 32 | } 33 | 34 | @Override 35 | protected GenerifiedComponent newComponent(String id, IModel model) { 36 | return new GenerifiedComponent(id); 37 | } 38 | } 39 | 40 | class GenerifiedComponent extends WebMarkupContainer { 41 | public GenerifiedComponent(String id) { 42 | super(id); 43 | } 44 | } -------------------------------------------------------------------------------- /jdave-wicket-1.5/src/test/jdave/wicket/GenerifiedComponentSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.wicket; 17 | 18 | import jdave.junit4.JDaveRunner; 19 | import org.apache.wicket.markup.html.WebMarkupContainer; 20 | import org.apache.wicket.model.IModel; 21 | import org.junit.runner.RunWith; 22 | 23 | /** 24 | * @author Joni Freeman 25 | */ 26 | @RunWith(JDaveRunner.class) 27 | public class GenerifiedComponentSpec extends ComponentSpecification, Void> { 28 | public class Any { 29 | public void startComponentDoesNotThrowExceptionBugFix() { 30 | startComponent(); 31 | } 32 | } 33 | 34 | @Override 35 | protected GenerifiedComponent newComponent(String id, IModel model) { 36 | return new GenerifiedComponent(id); 37 | } 38 | } 39 | 40 | class GenerifiedComponent extends WebMarkupContainer { 41 | public GenerifiedComponent(String id) { 42 | super(id); 43 | } 44 | } -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/contract/SerializableContractTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.contract; 17 | 18 | import static org.junit.Assert.fail; 19 | import jdave.ExpectationFailedException; 20 | import jdave.Specification; 21 | 22 | import org.junit.Test; 23 | 24 | /** 25 | * @author Joni Freeman 26 | */ 27 | public class SerializableContractTest { 28 | private Specification spec = new Specification() {}; 29 | 30 | @Test 31 | public void testSerializableIsAccepted() { 32 | spec.specify(5, spec.satisfies(new SerializableContract())); 33 | } 34 | 35 | @Test 36 | public void testNonSerializableIsNotAccepted() { 37 | try { 38 | spec.specify(new NonSerializable(), spec.satisfies(new SerializableContract())); 39 | fail(); 40 | } catch (ExpectationFailedException e) { 41 | } 42 | } 43 | 44 | private static class NonSerializable { 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/elements/CheckBox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver.elements; 17 | 18 | import jdave.webdriver.Channel; 19 | 20 | import org.openqa.selenium.WebElement; 21 | 22 | /** 23 | * @author Juha Karemo 24 | */ 25 | public class CheckBox { 26 | private WebElement webElement; 27 | private Channel channel = new Channel(); 28 | 29 | public CheckBox(WebElement webElement) { 30 | this.webElement = webElement; 31 | } 32 | 33 | public void select() { 34 | if (!isSelected()) { 35 | webElement.click(); 36 | channel.waitForAjax(); 37 | } 38 | } 39 | 40 | public void unselect() { 41 | if (isSelected()) { 42 | webElement.click(); 43 | channel.waitForAjax(); 44 | } 45 | } 46 | 47 | public boolean isSelected() { 48 | return webElement.isSelected(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/containment/ObjectContainment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.containment; 17 | 18 | import java.util.Collection; 19 | 20 | import jdave.BaseMatcherContainment; 21 | 22 | /** 23 | * @author Joni Freeman 24 | */ 25 | public class ObjectContainment extends BaseMatcherContainment { 26 | 27 | private final Object object; 28 | 29 | public ObjectContainment(final Object object) { 30 | this.object = object; 31 | } 32 | 33 | public boolean matches(final Collection actual) { 34 | if (actual == null) { 35 | return false; 36 | } 37 | this.actual = actual; 38 | return actual.contains(object); 39 | } 40 | 41 | public String error(final Collection actual) { 42 | return "The specified collection '" + actual + "' does not contain '" + this + "'"; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return object.toString(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/tools/FileStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.tools; 17 | 18 | import java.io.File; 19 | import java.io.IOException; 20 | 21 | import jdave.support.IO; 22 | 23 | /** 24 | * @author Joni Freeman 25 | */ 26 | public class FileStore implements IDoxStore { 27 | private String dir; 28 | 29 | public FileStore(String dir) { 30 | this.dir = dir; 31 | } 32 | 33 | public void store(String doxName, String suffix, String content) { 34 | try { 35 | File directory = new File(dir); 36 | if (!directory.exists()) { 37 | directory.mkdirs(); 38 | } 39 | File file = newFile(directory, doxName + "." + suffix); 40 | IO.write(file, content); 41 | } catch (IOException e) { 42 | throw new DoxStoreException(e); 43 | } 44 | } 45 | 46 | protected File newFile(File dir, String name) throws IOException { 47 | return new File(dir, name); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/mock/ConcreteClassMockingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.mock; 17 | 18 | import jdave.Specification; 19 | 20 | import org.jmock.Expectations; 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Pekka Enberg 25 | */ 26 | public class ConcreteClassMockingTest { 27 | @Test 28 | public void testMockReturningInstanceOfFinalClass() { 29 | Specification specification = new Specification() { }; 30 | final PurchaseOrder mock = specification.mock(PurchaseOrder.class, "mock"); 31 | specification.checking(new Expectations() {{ 32 | one(mock).getTimestamp(); will(returnValue(new DateTime())); 33 | }}); 34 | mock.getTimestamp(); 35 | } 36 | 37 | public static class PurchaseOrder { 38 | DateTime timestamp = new DateTime(); 39 | 40 | public DateTime getTimestamp() { 41 | return timestamp; 42 | } 43 | } 44 | 45 | public static final class DateTime { 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/containment/AllContainmentTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.containment; 17 | 18 | import static org.junit.Assert.assertFalse; 19 | import static org.junit.Assert.assertTrue; 20 | import java.util.Arrays; 21 | import java.util.Iterator; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | 25 | /** 26 | * @author Joni Freeman 27 | */ 28 | public class AllContainmentTest extends ContainmentTest { 29 | @Before 30 | public void setUp() throws Exception { 31 | containment = new AllContainment(new Iterable() { 32 | public Iterator iterator() { 33 | return Arrays.asList(1, 2, 3).iterator(); 34 | } 35 | }); 36 | } 37 | 38 | @Test 39 | public void testIsInEqualList() { 40 | assertTrue(containment.matches(Arrays.asList(1, 2, 3))); 41 | } 42 | 43 | @Test 44 | public void testIsNotInPartialList() { 45 | assertFalse(containment.matches(Arrays.asList(1, 2))); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/mock/DummyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.mock; 17 | 18 | import jdave.Specification; 19 | 20 | import org.junit.Test; 21 | 22 | /** 23 | * @author Joni Freeman 24 | */ 25 | public class DummyTest { 26 | private Specification specification = new Specification() {}; 27 | 28 | @Test 29 | public void dummyMethodsAreIgnored() { 30 | Observable observable = new Observable(specification.dummy(Observer.class)); 31 | observable.poke(); 32 | specification.verifyMocks(); 33 | } 34 | 35 | static class Observable { 36 | private final Observer observer; 37 | 38 | public Observable(Observer observer) { 39 | this.observer = observer; 40 | } 41 | 42 | public void poke() { 43 | observer.changed(); 44 | } 45 | } 46 | 47 | public static class Observer { 48 | public void changed() { 49 | throw new RuntimeException(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jdave-guice/src/main/java/jdave/guice/InjectorCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package jdave.guice; 17 | 18 | import jdave.guice.internal.GuiceAnnotationEngine; 19 | import org.mockito.MockitoAnnotations; 20 | import com.google.inject.Binder; 21 | import com.google.inject.Guice; 22 | import com.google.inject.Injector; 23 | import com.google.inject.Module; 24 | 25 | /** 26 | *

27 | * Create an instance of this, and call createInjector(interested) to create 28 | * mocks and bind them. 29 | *

30 | */ 31 | public class InjectorCreator { 32 | public Injector createInjector(final InterestedInGuice interested) { 33 | return Guice.createInjector(new Module() { 34 | public void configure(final Binder binder) { 35 | GuiceAnnotationEngine.binder.set(binder); 36 | MockitoAnnotations.initMocks(interested); 37 | interested.addBindings(binder); 38 | GuiceAnnotationEngine.binder.remove(); 39 | } 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/tools/SpecdoxTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.tools; 17 | 18 | 19 | import org.jmock.Expectations; 20 | import org.jmock.Mockery; 21 | import org.jmock.integration.junit4.JMock; 22 | import org.jmock.integration.junit4.JUnit4Mockery; 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | 26 | /** 27 | * @author Joni Freeman 28 | */ 29 | @RunWith(JMock.class) 30 | public class SpecdoxTest { 31 | private Mockery context = new JUnit4Mockery(); 32 | private IDoxStore doxStore = context.mock(IDoxStore.class); 33 | private Specdox dox = new Specdox(doxStore); 34 | 35 | @Test 36 | public void testSavesPlainTextVersionToDoxStore() { 37 | final String expectedOutput = 38 | "StackSpec:\n\n" + 39 | "Full stack\n" + 40 | " - complains on push\n"; 41 | context.checking(new Expectations() {{ 42 | one(doxStore).store("StackSpec", "txt", expectedOutput); 43 | }}); 44 | dox.generate(StackSpec.class, new PlainTextFormat()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/Browser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver; 17 | 18 | import org.openqa.selenium.WebDriver; 19 | import org.openqa.selenium.WebDriver.Options; 20 | 21 | /** 22 | * @author Juha Karemo 23 | */ 24 | public class Browser { 25 | private final String profileName; 26 | 27 | public Browser() { 28 | this(null); 29 | } 30 | 31 | public Browser(String profileName) { 32 | this.profileName = profileName; 33 | } 34 | 35 | public void open() { 36 | // TODO: this is madness, isn't there any other way to set the profile name 37 | if (profileName != null) { 38 | System.setProperty("webdriver.firefox.profile", profileName); 39 | } 40 | } 41 | 42 | public void close() { 43 | WebDriver webDriver = WebDriverHolder.get(); 44 | Options options = webDriver.manage(); 45 | if (options != null) { 46 | options.deleteAllCookies(); 47 | } 48 | webDriver.quit(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/containment/ExactContainment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.containment; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Collection; 20 | import java.util.Iterator; 21 | import java.util.List; 22 | 23 | /** 24 | * @author Joni Freeman 25 | */ 26 | public class ExactContainment extends CollectionContainment { 27 | public ExactContainment(final Collection elements) { 28 | super(elements); 29 | } 30 | 31 | public ExactContainment(final Iterator elements) { 32 | super(elements); 33 | } 34 | 35 | public ExactContainment(final Iterable elements) { 36 | super(elements); 37 | } 38 | 39 | @Override 40 | public boolean nullSafeMatches(final Collection actual) { 41 | if (actual.size() != elements.size()) { 42 | return false; 43 | } 44 | final List remaining = new ArrayList(actual); 45 | for (final Object element : elements) { 46 | remaining.remove(element); 47 | } 48 | return remaining.isEmpty(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/containment/MapContainment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.containment; 17 | 18 | import java.util.Map; 19 | 20 | import jdave.ExpectationFailedException; 21 | import jdave.support.Assert; 22 | 23 | /** 24 | * @author Joni Freeman 25 | */ 26 | public class MapContainment { 27 | private final Object[] keys; 28 | private Object[] values; 29 | 30 | public MapContainment(Object... keys) { 31 | this.keys = keys; 32 | } 33 | 34 | public MapContainment to(Object... values) { 35 | Assert.isTrue(keys.length == values.length, "number of keys " + keys.length + " does not match number of values " + values.length); 36 | this.values = values; 37 | return this; 38 | } 39 | 40 | public void verify(Map map) { 41 | for (int i = 0; i < keys.length; i++) { 42 | Object key = map.get(keys[i]); 43 | if (key == null || !key.equals(values[i])) { 44 | throw new ExpectationFailedException("no mapping " + keys[i] + " -> " + values[i]); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /jdave-unfinalizer/src/test/jdave/unfinalizer/agent/InstrumentationAgentSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package jdave.unfinalizer.agent; 17 | 18 | import static org.mockito.Matchers.isA; 19 | import static org.mockito.Mockito.verify; 20 | 21 | import java.lang.instrument.Instrumentation; 22 | 23 | import jdave.Specification; 24 | import jdave.junit4.JDaveRunner; 25 | import jdave.unfinalizer.agent.InstrumentationAgent; 26 | import jdave.unfinalizer.internal.DelegatingClassFileTransformer; 27 | 28 | import org.junit.runner.RunWith; 29 | import org.mockito.Mockito; 30 | 31 | /** 32 | * @author Tuomas Karkkainen 33 | */ 34 | @RunWith(JDaveRunner.class) 35 | public class InstrumentationAgentSpec extends Specification { 36 | public class WhenPremainIsCalled { 37 | public void unfinalizingTransformerIsAdded() { 38 | final Instrumentation instrumentation = Mockito.mock(Instrumentation.class); 39 | InstrumentationAgent.agentmain(null, instrumentation); 40 | verify(instrumentation).addTransformer(isA(DelegatingClassFileTransformer.class)); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/ExpectedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * @author Lasse Koskela 20 | */ 21 | public class ExpectedException { 22 | protected final Class expected; 23 | 24 | public ExpectedException(Class expected) { 25 | this.expected = expected; 26 | } 27 | 28 | public boolean matches(Throwable t) { 29 | return matchesType(t.getClass()); 30 | } 31 | 32 | public String error(Throwable t) { 33 | if (!matchesType(t.getClass())) { 34 | return "The specified block should throw " 35 | + expected.getName() + " but " + t.getClass().getName() 36 | + " was thrown."; 37 | } 38 | throw new IllegalStateException(); 39 | } 40 | 41 | protected boolean matchesType(Class actual) { 42 | return expected.isAssignableFrom(actual); 43 | } 44 | 45 | public String notThrown() { 46 | return "The specified block should throw " + expected.getName() + " but nothing was thrown."; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /jdave-wicket/src/test/jdave/wicket/EmptyPanelSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.wicket; 17 | 18 | import jdave.junit4.JDaveRunner; 19 | import org.apache.wicket.model.IModel; 20 | import static org.hamcrest.Matchers.sameInstance; 21 | import org.junit.runner.RunWith; 22 | 23 | /** 24 | * @author Joni Freeman 25 | */ 26 | @RunWith(JDaveRunner.class) 27 | public class EmptyPanelSpec extends ComponentSpecification { 28 | private EmptyPanel panel; 29 | 30 | public class WhenContainerIsStarted { 31 | public EmptyPanel create() { 32 | return startComponent(null); 33 | } 34 | 35 | public void theContextIsSameInstanceAsPanelCreatedInNewContainer() { 36 | specify(context, sameInstance(panel)); 37 | } 38 | 39 | public void wicketTesterInstanceIsCreated() { 40 | specify(wicket, should.not().equal(null)); 41 | } 42 | } 43 | 44 | @Override 45 | protected EmptyPanel newComponent(String id, IModel model) { 46 | return panel = new EmptyPanel(id); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /jdave-wicket-1.5/src/test/jdave/wicket/EmptyPanelSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.wicket; 17 | 18 | import jdave.junit4.JDaveRunner; 19 | import org.apache.wicket.model.IModel; 20 | import static org.hamcrest.Matchers.sameInstance; 21 | import org.junit.runner.RunWith; 22 | 23 | /** 24 | * @author Joni Freeman 25 | */ 26 | @RunWith(JDaveRunner.class) 27 | public class EmptyPanelSpec extends ComponentSpecification { 28 | private EmptyPanel panel; 29 | 30 | public class WhenContainerIsStarted { 31 | public EmptyPanel create() { 32 | return startComponent(null); 33 | } 34 | 35 | public void theContextIsSameInstanceAsPanelCreatedInNewContainer() { 36 | specify(context, sameInstance(panel)); 37 | } 38 | 39 | public void wicketTesterInstanceIsCreated() { 40 | specify(wicket, should.not().equal(null)); 41 | } 42 | } 43 | 44 | @Override 45 | protected EmptyPanel newComponent(String id, IModel model) { 46 | return panel = new EmptyPanel(id); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /jdave-unfinalizer/src/java/jdave/unfinalizer/agent/InstrumentationAgent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package jdave.unfinalizer.agent; 17 | 18 | import java.lang.instrument.Instrumentation; 19 | 20 | import jdave.unfinalizer.internal.DelegatingClassFileTransformer; 21 | import jdave.unfinalizer.internal.UnfinalizingClassVisitorDelegator; 22 | 23 | /** 24 | * Adds unfinalizing transformer to instrumentation class loading stack. 25 | * 26 | * @author Tuomas Karkkainen 27 | */ 28 | public class InstrumentationAgent { 29 | public static void agentmain(@SuppressWarnings("unused") 30 | final String agentArgs, final Instrumentation instrumentation) { 31 | addTransformer(instrumentation); 32 | } 33 | 34 | public static void premain(@SuppressWarnings("unused") 35 | final String agentArgs, final Instrumentation instrumentation) { 36 | addTransformer(instrumentation); 37 | } 38 | 39 | private static void addTransformer(final Instrumentation instrumentation) { 40 | instrumentation.addTransformer(new DelegatingClassFileTransformer(new UnfinalizingClassVisitorDelegator())); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/StringEqualsEqualityCheck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | import jdave.equality.EqualsEqualityCheck; 19 | import jdave.util.Diff; 20 | 21 | /** 22 | * @author Joni Freeman 23 | */ 24 | public class StringEqualsEqualityCheck extends EqualsEqualityCheck { 25 | private final Specification specification; 26 | 27 | public StringEqualsEqualityCheck(Specification specification, String expected) { 28 | super(expected); 29 | this.specification = specification; 30 | } 31 | 32 | @Override 33 | public String error(Object actual) { 34 | if (actual == null || !actual.getClass().equals(String.class)) { 35 | return super.error(actual); 36 | } 37 | Diff diff = Diff.diff((String) actual, (String) expected); 38 | return "The given strings do not match:\n" + diff.verbose(); 39 | } 40 | 41 | @Override 42 | public void verify(Object actual) { 43 | if (!matches(actual)) { 44 | specification.stringComparisonFailure().fail(error(actual), (String) expected, (String) actual); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/ILifecycleListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave; 17 | 18 | /** 19 | * A listener which will get notifications when new contexts are created. 20 | * 21 | * @see Specification#addListener(ILifecycleListener) 22 | * 23 | * @author Joni Freeman 24 | */ 25 | public interface ILifecycleListener { 26 | /** 27 | * Called just after a context has been instantiated. 28 | * 29 | * @param contextInstance the instantiated context 30 | */ 31 | void afterContextInstantiation(Object contextInstance); 32 | 33 | /** 34 | * Called just after context's create method has been called. 35 | * 36 | * @param contextInstance the holding context 37 | * @param createdContext the object which was returned from create method 38 | */ 39 | void afterContextCreation(Object contextInstance, Object createdContext); 40 | 41 | /** 42 | * Called just after context's destroy method has been called. 43 | * 44 | * @param contextInstance the context instance 45 | */ 46 | void afterContextDestroy(Object contextInstance); 47 | } 48 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/containment/ObjectContainmentTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.containment; 17 | 18 | import static java.util.Arrays.asList; 19 | import static org.hamcrest.Matchers.is; 20 | import static org.junit.Assert.assertThat; 21 | import org.hamcrest.StringDescription; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | 25 | /** 26 | * @author Tuomas Kärkkäinen 27 | */ 28 | public class ObjectContainmentTest extends ContainmentTest { 29 | 30 | @Before 31 | public void setUp() throws Exception { 32 | containment = new ObjectContainment(1); 33 | } 34 | 35 | @Test 36 | public void canBeUsedAsAMatcher() { 37 | assertThat(asList(1), containment); 38 | } 39 | 40 | @Test 41 | public void describesWell() { 42 | final StringDescription description = new StringDescription(); 43 | containment.matches(asList(9)); 44 | containment.describeTo(description); 45 | assertThat(description.toString(), 46 | is("The specified collection '[9]' does not contain '1'")); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /jdave-examples/src/test/jdave/examples/ObservableSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.examples; 17 | 18 | import jdave.Specification; 19 | import jdave.examples.observer.Observable; 20 | import jdave.examples.observer.Observer; 21 | import jdave.junit4.JDaveRunner; 22 | 23 | import org.jmock.Expectations; 24 | import org.junit.runner.RunWith; 25 | 26 | /** 27 | * @author Joni Freeman 28 | */ 29 | @RunWith(JDaveRunner.class) 30 | public class ObservableSpec extends Specification { 31 | public class ObservableHavingObserver { 32 | private Observable observable; 33 | private Observer observer; 34 | 35 | public Observable create() { 36 | observable = new Observable(); 37 | observer = mock(Observer.class); 38 | observable.register(observer); 39 | return observable; 40 | } 41 | 42 | public void callsOnActionWhenSignificantEventHappens() { 43 | checking(new Expectations() {{ 44 | one(observer).onAction(observable); 45 | }}); 46 | observable.significantEvent(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/tools/SpecdoxRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.tools; 17 | 18 | import jdave.Specification; 19 | 20 | /** 21 | * @author Joni Freeman 22 | */ 23 | public class SpecdoxRunner { 24 | public static final String FORMAT = "jdave.tools.specdox.format"; 25 | public static final String DIRNAME = "jdave.tools.specdox.dir"; 26 | private final Formats formats; 27 | 28 | public SpecdoxRunner() { 29 | this(new Formats()); 30 | } 31 | 32 | public SpecdoxRunner(Formats formats) { 33 | this.formats = formats; 34 | } 35 | 36 | public void generate(Class> specType) { 37 | if (System.getProperty(FORMAT) != null) { 38 | for (String s : System.getProperty(FORMAT).split("\\s+")) { 39 | IDoxFormat format = formats.formatFor(s); 40 | Specdox specdox = new Specdox(new FileStore(dirname())); 41 | specdox.generate(specType, format); 42 | } 43 | } 44 | } 45 | 46 | private String dirname() { 47 | return System.getProperty(DIRNAME, "target/jdave"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/containment/DuplicatesValuesInExpectedCollectionExactContainmentTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.containment; 17 | 18 | import static org.junit.Assert.assertFalse; 19 | import static org.junit.Assert.assertTrue; 20 | import java.util.Arrays; 21 | import java.util.Iterator; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | 25 | /** 26 | * @author Pekka Enberg 27 | */ 28 | public class DuplicatesValuesInExpectedCollectionExactContainmentTest extends ContainmentTest { 29 | @Before 30 | public void setUp() throws Exception { 31 | containment = new ExactContainment(new Iterable() { 32 | public Iterator iterator() { 33 | return Arrays.asList(1, 2, 2).iterator(); 34 | } 35 | }); 36 | } 37 | 38 | @Test 39 | public void testIsInListWhichMatchesTotally() { 40 | assertTrue(containment.matches(Arrays.asList(1, 2, 2))); 41 | } 42 | 43 | @Test 44 | public void testIsNotInListWhichMatchesPartially() { 45 | assertFalse(containment.matches(Arrays.asList(1, 2, 3))); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/injection/Field.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.injection; 17 | 18 | 19 | /** 20 | * @author Joni Freeman 21 | */ 22 | public class Field { 23 | private final Object object; 24 | private final java.lang.reflect.Field field; 25 | 26 | Field(Object object, java.lang.reflect.Field field) { 27 | this.object = object; 28 | this.field = field; 29 | field.setAccessible(true); 30 | } 31 | 32 | public void set(Object value) { 33 | try { 34 | field.set(object, value); 35 | } catch (IllegalArgumentException e) { 36 | throw new ReflectionException(e); 37 | } catch (IllegalAccessException e) { 38 | throw new ReflectionException(e); 39 | } 40 | } 41 | 42 | public Object get() { 43 | try { 44 | return field.get(object); 45 | } catch (IllegalArgumentException e) { 46 | throw new ReflectionException(e); 47 | } catch (IllegalAccessException e) { 48 | throw new ReflectionException(e); 49 | } 50 | } 51 | 52 | public java.lang.reflect.Field field() { 53 | return field; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/contract/SerializableContract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.contract; 17 | 18 | import java.io.IOException; 19 | import java.io.ObjectOutputStream; 20 | import java.io.OutputStream; 21 | import jdave.ExpectationFailedException; 22 | import jdave.IContract; 23 | 24 | /** 25 | * @author Joni Freeman 26 | */ 27 | public class SerializableContract implements IContract { 28 | public void isSatisfied(Object obj) throws ExpectationFailedException { 29 | ObjectOutputStream stream; 30 | try { 31 | stream = new ObjectOutputStream(new OutputStream() { 32 | @Override 33 | public void write(int b) { 34 | } 35 | }); 36 | } catch (IOException e) { 37 | throw new RuntimeException(e); 38 | } 39 | 40 | try { 41 | stream.writeObject(obj); 42 | } catch (IOException e) { 43 | throw new ExpectationFailedException(obj + " is not serializable", e); 44 | } finally { 45 | try { 46 | stream.close(); 47 | } catch (IOException e) { 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/tools/PlainTextFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.tools; 17 | 18 | /** 19 | * @author Joni Freeman 20 | */ 21 | public class PlainTextFormat implements IDoxFormat { 22 | private StringBuilder dox = new StringBuilder(); 23 | private String specName; 24 | 25 | public void newSpec(String specName, String fqn) { 26 | this.specName = specName; 27 | } 28 | 29 | public void endSpec(String specName) { 30 | } 31 | 32 | public void newContext(String contextName) { 33 | if (dox.length() > 0) { 34 | dox.append("\n"); 35 | } 36 | dox.append(Sentence.fromCamelCase(contextName)); 37 | dox.append("\n"); 38 | } 39 | 40 | public void endContext(String name) { 41 | } 42 | 43 | public void newBehavior(String behaviorName) { 44 | dox.append(" - "); 45 | dox.append(Sentence.fromCamelCase(behaviorName)); 46 | dox.append("\n"); 47 | } 48 | 49 | public String suffix() { 50 | return "txt"; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return specName + ":\n\n" + dox.toString(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /jdave-junit4/src/java/jdave/junit4/ResultsAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.junit4; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import jdave.ExpectationFailedException; 21 | import jdave.runner.IBehaviorResults; 22 | 23 | import org.junit.runner.Description; 24 | import org.junit.runner.notification.Failure; 25 | import org.junit.runner.notification.RunNotifier; 26 | 27 | /** 28 | * The ResultsAdapter receives failure notifications from JDave and forwards 29 | * them to JUnit's RunNotifier. 30 | * 31 | * @author Lasse Koskela 32 | */ 33 | public class ResultsAdapter implements IBehaviorResults { 34 | private final RunNotifier notifier; 35 | private final Description desc; 36 | 37 | ResultsAdapter(RunNotifier notifier, Description desc) { 38 | this.notifier = notifier; 39 | this.desc = desc; 40 | } 41 | 42 | public void error(Method m, Throwable e) { 43 | notifier.fireTestFailure(new Failure(desc, e)); 44 | } 45 | 46 | public void expected(Method m) { 47 | // ignored 48 | } 49 | 50 | public void unexpected(Method m, ExpectationFailedException e) { 51 | notifier.fireTestFailure(new Failure(desc, e)); 52 | } 53 | } -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/test/jdave/webdriver/elements/LinkSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver.elements; 17 | 18 | import jdave.Specification; 19 | import jdave.junit4.JDaveRunner; 20 | import jdave.webdriver.Channel; 21 | 22 | import org.jmock.Expectations; 23 | import org.junit.runner.RunWith; 24 | import org.laughingpanda.beaninject.Inject; 25 | import org.openqa.selenium.WebElement; 26 | 27 | /** 28 | * @author Juha Karemo 29 | */ 30 | @RunWith(JDaveRunner.class) 31 | public class LinkSpec extends Specification { 32 | public class AnyLink { 33 | private WebElement webElement = mock(WebElement.class); 34 | private Channel channel = mock(Channel.class); 35 | 36 | public Link create() { 37 | Link link = new Link(webElement); 38 | Inject.field("channel").of(link).with(channel); 39 | return link; 40 | } 41 | 42 | public void canBeClicked() { 43 | checking(new Expectations() {{ 44 | one(webElement).click(); 45 | one(channel).waitForAjax(); 46 | }}); 47 | context.click(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jdave-junit4/src/test/jdave/junit4/specs/DiverseSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.junit4.specs; 17 | 18 | import java.util.Stack; 19 | 20 | import jdave.Specification; 21 | 22 | /** 23 | * This is a sample spec with a mix of passing and intentionally failing tests. It is used for testing the JUnit 4 runner. 24 | * 25 | * @author Lasse Koskela 26 | */ 27 | public class DiverseSpec extends Specification> { 28 | public class FirstContext { 29 | private Stack stack; 30 | 31 | public Stack create() { 32 | stack = new Stack(); 33 | return stack; 34 | } 35 | 36 | public void passes() { 37 | } 38 | 39 | public void fails() { 40 | stack.push("anything"); 41 | specify(stack, should.be.empty()); // intentional failure 42 | } 43 | } 44 | 45 | public class SecondContext { 46 | private Stack stack; 47 | 48 | public Stack create() { 49 | stack = new Stack(); 50 | return stack; 51 | } 52 | 53 | public void throwsException() { 54 | throw new RuntimeException("intentional"); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/test/jdave/webdriver/elements/WebElementsSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver.elements; 17 | 18 | import java.util.Arrays; 19 | import java.util.List; 20 | 21 | import jdave.Specification; 22 | import jdave.junit4.JDaveRunner; 23 | import jdave.util.Fields; 24 | 25 | import org.junit.runner.RunWith; 26 | import org.openqa.selenium.WebElement; 27 | 28 | /** 29 | * @author Juha Karemo 30 | */ 31 | @RunWith(JDaveRunner.class) 32 | public class WebElementsSpec extends Specification> { 33 | public class ListOfWebElements { 34 | private WebElement webElement = mock(WebElement.class, "we1"); 35 | private WebElement webElement2 = mock(WebElement.class, "we2"); 36 | 37 | public List create() { 38 | return Arrays.asList(webElement, webElement2); 39 | } 40 | 41 | public void canBeConvertedToLinks() { 42 | List links = WebElements.asLinks(context); 43 | specify(Fields.get(links.get(0), "webElement"), does.equal(webElement)); 44 | specify(Fields.get(links.get(1), "webElement"), does.equal(webElement2)); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /jdave-junit3/src/test/jdave/junit3/ResultAdapterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.junit3; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import jdave.ExpectationFailedException; 21 | import jdave.junit3.JDaveSuite.ResultAdapter; 22 | import junit.framework.TestCase; 23 | import junit.framework.TestResult; 24 | 25 | /** 26 | * @author Joni Freeman 27 | */ 28 | public class ResultAdapterTest extends TestCase { 29 | private TestCase test; 30 | private TestResult result; 31 | private ResultAdapter adapter; 32 | private Method method; 33 | 34 | @Override 35 | protected void setUp() throws Exception { 36 | result = new TestResult(); 37 | test = new TestCase("test") {}; 38 | adapter = new JDaveSuite.ResultAdapter(test, result); 39 | method = ResultAdapterTest.class.getDeclaredMethod("setUp"); 40 | } 41 | 42 | public void testShouldAdaptError() { 43 | adapter.error(method, new Exception()); 44 | assertEquals(1, result.errorCount()); 45 | } 46 | 47 | public void testShouldAdaptFailure() { 48 | adapter.unexpected(method, new ExpectationFailedException("")); 49 | assertEquals(1, result.failureCount()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/tools/FileStoreTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.tools; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.junit.Assert.assertTrue; 20 | 21 | import java.io.File; 22 | import java.io.FileInputStream; 23 | import java.io.FileNotFoundException; 24 | import java.io.IOException; 25 | 26 | import jdave.support.IO; 27 | 28 | import org.junit.Before; 29 | import org.junit.Test; 30 | 31 | /** 32 | * @author Joni Freeman 33 | */ 34 | public class FileStoreTest { 35 | private IDoxStore store; 36 | private File file; 37 | 38 | @Before 39 | public void setUp() throws Exception { 40 | store = new FileStore("target/jdave") { 41 | @Override 42 | protected File newFile(File dir, String name) throws IOException { 43 | file = File.createTempFile(name, "", dir); 44 | return file; 45 | } 46 | }; 47 | } 48 | 49 | @Test 50 | public void testCreatesFileBySpecName() throws FileNotFoundException, IOException { 51 | store.store("Test", "txt", "content"); 52 | assertTrue(file.exists()); 53 | assertEquals("content", IO.read(new FileInputStream(file))); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /jdave-junit4/src/test/jdave/junit4/StringComparisonFailureTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.junit4; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import jdave.Specification; 20 | import junit.framework.ComparisonFailure; 21 | import org.junit.Test; 22 | import org.junit.runner.notification.Failure; 23 | import org.junit.runner.notification.RunNotifier; 24 | 25 | public class StringComparisonFailureTest { 26 | private Throwable actualException; 27 | 28 | @Test 29 | public void testThrowsComparisonFailureExceptionWhenComparingNonEqualStrings() { 30 | final JDaveRunner runner = new JDaveRunner(FailingSpec.class); 31 | runner.run(new RunNotifier() { 32 | @Override 33 | public void fireTestFailure(final Failure failure) { 34 | actualException = failure.getException(); 35 | } 36 | }); 37 | assertEquals(ComparisonFailure.class, actualException.getClass()); 38 | } 39 | 40 | public static class FailingSpec extends Specification { 41 | public class FailingContext { 42 | public void failingBehavior() { 43 | specify("foo", does.equal("bar")); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/java/jdave/webdriver/WebDriverSpecRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver; 17 | 18 | import jdave.Specification; 19 | import jdave.junit4.JDaveRunner; 20 | 21 | import org.junit.runner.Description; 22 | import org.junit.runner.Runner; 23 | import org.junit.runner.notification.RunNotifier; 24 | 25 | /** 26 | * @author Juha Karemo 27 | */ 28 | public class WebDriverSpecRunner extends Runner { 29 | protected Runner jDaveRunner; 30 | protected WebDriverFactory webDriverFactory = new WebDriverFactory(); 31 | protected Browser browser = new Browser(); 32 | 33 | public WebDriverSpecRunner(Class> spec) { 34 | jDaveRunner = new JDaveRunner(spec); 35 | } 36 | 37 | @Override 38 | public Description getDescription() { 39 | return jDaveRunner.getDescription(); 40 | } 41 | 42 | @Override 43 | public void run(RunNotifier notifier) { 44 | WebDriverHolder.set(webDriverFactory.createFireFoxDriver()); 45 | try { 46 | browser.open(); 47 | jDaveRunner.run(notifier); 48 | } finally { 49 | browser.close(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jdave-wicket-webdriver/src/test/jdave/webdriver/RetrySpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.webdriver; 17 | 18 | import jdave.Block; 19 | import jdave.Specification; 20 | import jdave.junit4.JDaveRunner; 21 | 22 | import org.hamcrest.Matchers; 23 | import org.junit.runner.RunWith; 24 | 25 | /** 26 | * @author Marko Sibakov 27 | */ 28 | @RunWith(JDaveRunner.class) 29 | public class RetrySpec extends Specification { 30 | public class WithTwoRetriesAndNeverSatisfied { 31 | public Retry create() { 32 | return new Retry(2); 33 | } 34 | 35 | public void triesAtLeastTwoHundedMillis() { 36 | long startMillis = System.currentTimeMillis(); 37 | 38 | specify(new Block() { 39 | public void run() throws Throwable { 40 | context.with(new Retry.WaitForCondition() { 41 | public boolean isSatisfied() { 42 | return false; 43 | }}); 44 | } 45 | }, does.raiseExactly(RuntimeException.class)); 46 | long endMillis = System.currentTimeMillis(); 47 | specify(endMillis - startMillis, Matchers.greaterThan(200L)); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jdave-core/src/test/jdave/runner/SpecRunnerVisitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.runner; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import jdave.Specification; 20 | 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author Joni Freeman 25 | */ 26 | public class SpecRunnerVisitTest { 27 | private SpecRunner runner = new SpecRunner(); 28 | private Behavior visitedMethod; 29 | 30 | @Test 31 | public void testUsesVisitingSpecMethod() throws Exception { 32 | runner.visit(TestSpec.class, new ISpecVisitor() { 33 | public void onContext(Context context) { 34 | } 35 | 36 | public void onBehavior(Behavior method) { 37 | visitedMethod = method; 38 | } 39 | 40 | public void afterContext(Context context) { 41 | } 42 | }); 43 | assertEquals(visitedMethod.getClass(), VisitingBehavior.class); 44 | } 45 | 46 | public static class TestSpec extends Specification { 47 | public class SomeContext { 48 | public Object create() { 49 | return new Object(); 50 | } 51 | 52 | public void someMethod() { 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /jdave-report-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | org.jdave 6 | jdave-parent 7 | 1.5-SNAPSHOT 8 | 9 | 10 | jdave-report-plugin 11 | jdave-report-plugin 12 | maven-plugin 13 | 14 | 15 | 16 | org.apache.maven 17 | maven-plugin-api 18 | 2.0 19 | 20 | 21 | org.apache.maven.reporting 22 | maven-reporting-api 23 | 2.0 24 | 25 | 26 | org.apache.maven.reporting 27 | maven-reporting-impl 28 | 2.0 29 | 30 | 31 | net.sf.saxon 32 | saxon 33 | 8.7 34 | 35 | 36 | ${project.groupId} 37 | jdave-core 38 | ${project.version} 39 | 40 | 41 | ${project.groupId} 42 | jdave-junit4 43 | ${project.version} 44 | test 45 | 46 | 47 | 48 | 49 | 50 | 51 | src/resources 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /jdave-core/src/java/jdave/util/Fields.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jdave.util; 17 | 18 | import java.lang.reflect.Field; 19 | 20 | 21 | /** 22 | * @author Pekka Enberg 23 | * @author Juha Karemo 24 | */ 25 | public class Fields { 26 | public static void set(Object object, String fieldName, Object value) { 27 | try { 28 | object.getClass().getField(fieldName).set(object, value); 29 | } catch (Exception e) { 30 | throw new RuntimeException(e); 31 | } 32 | } 33 | 34 | public static Object get(Object object, String fieldName) { 35 | try { 36 | Field field = object.getClass().getDeclaredField(fieldName); 37 | field.setAccessible(true); 38 | return field.get(object); 39 | } catch (Exception e) { 40 | throw new RuntimeException(e); 41 | } 42 | } 43 | 44 | @SuppressWarnings("unchecked") 45 | public static T getStatic(Class clazz, String fieldName) { 46 | try { 47 | Field field = clazz.getDeclaredField(fieldName); 48 | field.setAccessible(true); 49 | return (T) field.get(clazz); 50 | } catch (Exception e) { 51 | throw new RuntimeException(e); 52 | } 53 | } 54 | } 55 | --------------------------------------------------------------------------------