@Theory(nullsAccepted = false) public void backTraceHasGoodToString(String descriptionName, final String stackTraceClassName) { Failure failure = new Failure(Description .createSuiteDescription(descriptionName), new Throwable() { private static final long serialVersionUID = 1L; @Override public StackTraceElement[] getStackTrace() { return new StackTraceElement[]{new StackTraceElement( stackTraceClassName, "methodName", "fileName", 1)}; } }); assertThat(new PrintableResult(asList(failure)).toString(), allOf( containsString(descriptionName), containsString(stackTraceClassName))); }
@Test public void whereTypeVariablesAbound() { PrintableResult result = testResult(TypeVariablesAbound.class); assertThat(result, failureCountIs(7)); assertThat(result, hasFailureContaining("unresolved type variable A")); assertThat(result, hasFailureContaining("unresolved type variable B")); assertThat(result, hasFailureContaining("unresolved type variable C")); assertThat(result, hasFailureContaining("unresolved type variable D")); assertThat(result, hasFailureContaining("unresolved type variable E")); assertThat(result, hasFailureContaining("unresolved type variable F")); assertThat(result, hasFailureContaining("unresolved type variable G")); }
@Test public void dataPointFieldsMustBeStatic() { assertThat( testResult(DataPointFieldsMustBeStatic.class), CoreMatchers.<PrintableResult>both(failureCountIs(2)) .and( hasFailureContaining("DataPoint field THREE must be static")) .and( hasFailureContaining("DataPoint field FOURS must be static"))); }
@Test public void dataPointMethodsMustBeStatic() { assertThat( testResult(DataPointMethodsMustBeStatic.class), CoreMatchers.<PrintableResult>both(failureCountIs(2)) .and( hasFailureContaining("DataPoint method singleDataPointMethod must be static")) .and( hasFailureContaining("DataPoint method dataPointArrayMethod must be static"))); }
@Test public void dataPointFieldsMustBePublic() { PrintableResult result = testResult(DataPointFieldsMustBePublic.class); assertEquals(6, result.failureCount()); assertThat(result, allOf(hasFailureContaining("DataPoint field THREE must be public"), hasFailureContaining("DataPoint field THREES must be public"), hasFailureContaining("DataPoint field FOUR must be public"), hasFailureContaining("DataPoint field FOURS must be public"), hasFailureContaining("DataPoint field FIVE must be public"), hasFailureContaining("DataPoint field FIVES must be public"))); }
@Test public void dataPointMethodsMustBePublic() { PrintableResult result = testResult(DataPointMethodsMustBePublic.class); assertEquals(6, result.failureCount()); assertThat(result, allOf(hasFailureContaining("DataPoint method three must be public"), hasFailureContaining("DataPoint method threes must be public"), hasFailureContaining("DataPoint method four must be public"), hasFailureContaining("DataPoint method fours must be public"), hasFailureContaining("DataPoint method five must be public"), hasFailureContaining("DataPoint method fives must be public"))); }
@Test public void testWatcherSkippedThrowsException() { PrintableResult result = testResult(TestWatcherSkippedThrowsExceptionTest.class); assertThat(result, failureCountIs(2)); assertThat(result, hasFailureContaining("test failure")); assertThat(result, hasFailureContaining("watcher failure")); }
@Test public void testWatcherFailedThrowsException() { PrintableResult result = testResult(TestWatcherFailedThrowsExceptionTest.class); assertThat(result, failureCountIs(2)); assertThat(result, hasFailureContaining("test failure")); assertThat(result, hasFailureContaining("watcher failure")); }
@Test public void testWatcherStartingThrowsException() { PrintableResult result = testResult(TestWatcherStartingThrowsExceptionTest.class); assertThat(result, failureCountIs(2)); assertThat(result, hasFailureContaining("test failure")); assertThat(result, hasFailureContaining("watcher failure")); }
@Test public void testWatcherFailedAndFinishedThrowsException() { PrintableResult result = testResult(TestWatcherFailedAndFinishedThrowsExceptionTest.class); assertThat(result, failureCountIs(3)); assertThat(result, hasFailureContaining("test failure")); assertThat(result, hasFailureContaining("watcher failed failure")); assertThat(result, hasFailureContaining("watcher finished failure")); }
@Test public void usedErrorCollectorCheckThatShouldFail() { PrintableResult testResult = testResult(UsesErrorCollectorCheckThat.class); assertThat(testResult, hasFailureContaining("was <3>")); assertThat(testResult, hasFailureContaining("was <5>")); assertThat(testResult, hasFailureContaining("reason 1")); assertThat(testResult, hasFailureContaining("was <7>")); assertThat(testResult, hasFailureContaining("reason 2")); assertThat(testResult, hasFailureContaining("was <9>")); }
@Theory public void includeMultipleFailures(String secondExceptionName) { PrintableResult backtrace = new PrintableResult(Arrays.asList( new Failure(Description.createSuiteDescription("firstName"), new RuntimeException("firstException")), new Failure( Description.createSuiteDescription("secondName"), new RuntimeException(secondExceptionName)))); assertThat(backtrace.toString(), containsString(secondExceptionName)); }
@Test public void dataPointsMustBeStatic() { assertThat( testResult(DataPointsMustBeStatic.class), CoreMatchers.<PrintableResult>both(failureCountIs(2)) .and( hasFailureContaining("DataPoint field THREE must be static")) .and( hasFailureContaining("DataPoint field FOUR must be static"))); }
@Test public void whereTypeVariableIsOnTheTheory() { PrintableResult result = testResult(TypeVariableOnTheoryOnly.class); assertThat(result, isSuccessful()); }
@Test public void whereTypeVariableIsOnTheoryParm() { PrintableResult result = testResult(TypeVariableOnTheoryParm.class); assertThat(result, hasSingleFailureContaining("unresolved type variable T")); }
@Test public void whereTypeVariableIsOnParameterizedTheoryParm() { PrintableResult result = testResult(TypeVariableOnParameterizedTheoryParm.class); assertThat(result, hasSingleFailureContaining("unresolved type variable T")); }
@Test public void whereTypeVariableIsOnWildcardUpperBoundOnTheoryParm() { PrintableResult result = testResult(TypeVariableOnWildcardUpperBoundOnTheoryParm.class); assertThat(result, hasSingleFailureContaining("unresolved type variable U")); }
@Test public void whereTypeVariableIsOnWildcardLowerBoundOnTheoryParm() { PrintableResult result = testResult(TypeVariableOnWildcardLowerBoundOnTheoryParm.class); assertThat(result, hasSingleFailureContaining("unresolved type variable V")); }
@Test public void whereTypeVariableIsOnArrayTypeOnTheoryParm() { PrintableResult result = testResult(TypeVariableOnArrayTypeOnTheoryParm.class); assertThat(result, hasSingleFailureContaining("unresolved type variable T")); }
@Test public void whereTypeVariableIsOnComponentOfArrayTypeOnTheoryParm() { PrintableResult result = testResult(TypeVariableOnComponentOfArrayTypeOnTheoryParm.class); assertThat(result, hasSingleFailureContaining("unresolved type variable U")); }
@Test public void whereTypeVariableIsOnTheoryClass() { PrintableResult result = testResult(TypeVariableOnTheoryClass.class); assertThat(result, hasSingleFailureContaining("unresolved type variable T")); }
@Test public void usedErrorCollectorTwiceShouldFail() { PrintableResult testResult = testResult(UsesErrorCollectorTwice.class); assertThat(testResult, hasFailureContaining("first thing went wrong")); assertThat(testResult, hasFailureContaining("second thing went wrong")); }
@Test public void usedErrorCollectorCheckSucceedsShouldFail() { PrintableResult testResult = testResult(UsesErrorCollectorCheckSucceeds.class); assertThat(testResult, hasFailureContaining("first!")); assertThat(testResult, hasFailureContaining("second!")); }