@Override public String getMessage() { return StringDescription.asString(this); }
@Override public String getMessage() { return StringDescription.asString(this); }
@Override public String getMessage() { return StringDescription.asString(this); }
@Override public String call(SelfDescribing selfDescribing) throws Exception { return asString(selfDescribing); } };
@Override public String getMessage() { return StringDescription.asString(this); }
@Override public String getMessage() { return StringDescription.asString(this); }
@Override public String toString() { return StringDescription.asString(this); }
@Override public String getMessage() { return StringDescription.asString(this); }
@Override public String getMessage() { return StringDescription.asString(this); }
private void waitUntil(StatePredicate p, Timeout timeout) throws InterruptedException { synchronized (sync) { while (!p.isActive()) { try { sync.wait(timeout.timeRemaining()); } catch (TimeoutException e) { if (firstError != null) { throw firstError; } else { throw new AssertionError("timed out waiting for " + asString(p)); } } } } }
public static <T> Function1<T, String> describeMismatch(final Matcher<? super T> matcher) { if (matcher instanceof DiagnosingMatcher) return diagnoseMismatch((DiagnosingMatcher) matcher); return returns1(StringDescription.asString(matcher)); }
@Test public void assumptionViolatedExceptionWithMatcherDescribesItself() { AssumptionViolatedException e = new AssumptionViolatedException(3, is(2)); assertThat(StringDescription.asString(e), is("got: <3>, expected: is <2>")); }
public void testDoesNotDescribeReturnValueForMethodsThatAreKnownToBeVoid() { context.checking(new Expectations() {{ oneOf (mock).doSomething(); }}); assertThat(asString(context), not(containsString("returns a default value"))); }
@Test public void simpleAssumptionViolatedExceptionDescribesItself() { AssumptionViolatedException e = new AssumptionViolatedException("not enough money"); assertThat(StringDescription.asString(e), is("not enough money")); } }
public void testMismatchDescription() { context.checking(new Expectations() {{ oneOf (mock).doSomethingWith("foo"); oneOf (mock).doSomethingWith("x", "y"); will(doSomethingDescribedAs("ACTION")); }}); try { mock.doSomethingWith("X", "Y"); } catch (ExpectationError e) { String failure = asString(e); Integer actionIndex = failure.indexOf("ACTION"); Integer parameterMismatchIndex = failure.indexOf("parameter 0 did not match"); assertTrue("action should come before parameter mismatches in description", actionIndex < parameterMismatchIndex); } }
public void testDoesNotRecordUnexpectedInvocations() { context.checking(new Expectations() {{ allowing (mock).doSomethingWith("foo"); }}); try { mock.doSomethingWith("bar"); } catch (ExpectationError expected) {} assertThat(asString(context), containsInOrder( "what happened before this:", "nothing")); }
public void testRecordsActualInvocations() { context.checking(new Expectations() {{ allowing (same(mock)); }}); mock.doSomething(); mock.doSomethingWith("foo"); mock.doSomethingWith("x", "y"); assertThat(asString(context), containsInOrder( "what happened before this:", "mock.doSomething()", "mock.doSomethingWith(\"foo\")", "mock.doSomethingWith(\"x\", \"y\")")); }
public void testRecordsInvocationsThatThrowExceptions() { context.checking(new Expectations() {{ allowing (mock).doSomething(); will(throwException(new ExampleException())); }}); try { mock.doSomething(); fail("no exception thrown"); } catch (ExampleException expected) {} assertThat(asString(context), containsInOrder( "what happened before this:", "mock.doSomething()")); }
public void testReportsRecordedInvocationsWhenUnexpectedInvocationReceived() { context.checking(new Expectations() {{ oneOf (mock).doSomethingWith("x"); oneOf (mock).doSomethingWith("y"); }}); mock.doSomethingWith("y"); try { mock.doSomethingWith("z"); fail("should have reported unexpected invocation"); } catch (ExpectationError e) { assertThat(asString(e), containsInOrder( "what happened before this:", "mock.doSomethingWith(\"y\")" )); } }