### Question:
Repository { public String getConfigValue(String key) { if (selectOne != null) { try { selectOne.setString(1, key); ResultSet rs = selectOne.executeQuery(); if (rs.next()) { return rs.getString(1); } } catch (SQLException e) { log.log(Level.FINE, () -> "query for config value failed: " + e.getMessage()); } } return null; } Repository(Config config); Map<String, String> getAllConfigValues(); String getConfigValue(String key);  }### Answer:
@Test void testGetConfigValue() throws SQLException { repository.selectOne = mock(PreparedStatement.class); ResultSet rs = mock(ResultSet.class); when(rs.next()).thenReturn(true); when(rs.getString(1)).thenReturn("value"); when(repository.selectOne.executeQuery()).thenReturn(rs); assertEquals("value", repository.getConfigValue("test")); }
@Test void testGetConfigValue_exception() throws SQLException { repository.selectOne = mock(PreparedStatement.class); when(repository.selectOne.executeQuery()).thenThrow(SQLException.class); assertNull(repository.getConfigValue("test")); }
@Test void testGetConfigValue_none() throws SQLException { repository.selectOne = mock(PreparedStatement.class); ResultSet rs = mock(ResultSet.class); when(rs.next()).thenReturn(false); when(repository.selectOne.executeQuery()).thenReturn(rs); assertNull(repository.getConfigValue("test")); }
@Test void testGetConfigValue_no_stmt() throws SQLException { assertNull(repository.getConfigValue("test")); }