@Test public void usage() { // given Foo foo = mock(Foo.class, withSettings().verboseLogging()); given(foo.giveMeSomeString("Apple")).willReturn("earbuds"); // when foo.giveMeSomeString("Shure"); foo.giveMeSomeString("Apple"); foo.doSomething("Klipsch"); }
@Test public void shouldPrintStubbedInvocationOnMockToStdOut() { // given Foo foo = mock(Foo.class, withSettings().verboseLogging()); given(foo.giveMeSomeString("Klipsch")).willReturn("earbuds"); // when foo.giveMeSomeString("Klipsch"); // then Assertions.assertThat(printed()) .contains(getClass().getName()) .contains(mockName(foo)) .contains("giveMeSomeString") .contains("Klipsch") .contains("earbuds"); }
@Test public void shouldNotPrintInvocationOnMockWithoutSetting() { // given Foo foo = mock(Foo.class, withSettings().verboseLogging()); // when foo.giveMeSomeString("Klipsch"); unrelatedMock.unrelatedMethod("Apple"); // then Assertions.assertThat(printed()) .doesNotContain(mockName(unrelatedMock)) .doesNotContain("unrelatedMethod") .doesNotContain("Apple"); }