### Question:
MonitoredCTSConnectionFactory implements ConnectionFactory<C> { public C create() throws DataLayerException { boolean success = false; try { C response = connectionFactory.create(); success = true; return response; } finally { monitorStore.addConnection(success); } } MonitoredCTSConnectionFactory(ConnectionFactory<C> connectionFactory,
                                         CTSConnectionMonitoringStore monitorStore); C create(); @Override Promise<C, DataLayerException> createAsync(); @Override void close(); @Override boolean isValid(C connection);  }### Answer:
@Test public void shouldAddToFailedConnectionOnError() throws Exception { doThrow(DataLayerException.class).when(connectionFactory).create(); try { monitoredConnectionFactory.create(); fail("Should throw exception"); } catch (DataLayerException e) { } verify(monitoringStore).addConnection(false); }
@Test public void shouldAddToFailedConnectionOnError() throws Exception { doThrow(Exception.class).when(connectionFactory).create(); try { monitoredConnectionFactory.create(); fail("Should throw exception"); } catch (Exception e) { } verify(monitoringStore).addConnection(false); }
@Test public void shouldAddToSuccessfulConnection() throws Exception { boolean success = true; monitoredConnectionFactory.create(); verify(monitoringStore).addConnection(success); }