@Test public void personCanBePrinted() throws Exception { // Expectancy: define behaviour (a.k.a. "recording") when(printer.startPrinting()).thenReturn(true, false); assertTrue(person.print(printer)); verify(printer, times(1)).addToQueue(person); verify(printer, times(1)).startPrinting(); verifyNoMoreInteractions(printer); }
@Test(expected = UnsupportedOperationException.class) public void printerNotYetImplemented() throws Exception { when(printer.startPrinting()).thenThrow(new UnsupportedOperationException()); person.print(printer); }