SocketHolder { public void close(String logTag) { try { if (socket != null) { socket.close(); socket = null; } } catch (IOException e) { Logger.logVerbose(logTag, e.toString()); } } SocketHolder(Socket socket); void close(String logTag);  }
@Test public void closesSocketOnlyOnce() { testSubject.close(logTag); verifySocketClosed(times(1)); reset(socketMock); testSubject.close(logTag); verifySocketClosed(never()); }
@Test public void logsFailure() { IOException testException = new IOException("test exception message"); try { doThrow(testException).when(socketMock).close(); } catch (IOException e) { Assert.fail(e.getMessage()); } testSubject.close(logTag); PowerMockito.verifyStatic(Logger.class); Logger.logVerbose(logTag, testException.toString()); }