• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 package org.mockitousage.verification;
6 
7 import static org.assertj.core.api.Assertions.assertThat;
8 import static org.junit.Assert.fail;
9 
10 import org.junit.Test;
11 import org.mockito.Mockito;
12 import org.mockito.exceptions.verification.opentest4j.ArgumentsAreDifferent;
13 
14 public class VerifyPrintsAllInvocationsOnErrorTest {
15 
16     @Test
shouldPrintAllInvocationsOnError()17     public void shouldPrintAllInvocationsOnError() {
18         ExampleBuilder mockBuilder = Mockito.mock(ExampleBuilder.class);
19         mockBuilder.with("key1", "val1");
20         mockBuilder.with("key2", "val2");
21         try {
22             Mockito.verify(mockBuilder).with("key1", "wrongValue");
23             fail();
24         } catch (ArgumentsAreDifferent e) {
25             assertThat(e).hasMessageContaining("exampleBuilder.with(\"key1\", \"val1\")");
26             assertThat(e).hasMessageContaining("exampleBuilder.with(\"key2\", \"val2\"");
27         }
28     }
29 
30     private static class ExampleBuilder {
with(String key, String val)31         public ExampleBuilder with(String key, String val) {
32             return this;
33         }
34     }
35 }
36