JdbcConnectionFactory { public Connection create() { try { return DriverManager.getConnection(properties.getProperty("databaseurl") + "?user=" + properties.getProperty("user") + "&password=" + properties.getProperty("password")); } catch (SQLException e) { logger.severe(e.getMessage()); } return null; } JdbcConnectionFactory();  JdbcConnectionFactory(Properties properties); Connection create();  }
@Test public void createWithExistingPropertyFile() throws Exception { JdbcConnectionFactory jdbcConnectionFactory = new JdbcConnectionFactory(); assertNotNull(jdbcConnectionFactory.create()); }
@Test public void whenAConnectionCannotBeCreatedASQLExcepionIsLogged() { Logger mockLogger = mock(Logger.class); Whitebox.setInternalState(JdbcConnectionFactory.class, "logger", mockLogger); Properties properties = mock(Properties.class); when(properties.getProperty("user")).thenReturn(USER); when(properties.getProperty("password")).thenReturn(PASS); when(properties.getProperty("databaseurl")).thenReturn(URL); when(properties.getProperty("driver")).thenReturn(DRIVER); JdbcConnectionFactory jdbcConnectionFactory = new JdbcConnectionFactory(properties); jdbcConnectionFactory.create(); verify(mockLogger).severe(anyString()); }