@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 shouldPrintUnstubbedInvocationOnMockToStdOut() { // given Foo foo = mock(Foo.class, withSettings().verboseLogging()); // when foo.doSomething("Klipsch"); // then Assertions.assertThat(printed()) .contains(getClass().getName()) .contains(mockName(foo)) .contains("doSomething") .contains("Klipsch"); }
@Test public void shouldPrintThrowingInvocationOnMockToStdOut() { // given Foo foo = mock(Foo.class, withSettings().verboseLogging()); doThrow(new ThirdPartyException()).when(foo).doSomething("Klipsch"); try { // when foo.doSomething("Klipsch"); fail("Exception excepted."); } catch (ThirdPartyException e) { // then Assertions.assertThat(printed()) .contains(getClass().getName()) .contains(mockName(foo)) .contains("doSomething") .contains("Klipsch") .contains(ThirdPartyException.class.getName()); } }