Question: Please write an acceptance test for the code below: public static List getAllWorldNames ( Connection connection ) { List worldNames; worldNames = readData ( connection

Please write an acceptance test for the code below:
public static List getAllWorldNames(Connection connection){
List worldNames;
worldNames = readData(connection);
return worldNames;
}
public static List readData(final Connection connection){
List worldNames = new ArrayList<>();
try (final PreparedStatement stmt = connection.prepareStatement(
"SELECT name FROM worlds"
)){
final boolean gotAResultSet = stmt.execute();
if (!gotAResultSet){
throw new RuntimeException("Expected a SQL resultset, but we got an update count instead!");
}
try (ResultSet results = stmt.getResultSet()){
while (results.next()){
final String worldName = results.getString("name").toLowerCase();
worldNames.add(worldName);
}
}
} catch (SQLException e){
throw new RuntimeException(e);
}
return worldNames;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!