Skip to content

Commit

Permalink
Tweaked the output produced by JUnitRule
Browse files Browse the repository at this point in the history
Tweaked the output and improve test coverage (the case of multiple different kinds of stubbing)

See issue #384
  • Loading branch information
mockitoguy committed Apr 18, 2016
1 parent 846938b commit 176caf1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public String getStubbingInfo() {

List<String> lines = new LinkedList<String>();
lines.add("[Mockito] Additional stubbing information (see javadoc for StubbingInfo class):");
lines.add("[Mockito]");

if (!argMismatchStubs.isEmpty()) {
lines.add("[Mockito]");
lines.add("[Mockito] Unused stubbing due to argument mismatch (is stubbing correct in the test?):");
lines.add("[Mockito]");
for (String info : argMismatchStubs) {
Expand All @@ -61,6 +61,7 @@ public String getStubbingInfo() {
}

if (!unusedStubs.isEmpty()) {
lines.add("[Mockito]");
lines.add("[Mockito] Unused stubbing (perhaps can be removed from the test?):");
lines.add("[Mockito]");
for (String info : unusedStubs) {
Expand All @@ -69,6 +70,7 @@ public String getStubbingInfo() {
}

if (!unstubbedCalls.isEmpty()) {
lines.add("[Mockito]");
lines.add("[Mockito] Unstubbed method calls (perhaps missing stubbing in the test?):");
lines.add("[Mockito]");
for (String info : unstubbedCalls) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ public void informs_about_unused_stubs_due_arg_mismatch() {
"[Mockito] BUT called with different args at com.Foo:120", listener.getStubbingInfo());
}

@Test
public void informs_about_various_kinds_of_stubs() {
//given
LoggingListener listener = new LoggingListener(true);

//when
listener.foundUnusedStub(invocationAt("at com.FooTest:30"));
listener.foundStubCalledWithDifferentArgs(invocationAt("at com.FooTest:20"), invocationMatcherAt("at com.Foo:100"));
listener.foundUnstubbed(invocationMatcherAt("at com.Foo:96"));

//then
assertEquals(
"[Mockito] Additional stubbing information (see javadoc for StubbingInfo class):\n" +
"[Mockito]\n" +
"[Mockito] Unused stubbing due to argument mismatch (is stubbing correct in the test?):\n" +
"[Mockito]\n" +
"[Mockito] stubbed with those args here at com.FooTest:20\n" +
"[Mockito] BUT called with different args at com.Foo:100\n" +
"[Mockito]\n" +
"[Mockito] Unused stubbing (perhaps can be removed from the test?):\n" +
"[Mockito]\n" +
"[Mockito] This stubbing was never used at com.FooTest:30\n" +
"[Mockito]\n" +
"[Mockito] Unstubbed method calls (perhaps missing stubbing in the test?):\n" +
"[Mockito]\n" +
"[Mockito] unstubbed method at com.Foo:96", listener.getStubbingInfo());
}

@Test
public void hides_unstubbed() {
//given
Expand Down

0 comments on commit 176caf1

Please sign in to comment.