Browse Source

Added two Publisher checkers + Tests

dev
Adem Berber 3 years ago
parent
commit
443c200c09
  1. BIN
      projjpn/GamesDB.accdb
  2. BIN
      projjpn/GamesDB.laccdb
  3. 70
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java
  4. 22
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java

BIN
projjpn/GamesDB.accdb

BIN
projjpn/GamesDB.laccdb

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

@ -9,7 +9,7 @@ import java.sql.Statement;
public class Games { public class Games {
private String databaseURL = "jdbc:ucanaccess://GamesDB.accdb"; private String databaseURL = "jdbc:ucanaccess://GamesDB.accdb";
public boolean checkForConnection() {
public boolean checkConnection() {
try { try {
Connection connection = DriverManager.getConnection(databaseURL); Connection connection = DriverManager.getConnection(databaseURL);
@ -21,7 +21,7 @@ public class Games {
} }
} }
public String checkForConsoles() {
public String checkConsoles() {
String result = ""; String result = "";
String query = "SELECT Game_Console FROM Games"; String query = "SELECT Game_Console FROM Games";
boolean ninSwitch = false; boolean ninSwitch = false;
@ -71,4 +71,70 @@ public class Games {
// The substring removes the last New line in the String. // The substring removes the last New line in the String.
return result.substring(0, result.length() - 2); return result.substring(0, result.length() - 2);
} }
public String checkAllSamePublishers() {
String result = "";
String query = "SELECT Game_Name, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA FROM Games";
try {
Connection connection = DriverManager.getConnection(databaseURL);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) {
String gameName = resultSet.getString("Game_Name");
String gamePublisherEu = resultSet.getString("Game_Publisher_EU");
String gamePublisherJp = resultSet.getString("Game_Publisher_JP");
String gamePublisherNa = resultSet.getString("Game_Publisher_NA");
if (gamePublisherEu.equals(gamePublisherJp) && gamePublisherJp.equals(gamePublisherNa) && gamePublisherEu.equals(gamePublisherNa)) {
result += gameName + ", ";
}
}
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);
}
public String checkAllDifferentPublishers() {
String result = "";
String query = "SELECT Game_Name, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA FROM Games";
try {
Connection connection = DriverManager.getConnection(databaseURL);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) {
String gameName = resultSet.getString("Game_Name");
String gamePublisherEu = resultSet.getString("Game_Publisher_EU");
String gamePublisherJp = resultSet.getString("Game_Publisher_JP");
String gamePublisherNa = resultSet.getString("Game_Publisher_NA");
if (!gamePublisherEu.equals(gamePublisherJp) && !gamePublisherJp.equals(gamePublisherNa) && !gamePublisherEu.equals(gamePublisherNa)) {
result += gameName + ", ";
}
}
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);
}
} }

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

@ -2,17 +2,31 @@ package de.hs_fulda.ciip.projjpn;
import junit.framework.TestCase; import junit.framework.TestCase;
public class GamesTest extends TestCase { public class GamesTest extends TestCase {
public void test_checkForConnection() {
public void test_checkConnection() {
Games testObject = new Games(); Games testObject = new Games();
boolean expected = true; boolean expected = true;
boolean actual = testObject.checkForConnection();
boolean actual = testObject.checkConnection();
assertEquals(expected, actual); assertEquals(expected, actual);
} }
public void test_checkForConsoles() {
public void test_checkConsoles() {
Games testObject = new Games(); 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 expected = "PlayStation 4, Multiplatform, Nintendo Switch, Nintendo DS, PlayStation 3, Xbox, PlayStation Portable, Nintendo 3DS, Xbox 360, PlayStation Vita";
String actual = testObject.checkForConsoles();
String actual = testObject.checkConsoles();
assertEquals(expected, actual);
}
public void test_checkAllSamePublishers() {
Games testObject = new Games();
String expected = "Ratchet & Clank, Astral Chain, Fire Emblem: Three Houses, Rhythm Paradise, Super Smash Bros. Ultimate, Yakuza: Dead Souls, Jet Set Radio Future, Tomodachi Life, Beautiful Katamari, Crash Bandicoot N. Sane Trilogy";
String actual = testObject.checkAllSamePublishers();
assertEquals(expected, actual);
}
public void test_checkAllDifferentPublishers() {
Games testObject = new Games();
String expected = "Atelier Totori Plus";
String actual = testObject.checkAllDifferentPublishers();
assertEquals(expected, actual); assertEquals(expected, actual);
} }
} }
Loading…
Cancel
Save