### Question:
MessagePublisher implements AutoCloseable { public synchronized void close() { LoggingService.logDebug(MODULE_NAME, "Start closing publish"); try { archive.close(); } catch (Exception exp) { logError(MODULE_NAME, "Error closing message archive", new AgentSystemException(exp.getMessage(), exp)); } if (producers != null && producers.size() > 0) { for (MessageProducer producer: producers) { try { producer.close(); } catch (Exception exp) { logError(MODULE_NAME, "Error closing message publisher", new AgentSystemException(exp.getMessage(), exp)); } } producers.clear(); } LoggingService.logDebug(MODULE_NAME, "Finished closing publish"); } MessagePublisher(String name, Route route, List<MessageProducer> producers); String getName(); synchronized void close(); synchronized List<Message> messageQuery(long from, long to); Route getRoute();  }### Answer:
@Test public void testClose() { try { messagePublisher.close(); Mockito.verify(messageArchive, atLeastOnce()).close(); verifyStatic(LoggingService.class); LoggingService.logDebug(MODULE_NAME, "Start closing publish"); verifyStatic(LoggingService.class); LoggingService.logDebug(MODULE_NAME, "Finished closing publish"); } catch (Exception e) { fail("This should not happen"); } }
@Test public void throwsExceptionWhenCloseIsCalled() { try { PowerMockito.doThrow(mock(RuntimeException.class)).when(messageArchive).close(); messagePublisher.close(); Mockito.verify(messageArchive, atLeastOnce()).close(); verifyStatic(LoggingService.class); logError(eq(MODULE_NAME), eq("Error closing message archive"), any()); } catch (Exception e) { fail("This should not happen"); } }