Permalink
Browse files

Fixed lack of an empty character between words in certain "unexpected…

… invocation" exception messages.
  • Loading branch information...
1 parent 9df0da2 commit 15390aab9cbb48cb1083667750db7766186fd0fc @rliesenfeld rliesenfeld committed Jan 3, 2017
@@ -240,7 +240,8 @@ public ExpectedInvocation(
@Nonnull
public UnexpectedInvocation errorForUnexpectedInvocation()
{
- return newUnexpectedInvocationWithCause("Unexpected invocation", "Unexpected invocation of" + this);
+ String initialMessage = "Unexpected invocation of " + this;
+ return newUnexpectedInvocationWithCause("Unexpected invocation", initialMessage);
}
@Nonnull
@@ -353,27 +354,32 @@ public UnexpectedInvocation errorForUnexpectedInvocations(@Nonnull Object[] repl
@Nonnull
public UnexpectedInvocation errorForUnexpectedInvocationBeforeAnother(@Nonnull ExpectedInvocation another)
{
- return newUnexpectedInvocationWithCause("Unexpected invocation" + this, "Unexpected invocation before" + another);
+ String titleForCause = "Unexpected invocation " + this;
+ String initialMessage = "Unexpected invocation before " + another;
+ return newUnexpectedInvocationWithCause(titleForCause, initialMessage);
}
@Nonnull
public UnexpectedInvocation errorForUnexpectedInvocationFoundBeforeAnother()
{
- String initialMessage = "Invocation occurred unexpectedly before another" + this;
+ String initialMessage = "Invocation occurred unexpectedly before another " + this;
return newUnexpectedInvocationWithCause("Unexpected invocation", initialMessage);
}
@Nonnull
public UnexpectedInvocation errorForUnexpectedInvocationFoundBeforeAnother(@Nonnull ExpectedInvocation another)
{
+ String titleForCause = "Unexpected invocation " + this;
String initialMessage = "Another invocation unexpectedly occurred before" + another;
- return newUnexpectedInvocationWithCause("Unexpected invocation" + this, initialMessage);
+ return newUnexpectedInvocationWithCause(titleForCause, initialMessage);
}
@Nonnull
public UnexpectedInvocation errorForUnexpectedInvocationAfterAnother(@Nonnull ExpectedInvocation another)
{
- return newUnexpectedInvocationWithCause("Unexpected invocation" + this, "Unexpected invocation after" + another);
+ String titleForCause = "Unexpected invocation " + this;
+ String initialMessage = "Unexpected invocation after " + another;
+ return newUnexpectedInvocationWithCause(titleForCause, initialMessage);
}
@Nonnull @Override
@@ -27,6 +27,7 @@ void doSomethingElse(@SuppressWarnings("unused") String s) {}
public void unexpectedInvocationForRecordedStrictExpectation()
{
thrown.expect(UnexpectedInvocation.class);
+ thrown.expectMessage("Unexpected invocation of ");
thrown.expectMessage("2, \"xyz\"");
new StrictExpectations() {{
@@ -124,8 +125,13 @@ public void unexpectedFirstInvocationForExpectationsPartiallyVerifiedInOrder()
fail();
}
catch (UnexpectedInvocation e) {
- assertTrue(e.toString().contains("\"test\""));
- assertTrue(e.getCause().toString().contains("-5, \"abc\""));
+ String msg = e.toString();
+ assertTrue(msg, msg.startsWith("Unexpected invocation before "));
+ assertTrue(msg, msg.contains("\"test\""));
+
+ msg = e.getCause().toString();
+ assertTrue(msg, msg.startsWith("Unexpected invocation "));
+ assertTrue(msg, msg.contains("-5, \"abc\""));
}
}
@@ -167,8 +173,13 @@ public void unexpectedInvocationAfterAllOthers()
fail();
}
catch (UnexpectedInvocation e) {
- assertTrue(e.toString().contains("1, \"anotherValue\""));
- assertTrue(e.getCause().toString().contains("\"test\""));
+ String msg = e.toString();
+ assertTrue(msg, msg.startsWith("Unexpected invocation after "));
+ assertTrue(msg, msg.contains("1, \"anotherValue\""));
+
+ msg = e.getCause().toString();
+ assertTrue(msg, msg.startsWith("Unexpected invocation "));
+ assertTrue(msg, msg.contains("\"test\""));
}
}
@@ -9,6 +9,8 @@
import mockit.internal.*;
+import org.hamcrest.*;
+
@SuppressWarnings("UnusedDeclaration")
public final class VerificationsWithPartialOrderingTest
{
@@ -324,6 +326,13 @@ public void verifyThatSomeCallsInAnyRelativeOrderOccurAfterAllOthers_outOfOrder(
public void verifyThatUnorderedGroupOfCallsOccursAfterOneOtherCall_outOfOrder()
{
thrown.expect(UnexpectedInvocation.class);
+ thrown.expectCause(new CustomTypeSafeMatcher<Throwable>("starting with \"Unexpected invocation \"") {
+ @Override
+ protected boolean matchesSafely(Throwable cause)
+ {
+ return cause.toString().startsWith("Unexpected invocation ");
+ }
+ });
mock.setSomething(123);
mock.editABunchMoreStuff();
@@ -526,6 +535,7 @@ public void verifyThatOneGroupOfInvocationsOccursBeforeAnother_outOfOrder()
public void verifyThatOneGroupOccursBeforeAnotherAllowingUnverifiedInvocationsInBetween_outOfOrder()
{
thrown.expect(UnexpectedInvocation.class);
+ thrown.expectMessage("Invocation occurred unexpectedly before another ");
mock.save();
mock.prepare();

0 comments on commit 15390aa

Please sign in to comment.