Permalink
Browse files

Merge remote branch 'remotes/upstream/master'

Conflicts:
	src/test/java/org/junit/tests/experimental/rules/TestRuleTest.java
  • Loading branch information...
2 parents be8d4ee + 2e53904 commit 6caeeb1e1579cae1cd9ede58f38186e07da7f295 @mmichaelis mmichaelis committed Aug 26, 2012
Showing with 1,029 additions and 575 deletions.
  1. +1 −1 .classpath
  2. +0 −1 README.html
  3. +3 −2 build.xml
  4. +1 −1 build/maven/junit-pom-template.xml
  5. +1 −1 build/maven/sample_project_template/pom.xml
  6. +1 −1 build/profile_junit.sh
  7. BIN lib/hamcrest-core-1.1.jar
  8. BIN lib/hamcrest-core-1.3-sources.jar
  9. BIN lib/hamcrest-core-1.3.jar
  10. +4 −19 src/main/java/org/junit/Assert.java
  11. +2 −2 src/main/java/org/junit/Assume.java
  12. +1 −1 src/main/java/org/junit/experimental/results/ResultMatchers.java
  13. +8 −3 src/main/java/org/junit/experimental/theories/Theories.java
  14. +26 −12 src/main/java/org/junit/experimental/theories/internal/AllMembersSupplier.java
  15. +0 −22 src/main/java/org/junit/internal/matchers/CauseMatcher.java
  16. +0 −34 src/main/java/org/junit/internal/matchers/CombinableMatcher.java
  17. +0 −24 src/main/java/org/junit/internal/matchers/Each.java
  18. +0 −67 src/main/java/org/junit/internal/matchers/IsCollectionContaining.java
  19. +56 −0 src/main/java/org/junit/internal/matchers/StacktracePrintingMatcher.java
  20. +0 −31 src/main/java/org/junit/internal/matchers/StringContains.java
  21. +0 −28 src/main/java/org/junit/internal/matchers/SubstringMatcher.java
  22. +37 −0 src/main/java/org/junit/internal/matchers/ThrowableCauseMatcher.java
  23. +37 −0 src/main/java/org/junit/internal/matchers/ThrowableMessageMatcher.java
  24. +3 −0 src/main/java/org/junit/internal/matchers/TypeSafeMatcher.java
  25. +60 −27 src/main/java/org/junit/matchers/JUnitMatchers.java
  26. +17 −48 src/main/java/org/junit/rules/ExpectedException.java
  27. +46 −0 src/main/java/org/junit/rules/ExpectedExceptionMatcherBuilder.java
  28. +1 −1 src/main/java/org/junit/rules/RuleChain.java
  29. +20 −13 src/main/java/org/junit/rules/TemporaryFolder.java
  30. +50 −7 src/main/java/org/junit/rules/TestWatcher.java
  31. +1 −1 src/main/java/org/junit/rules/Timeout.java
  32. +1 −1 src/main/java/org/junit/rules/Verifier.java
  33. +29 −4 src/main/java/org/junit/runner/Description.java
  34. +2 −2 src/main/java/org/junit/runners/BlockJUnit4ClassRunner.java
  35. +121 −0 src/main/java/org/junit/runners/Parameterized.java
  36. +6 −6 src/test/java/org/junit/internal/MethodSorterTest.java
  37. +37 −0 src/test/java/org/junit/internal/matchers/StacktracePrintingMatcherTest.java
  38. +4 −8 src/test/java/org/junit/tests/AllTests.java
  39. +6 −16 src/test/java/org/junit/tests/assertion/AssertionTest.java
  40. +0 −71 src/test/java/org/junit/tests/assertion/BothTest.java
  41. +0 −18 src/test/java/org/junit/tests/assertion/CauseMatcherTest.java
  42. +0 −13 src/test/java/org/junit/tests/assertion/EachTest.java
  43. +1 −1 src/test/java/org/junit/tests/experimental/AssumptionTest.java
  44. +1 −1 src/test/java/org/junit/tests/experimental/AssumptionViolatedExceptionTest.java
  45. +42 −0 src/test/java/org/junit/tests/experimental/max/DescriptionTest.java
  46. +1 −1 src/test/java/org/junit/tests/experimental/max/MaxStarterTest.java
  47. +1 −1 src/test/java/org/junit/tests/experimental/parallel/ParallelClassTest.java
  48. +1 −1 src/test/java/org/junit/tests/experimental/parallel/ParallelMethodTest.java
  49. +1 −2 src/test/java/org/junit/tests/experimental/results/PrintableResultTest.java
  50. +1 −1 src/test/java/org/junit/tests/experimental/results/ResultMatchersTest.java
  51. +3 −3 src/test/java/org/junit/tests/experimental/rules/EventCollector.java
  52. +15 −28 src/test/java/org/junit/tests/experimental/rules/ExpectedExceptionTest.java
  53. +2 −2 src/test/java/org/junit/tests/experimental/rules/MethodRulesTest.java
  54. +2 −2 src/test/java/org/junit/tests/experimental/rules/TempFolderRuleTest.java
  55. +56 −18 src/test/java/org/junit/tests/experimental/rules/TemporaryFolderUsageTest.java
  56. +9 −0 src/test/java/org/junit/tests/experimental/rules/TestRuleTest.java
  57. +80 −0 src/test/java/org/junit/tests/experimental/rules/TestWatcherTest.java
  58. +1 −1 src/test/java/org/junit/tests/experimental/rules/TimeoutRuleTest.java
  59. +4 −4 src/test/java/org/junit/tests/experimental/rules/VerifierRuleTest.java
  60. +4 −5 src/test/java/org/junit/tests/experimental/theories/ParameterSignatureTest.java
  61. +1 −1 src/test/java/org/junit/tests/experimental/theories/ParameterizedAssertionErrorTest.java
  62. +57 −0 ...t/java/org/junit/tests/experimental/theories/runner/TypeMatchingBetweenMultiDataPointsMethod.java
  63. +34 −4 src/test/java/org/junit/tests/experimental/theories/runner/UnsuccessfulWithDataPointFields.java
  64. +1 −1 src/test/java/org/junit/tests/experimental/theories/runner/WhenNoParametersMatch.java
  65. +3 −4 src/test/java/org/junit/tests/experimental/theories/runner/WithDataPointMethod.java
  66. +1 −1 src/test/java/org/junit/tests/experimental/theories/runner/WithOnlyTestAnnotations.java
  67. +1 −1 src/test/java/org/junit/tests/junit3compatibility/AllTestsTest.java
  68. +119 −1 src/test/java/org/junit/tests/running/classes/ParameterizedTestTest.java
  69. +1 −1 src/test/java/org/junit/tests/running/classes/ParentRunnerTest.java
  70. +3 −3 src/test/java/org/junit/tests/running/methods/AnnotationTest.java
  71. +1 −1 src/test/java/org/junit/tests/running/methods/TimeoutTest.java
