Closed dlipofsky closed 9 years ago
The behavior of Expectations
changed in release 1.13, as described in the release notes: http://jmockit.org/changes.html#1.13
It was changed because of frequent API misuse; users often were unaware of the "strict" semantics, or didn't really need it.
So, if you use StrictExpectations
, the behavior from JMockit 1.12 is restored.
But there are better solutions for tests like these, without using strict expectations.
The first option is to use a VerificationsInOrder
block:
@Test
public void test1b() {
remoteFoo.sendMessage("A");
remoteFoo.sendMessage("B");
remoteFoo.sendMessage("C");
remoteFoo.sendMessage("D");
new VerificationsInOrder() {{
remoteFoo.sendMessage("A");
remoteFoo.sendMessage("B");
remoteFoo.sendMessage("C");
remoteFoo.sendMessage("D");
}};
}
A second and better option is to capture the sequence of messages sent (since there is a single method to be verified):
@Test
public void test1c() {
remoteFoo.sendMessage("A");
remoteFoo.sendMessage("B");
remoteFoo.sendMessage("C");
remoteFoo.sendMessage("D");
new Verifications() {{
List<String> messages = new ArrayList<String>();
remoteFoo.sendMessage(withCapture(messages));
assertEquals(asList("A", "B", "C", "D"), messages);
}};
}
Test 1 prints the following in 1.12
but prints this in 1.13 - 1.18
Also test2 passes in 1.12 but fails in 1.13 - 1.18. test1 passes in all versions. This is suprising since the difference is so small. Both tests seem to have the O(N^2) problem.