> {
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