Formatter Changes
This commit is contained in:
parent
3fe81a3e07
commit
270acf62e4
|
@ -45,7 +45,8 @@ public class ResultSetToMapUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingContainsKey_thenConvertResultSetToMap() throws SQLException {
|
public void whenUsingContainsKey_thenConvertResultSetToMap() throws SQLException {
|
||||||
ResultSet resultSet = connection.prepareStatement("SELECT * FROM employee").executeQuery();
|
ResultSet resultSet = connection.prepareStatement("SELECT * FROM employee")
|
||||||
|
.executeQuery();
|
||||||
Map<String, List<String>> valueMap = new HashMap<>();
|
Map<String, List<String>> valueMap = new HashMap<>();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
|
@ -54,22 +55,27 @@ public class ResultSetToMapUnitTest {
|
||||||
if (!valueMap.containsKey(empCity)) {
|
if (!valueMap.containsKey(empCity)) {
|
||||||
valueMap.put(empCity, new ArrayList<>());
|
valueMap.put(empCity, new ArrayList<>());
|
||||||
}
|
}
|
||||||
valueMap.get(empCity).add(empName);
|
valueMap.get(empCity)
|
||||||
|
.add(empName);
|
||||||
}
|
}
|
||||||
assertEquals(3, valueMap.get("London").size());
|
assertEquals(3, valueMap.get("London")
|
||||||
|
.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingComputeIfAbsent_thenConvertResultSetToMap() throws SQLException {
|
public void whenUsingComputeIfAbsent_thenConvertResultSetToMap() throws SQLException {
|
||||||
ResultSet resultSet = connection.prepareStatement("SELECT * FROM employee").executeQuery();
|
ResultSet resultSet = connection.prepareStatement("SELECT * FROM employee")
|
||||||
|
.executeQuery();
|
||||||
Map<String, List<String>> valueMap = new HashMap<>();
|
Map<String, List<String>> valueMap = new HashMap<>();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
String empCity = resultSet.getString("empCity");
|
String empCity = resultSet.getString("empCity");
|
||||||
String empName = resultSet.getString("empName");
|
String empName = resultSet.getString("empName");
|
||||||
valueMap.computeIfAbsent(empCity, data -> new ArrayList<>()).add(empName);
|
valueMap.computeIfAbsent(empCity, data -> new ArrayList<>())
|
||||||
|
.add(empName);
|
||||||
}
|
}
|
||||||
assertEquals(3, valueMap.get("London").size());
|
assertEquals(3, valueMap.get("London")
|
||||||
|
.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -81,15 +87,17 @@ public class ResultSetToMapUnitTest {
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
String empCity = resultSet.getString("empCity");
|
String empCity = resultSet.getString("empCity");
|
||||||
String empName = resultSet.getString("empName");
|
String empName = resultSet.getString("empName");
|
||||||
result.computeIfAbsent(empCity, data -> new ArrayList<>()).add(empName);
|
result.computeIfAbsent(empCity, data -> new ArrayList<>())
|
||||||
|
.add(empName);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QueryRunner run = new QueryRunner();
|
QueryRunner run = new QueryRunner();
|
||||||
Map<String, List<String>> valueMap = run.query(connection, "SELECT * FROM employee", handler);
|
Map<String, List<String>> valueMap = run.query(connection, "SELECT * FROM employee", handler);
|
||||||
assertEquals(3, valueMap.get("London").size());
|
assertEquals(3, valueMap.get("London")
|
||||||
|
.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
Loading…
Reference in New Issue