Towtruck { @Scheduled(cron = "0 0 * * * *") void performBackup() throws IOException { log.info("Starting backup."); try (OutputStream output = outputStreamFactory.apply(keySupplier.get())) { mapper.writeValue(output, store); } log.info("Backup completed."); }    }
@Test public void happyPath() throws IOException { when(keySupplier.get()).thenReturn(KEY); when(outputStreamFactory.apply(KEY)).thenReturn(outputStream); underTest.performBackup(); InOrder inOrder = inOrder(mapper, keySupplier, outputStreamFactory, outputStream); inOrder.verify(keySupplier).get(); inOrder.verify(outputStreamFactory).apply(KEY); inOrder.verify(mapper).writeValue(outputStream, store); inOrder.verify(outputStream).close(); }
@Test(expected = IOException.class) public void exception() throws IOException { when(keySupplier.get()).thenReturn(KEY); doThrow(IOException.class).when(outputStreamFactory).apply(KEY); underTest.performBackup(); }