Browse Source

Added Console Listing + Test

dev
Adem Berber 3 years ago
parent
commit
b5ff15acd6
  1. BIN
      projjpn/GamesDB.laccdb
  2. 53
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java
  3. 7
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java

BIN
projjpn/GamesDB.laccdb

53
projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java

@ -2,7 +2,9 @@ package de.hs_fulda.ciip.projjpn;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Games {
private String databaseURL = "jdbc:ucanaccess://GamesDB.accdb";
@ -18,4 +20,55 @@ public class Games {
return false;
}
}
public String checkForConsoles() {
String result = "";
String query = "SELECT Game_Console FROM Games";
boolean ninSwitch = false;
boolean xbox = false;
boolean multiplat = false;
try {
Connection connection = DriverManager.getConnection(databaseURL);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) {
String gameConsole = resultSet.getString("Game_Console");
if (ninSwitch && gameConsole.equals("Nintendo Switch")) {
continue;
} else if (xbox && gameConsole.equals("Xbox")) {
continue;
} else if (multiplat && gameConsole.equals("Multiplatform")) {
continue;
}
switch (gameConsole) {
case "Nintendo Switch":
ninSwitch = true;
break;
case "Xbox":
xbox = true;
break;
case "Multiplatform":
multiplat = true;
break;
}
result += gameConsole + ", ";
}
statement.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
// The substring removes the last New line in the String.
return result.substring(0, result.length() - 2);
}
}

7
projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java

@ -8,4 +8,11 @@ public class GamesTest extends TestCase {
boolean actual = testObject.checkForConnection();
assertEquals(expected, actual);
}
public void test_checkForConsoles() {
Games testObject = new Games();
String expected = "PlayStation 4, Multiplatform, Nintendo Switch, Nintendo DS, PlayStation 3, Xbox, PlayStation Portable, Nintendo 3DS, Xbox 360, PlayStation Vita";
String actual = testObject.checkForConsoles();
assertEquals(expected, actual);
}
}
Loading…
Cancel
Save