Graphite extends ServiceImpl implements EventTrackingService { void closeSocket(Socket socket) { if(socket != null) { try { socket.close(); } catch (Exception ex) { utils.logIssue("Could not close graphite socket [" + host + ":" + port + "].", ex); } } } Graphite(Context context); @Override void enable(String url); @Override boolean isEnabled(); @Override ServiceType getServiceType(); @Override void logEvent(Context context, String event);  }
@Test public void testCloseSocketException() throws IOException { Graphite graphite = new Graphite(null); graphite.host = "unit_test_host"; graphite.port = 8080; Utils mockUtils = UnitTestUtils.mockUtils(); graphite.utils = mockUtils; Socket mockSocket = mock(Socket.class); doThrow(IOException.class).when(mockSocket).close(); graphite.closeSocket(mockSocket); verify(mockUtils).logIssue(eq("Could not close graphite socket [unit_test_host:8080]."), any(IOException.class)); }