### Question:
OpenSessionOnDesktopZkListener implements ExecutionInit, DesktopCleanup, ExecutionCleanup { @Override public void cleanup(Desktop desktop) throws Exception { try { openSessions.closeSession(desktop.getId()); } catch (Exception e) { logger.warn("Error closing hibernate session", e); throw e; } } OpenSessionOnDesktopZkListener();  OpenSessionOnDesktopZkListener(OpenSessions openSessions); @Override void cleanup(Desktop desktop); @Override void init(Execution exec, Execution parent); @Override void cleanup(Execution exec, Execution parent, List<Throwable> errs);  }### Answer:
@Test(dataProvider = "provideExecutionWithDesktopInside") public void testCleanup(Execution execution) throws Exception { sut.cleanup(execution, null, null); verify(openSessions).unbindSession(); }
@Test(dataProvider = "provideExecutionWithDesktopInside", expectedExceptions = IllegalArgumentException.class) public void cleanUpShouldRethrowExceptionIfItHappens(Execution execution) throws Exception { doThrow(new IllegalArgumentException()).when(openSessions).unbindSession(); sut.cleanup(execution, null, null); }
@Test(dataProvider = "provideDesktop") public void testCleanupDesktop(Desktop desktop) throws Exception { sut.cleanup(desktop); verify(openSessions).closeSession(desktop.getId()); }
@Test(dataProvider = "provideDesktop", expectedExceptions = IllegalArgumentException.class) public void cleanupDesktopShouldRethrowSameException(Desktop desktop) throws Exception { doThrow(new IllegalArgumentException()).when(openSessions).closeSession(anyString()); sut.cleanup(desktop); }