View
@@ -3,6 +3,6 @@
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry exported="true" kind="lib" path="lib/hamcrest-core-1.1.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/hamcrest-core-1.3.jar" sourcepath="lib/hamcrest-core-1.3-sources.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
@@ -2,7 +2,6 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="Author" content="Erich Gamma, Kent Beck, and David Saff">
<title>JUnit 4.6</title>
</head>
View
@@ -28,7 +28,8 @@
<property name="javadocdir" location="${dist}/javadoc" />
<property name="javadoczip" location="${dist}-javadoc.zip" />
- <property name="hamcrestlib" location="lib/hamcrest-core-1.1.jar" />
+ <property name="hamcrestlib" location="lib/hamcrest-core-1.3.jar" />
+ <property name="hamcrestlibsources" location="lib/hamcrest-core-1.3-sources.jar" />
<property name="hamcrestsrc" location="${dist}/temp.hamcrest.source" />
<property name="maven.deploy.goal" value="org.apache.maven.plugins:maven-gpg-plugin:1.1:sign-and-deploy-file" />
@@ -125,7 +126,7 @@
</target>
<target name="unjar.hamcrest">
- <unjar src="${hamcrestlib}" dest="${hamcrestsrc}" />
+ <unjar src="${hamcrestlibsources}" dest="${hamcrestsrc}" />
</target>
<target name="release-notes">
@@ -58,7 +58,7 @@
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
- <version>1.1</version>
+ <version>1.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
@@ -9,7 +9,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <version.hamcrest>1.2.1</version.hamcrest>
+ <version.hamcrest>1.3</version.hamcrest>
</properties>
<dependencies>
View
@@ -1,2 +1,2 @@
-java -classpath ../bin:../lib/hamcrest-core-1.1.jar -agentlib:hprof=cpu=samples,depth=18 org.junit.runner.JUnitCore org.junit.tests.AllTests
+java -classpath ../bin:../lib/hamcrest-core-1.3.jar -agentlib:hprof=cpu=samples,depth=18 org.junit.runner.JUnitCore org.junit.tests.AllTests
cat java.hprof.txt
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
@@ -1,8 +1,7 @@
package org.junit;
-import org.hamcrest.Description;
import org.hamcrest.Matcher;
-import org.hamcrest.StringDescription;
+import org.hamcrest.MatcherAssert;
import org.junit.internal.ArrayComparisonFailure;
import org.junit.internal.ExactComparisonCriteria;
import org.junit.internal.InexactComparisonCriteria;
@@ -919,7 +918,7 @@ public static void assertEquals(Object[] expecteds, Object[] actuals) {
* values
*
* @see org.hamcrest.CoreMatchers
- * @see org.junit.matchers.JUnitMatchers
+ * @see org.hamcrest.MatcherAssert
*/
public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
assertThat("", actual, matcher);
@@ -931,7 +930,6 @@ public static void assertEquals(Object[] expecteds, Object[] actuals) {
* the reason and information about the matcher and failing value. Example:
*
* <pre>
- * :
* assertThat(&quot;Help! Integers don't work&quot;, 0, is(1)); // fails:
* // failure message:
* // Help! Integers don't work
@@ -957,23 +955,10 @@ public static void assertEquals(Object[] expecteds, Object[] actuals) {
* values
*
* @see org.hamcrest.CoreMatchers
- * @see org.junit.matchers.JUnitMatchers
+ * @see org.hamcrest.MatcherAssert
*/
public static <T> void assertThat(String reason, T actual,
Matcher<? super T> matcher) {
- if (!matcher.matches(actual)) {
- Description description= new StringDescription();
- description.appendText(reason);
- description.appendText("\nExpected: ");
- description.appendDescriptionOf(matcher);
- description.appendText("\n got: ");
- description.appendValue(actual);
- description.appendText("\n");
- java.lang.AssertionError assertionError= new java.lang.AssertionError(
- description.toString());
- if (actual instanceof Throwable)
- assertionError.initCause((Throwable) actual);
- throw assertionError;
- }
+ MatcherAssert.assertThat(reason, actual, matcher);
}
}
@@ -1,12 +1,12 @@
package org.junit;
import static java.util.Arrays.asList;
+import static org.hamcrest.CoreMatchers.everyItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import org.hamcrest.Matcher;
import org.junit.internal.AssumptionViolatedException;
-import org.junit.internal.matchers.Each;
/**
* A set of methods useful for stating assumptions about the conditions in which a test is meaningful.
@@ -45,7 +45,7 @@ public static void assumeTrue(boolean b) {
* @param objects
*/
public static void assumeNotNull(Object... objects) {
- assumeThat(asList(objects), Each.each(notNullValue()));
+ assumeThat(asList(objects), everyItem(notNullValue()));
}
/**
@@ -3,7 +3,7 @@
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
-import org.junit.internal.matchers.TypeSafeMatcher;
+import org.hamcrest.TypeSafeMatcher;
/**
* Matchers on a PrintableResult, to enable JUnit self-tests.
@@ -34,9 +34,14 @@ protected void collectInitializationErrors(List<Throwable> errors) {
private void validateDataPointFields(List<Throwable> errors) {
Field[] fields= getTestClass().getJavaClass().getDeclaredFields();
- for (Field each : fields)
- if (each.getAnnotation(DataPoint.class) != null && !Modifier.isStatic(each.getModifiers()))
- errors.add(new Error("DataPoint field " + each.getName() + " must be static"));
+ for (Field field : fields) {
+ if (field.getAnnotation(DataPoint.class) == null)
+ continue;
+ if (!Modifier.isStatic(field.getModifiers()))
+ errors.add(new Error("DataPoint field " + field.getName() + " must be static"));
+ if (!Modifier.isPublic(field.getModifiers()))
+ errors.add(new Error("DataPoint field " + field.getName() + " must be public"));
+ }
}
@Override
@@ -1,6 +1,3 @@
-/**
- *
- */
package org.junit.experimental.theories.internal;
import java.lang.reflect.Array;
@@ -65,40 +62,42 @@ public AllMembersSupplier(TestClass type) {
addFields(sig, list);
addSinglePointMethods(sig, list);
- addMultiPointMethods(list);
+ addMultiPointMethods(sig, list);
return list;
}
- private void addMultiPointMethods(List<PotentialAssignment> list) {
+ private void addMultiPointMethods(ParameterSignature sig, List<PotentialAssignment> list) {
for (FrameworkMethod dataPointsMethod : fClass
.getAnnotatedMethods(DataPoints.class))
try {
- addArrayValues(dataPointsMethod.getName(), list, dataPointsMethod.invokeExplosively(null));
+ addMultiPointArrayValues(sig, dataPointsMethod.getName(), list, dataPointsMethod.invokeExplosively(null));
} catch (Throwable e) {
// ignore and move on
}
}
- @SuppressWarnings("deprecation")
private void addSinglePointMethods(ParameterSignature sig,
- List<PotentialAssignment> list) {
+ List<PotentialAssignment> list) {
for (FrameworkMethod dataPointMethod : fClass
.getAnnotatedMethods(DataPoint.class)) {
- Class<?> type= sig.getType();
- if ((dataPointMethod.producesType(type)))
+ if (isCorrectlyTyped(sig, dataPointMethod.getType()))
list.add(new MethodParameterValue(dataPointMethod));
}
}
private void addFields(ParameterSignature sig,
- List<PotentialAssignment> list) {
+ List<PotentialAssignment> list) {
for (final Field field : fClass.getJavaClass().getFields()) {
if (Modifier.isStatic(field.getModifiers())) {
Class<?> type= field.getType();
if (sig.canAcceptArrayType(type)
&& field.getAnnotation(DataPoints.class) != null) {
- addArrayValues(field.getName(), list, getStaticFieldValue(field));
+ try {
+ addArrayValues(field.getName(), list, getStaticFieldValue(field));
+ } catch (Throwable e) {
+ // ignore and move on
+ }
} else if (sig.canAcceptType(type)
&& field.getAnnotation(DataPoint.class) != null) {
list.add(PotentialAssignment
@@ -113,6 +112,21 @@ private void addArrayValues(String name, List<PotentialAssignment> list, Object
list.add(PotentialAssignment.forValue(name + "[" + i + "]", Array.get(array, i)));
}
+ private void addMultiPointArrayValues(ParameterSignature sig, String name, List<PotentialAssignment> list,
+ Object array) throws Throwable {
+ for (int i= 0; i < Array.getLength(array); i++) {
+ if (!isCorrectlyTyped(sig, Array.get(array, i).getClass())) {
+ return;
+ }
+ list.add(PotentialAssignment.forValue(name + "[" + i + "]", Array.get(array, i)));
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private boolean isCorrectlyTyped(ParameterSignature parameterSignature, Class<?> type) {
+ return parameterSignature.canAcceptType(type);
+ }
+
private Object getStaticFieldValue(final Field field) {
try {
return field.get(null);
@@ -1,22 +0,0 @@
-package org.junit.internal.matchers;
-
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-
-public class CauseMatcher extends TypeSafeMatcher<Throwable> {
- private final Matcher<? super Throwable> fCauseMatcher;
-
- public CauseMatcher(final Matcher<? super Throwable> causeMatcher) {
- fCauseMatcher= causeMatcher;
- }
-
- public void describeTo(Description description) {
- description.appendText("caused by ");
- fCauseMatcher.describeTo(description);
- }
-
- @Override
- public boolean matchesSafely(Throwable item) {
- return fCauseMatcher.matches(item.getCause());
- }
-}
@@ -1,34 +0,0 @@
-package org.junit.internal.matchers;
-
-import static org.hamcrest.CoreMatchers.allOf;
-import static org.hamcrest.CoreMatchers.anyOf;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-
-public class CombinableMatcher<T> extends BaseMatcher<T> {
-
- private final Matcher<? extends T> fMatcher;
-
- public CombinableMatcher(Matcher<? extends T> matcher) {
- fMatcher= matcher;
- }
-
- public boolean matches(Object item) {
- return fMatcher.matches(item);
- }
-
- public void describeTo(Description description) {
- description.appendDescriptionOf(fMatcher);
- }
-
- @SuppressWarnings("unchecked")
- public CombinableMatcher<T> and(Matcher<? extends T> matcher) {
- return new CombinableMatcher<T>(allOf(matcher, fMatcher));
- }
-
- @SuppressWarnings("unchecked")
- public CombinableMatcher<T> or(Matcher<? extends T> matcher) {
- return new CombinableMatcher<T>(anyOf(matcher, fMatcher));
- }
-}
@@ -1,24 +0,0 @@
-package org.junit.internal.matchers;
-
-import static org.hamcrest.CoreMatchers.not;
-import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-
-public class Each {
- public static <T> Matcher<Iterable<T>> each(final Matcher<T> individual) {
- final Matcher<Iterable<T>> allItemsAre = not(hasItem(not(individual)));
-
- return new BaseMatcher<Iterable<T>>() {
- public boolean matches(Object item) {
- return allItemsAre.matches(item);
- }
-
- public void describeTo(Description description) {
- description.appendText("each ");
- individual.describeTo(description);
- }
- };
- }
-}
@@ -1,67 +0,0 @@
-package org.junit.internal.matchers;
-
-import static org.hamcrest.core.AllOf.allOf;
-import static org.hamcrest.core.IsEqual.equalTo;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.hamcrest.Description;
-import org.hamcrest.Factory;
-import org.hamcrest.Matcher;
-
-// Copied (hopefully temporarily) from hamcrest-library
-public class IsCollectionContaining<T> extends TypeSafeMatcher<Iterable<T>> {
- private final Matcher<? extends T> elementMatcher;
-
- public IsCollectionContaining(Matcher<? extends T> elementMatcher) {
- this.elementMatcher = elementMatcher;
- }
-
- @Override
- public boolean matchesSafely(Iterable<T> collection) {
- for (T item : collection) {
- if (elementMatcher.matches(item)){
- return true;
- }
- }
- return false;
- }
-
- public void describeTo(Description description) {
- description
- .appendText("a collection containing ")
- .appendDescriptionOf(elementMatcher);
- }
-
- @Factory
- public static <T> Matcher<Iterable<T>> hasItem(Matcher<? extends T> elementMatcher) {
- return new IsCollectionContaining<T>(elementMatcher);
- }
-
- @Factory
- public static <T> Matcher<Iterable<T>> hasItem(T element) {
- return hasItem(equalTo(element));
- }
-
- @Factory
- public static <T> Matcher<Iterable<T>> hasItems(Matcher<? extends T>... elementMatchers) {
- Collection<Matcher<? extends Iterable<T>>> all
- = new ArrayList<Matcher<? extends Iterable<T>>>(elementMatchers.length);
- for (Matcher<? extends T> elementMatcher : elementMatchers) {
- all.add(hasItem(elementMatcher));
- }
- return allOf(all);
- }
-
- @Factory
- public static <T> Matcher<Iterable<T>> hasItems(T... elements) {
- Collection<Matcher<? extends Iterable<T>>> all
- = new ArrayList<Matcher<? extends Iterable<T>>>(elements.length);
- for (T element : elements) {
- all.add(hasItem(element));
- }
- return allOf(all);
- }
-
-}
Oops, something went wrong.

0 comments on commit 6caeeb1

Please sign in to comment.