Browse Source

Refactored Class and Test File

dev
Adem Berber 3 years ago
parent
commit
ae69414f36
  1. 134
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java
  2. 14
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java

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

@ -32,48 +32,55 @@ public class Games {
ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) {
int id = resultSet.getInt("Game_ID");
String gameName = resultSet.getString("Game_Name");
String gameConsole = resultSet.getString("Game_Console");
String gameDeveloper = resultSet.getString("Game_Developer");
String gamePublisherEu = resultSet.getString("Game_Developer");
String gamePublisherJp = resultSet.getString("Game_Console");
String gamePublisherNa = resultSet.getString("Game_Console");
String gameGenre = resultSet.getString("Game_Genre");
String gameReleaseEu = resultSet.getString("Game_Release_EU");
String gameReleaseEuDots = gameReleaseEu.substring(8, 10) + "." + gameReleaseEu.substring(5, 7)
+ "." + gameReleaseEu.substring(0, 4);
String gameReleaseJp = resultSet.getString("Game_Release_JP");
String gameReleaseJpDots = gameReleaseJp.substring(8, 10) + "." + gameReleaseJp.substring(5, 7)
+ "." + gameReleaseJp.substring(0, 4);
String gameReleaseNa = resultSet.getString("Game_Release_NA");
String gameReleaseNaDots = gameReleaseNa.substring(8, 10) + "." + gameReleaseNa.substring(5, 7)
+ "." + gameReleaseNa.substring(0, 4);
String gameReleaseAu = resultSet.getString("Game_Release_AU");
String gameReleaseAuDots;
if (gameReleaseAu != null) {
gameReleaseAuDots = gameReleaseAu.substring(8, 10) + "." + gameReleaseAu.substring(5, 7)
+ "." + gameReleaseAu.substring(0, 4);
} else {
gameReleaseAuDots = "Unknown";
}
int gameUsk = resultSet.getInt("Game_USK_Rating");
int gamePegi = resultSet.getInt("Game_PEGI_Rating");
String gameEsrb = resultSet.getString("Game_ESRB_Rating");
String gameCero = resultSet.getString("Game_CERO_Rating");
String gameAcb = resultSet.getString("Game_ACB_Rating");
String gamePlayers = resultSet.getString("Game_Players");
if (gamePegi != 0) {
result += id + ": " + gameName + ", " + gameConsole + ", " + gameDeveloper + ", " + gamePublisherEu + ", " + gamePublisherJp + ", " + gamePublisherNa + ", " + gameGenre + ", " + gameReleaseEuDots + ", " + gameReleaseJpDots + ", " + gameReleaseNaDots + ", " + gameReleaseAuDots + ", " + gameUsk + ", " + gamePegi + ", " + gameEsrb + ", " + gameCero + ", " + gameAcb + ", " + gamePlayers + "\n";
} else {
result += id + ": " + gameName + ", " + gameConsole + ", " + gameDeveloper + ", " + gamePublisherEu + ", " + gamePublisherJp + ", " + gamePublisherNa + ", " + gameGenre + ", " + gameReleaseEuDots + ", " + gameReleaseJpDots + ", " + gameReleaseNaDots + ", " + gameReleaseAuDots + ", " + gameUsk + ", Unknown, " + gameEsrb + ", " + gameCero + ", " + gameAcb + ", " + gamePlayers + "\n";
}
int id = resultSet.getInt("Game_ID");
String gameName = resultSet.getString("Game_Name");
String gameConsole = resultSet.getString("Game_Console");
String gameDeveloper = resultSet.getString("Game_Developer");
String gamePublisherEu = resultSet.getString("Game_Developer");
String gamePublisherJp = resultSet.getString("Game_Console");
String gamePublisherNa = resultSet.getString("Game_Console");
String gameGenre = resultSet.getString("Game_Genre");
String gameReleaseEu = resultSet.getString("Game_Release_EU");
String gameReleaseEuDots = gameReleaseEu.substring(8, 10) + "." + gameReleaseEu.substring(5, 7) + "."
+ gameReleaseEu.substring(0, 4);
String gameReleaseJp = resultSet.getString("Game_Release_JP");
String gameReleaseJpDots = gameReleaseJp.substring(8, 10) + "." + gameReleaseJp.substring(5, 7) + "."
+ gameReleaseJp.substring(0, 4);
String gameReleaseNa = resultSet.getString("Game_Release_NA");
String gameReleaseNaDots = gameReleaseNa.substring(8, 10) + "." + gameReleaseNa.substring(5, 7) + "."
+ gameReleaseNa.substring(0, 4);
String gameReleaseAu = resultSet.getString("Game_Release_AU");
String gameReleaseAuDots;
if (gameReleaseAu != null) {
gameReleaseAuDots = gameReleaseAu.substring(8, 10) + "." + gameReleaseAu.substring(5, 7) + "."
+ gameReleaseAu.substring(0, 4);
} else {
gameReleaseAuDots = "Unknown";
}
int gameUsk = resultSet.getInt("Game_USK_Rating");
int gamePegi = resultSet.getInt("Game_PEGI_Rating");
String gameEsrb = resultSet.getString("Game_ESRB_Rating");
String gameCero = resultSet.getString("Game_CERO_Rating");
String gameAcb = resultSet.getString("Game_ACB_Rating");
String gamePlayers = resultSet.getString("Game_Players");
if (gamePegi != 0) {
result += id + ": " + gameName + ", " + gameConsole + ", " + gameDeveloper + ", " + gamePublisherEu
+ ", " + gamePublisherJp + ", " + gamePublisherNa + ", " + gameGenre + ", "
+ gameReleaseEuDots + ", " + gameReleaseJpDots + ", " + gameReleaseNaDots + ", "
+ gameReleaseAuDots + ", " + gameUsk + ", " + gamePegi + ", " + gameEsrb + ", " + gameCero
+ ", " + gameAcb + ", " + gamePlayers + "\n";
} else {
result += id + ": " + gameName + ", " + gameConsole + ", " + gameDeveloper + ", " + gamePublisherEu
+ ", " + gamePublisherJp + ", " + gamePublisherNa + ", " + gameGenre + ", "
+ gameReleaseEuDots + ", " + gameReleaseJpDots + ", " + gameReleaseNaDots + ", "
+ gameReleaseAuDots + ", " + gameUsk + ", Unknown, " + gameEsrb + ", " + gameCero + ", "
+ gameAcb + ", " + gamePlayers + "\n";
}
}
statement.close();
@ -86,7 +93,7 @@ public class Games {
// The substring removes the last New line in the String.
return result.substring(0, result.length() - 1);
}
public String checkGames() {
String result = "";
String query = "SELECT Game_Name FROM Games";
@ -1089,7 +1096,7 @@ public class Games {
return result.substring(0, result.length() - 2);
}
public String checkAllSameReleaseYear() {
String result = "";
String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU FROM Games";
@ -1106,13 +1113,16 @@ public class Games {
String gameReleaseJp = resultSet.getString("Game_Release_JP");
String gameReleaseNa = resultSet.getString("Game_Release_NA");
String gameReleaseAu = resultSet.getString("Game_Release_AU");
if (gameReleaseAu == null) {
} else {
if (gameReleaseEu.substring(0, 4).equals(gameReleaseJp.substring(0, 4)) && gameReleaseJp.substring(0, 4).equals(gameReleaseNa.substring(0, 4))
&& gameReleaseEu.substring(0, 4).equals(gameReleaseNa.substring(0, 4)) && gameReleaseAu.substring(0, 4).equals(gameReleaseEu.substring(0, 4))
&& gameReleaseAu.substring(0, 4).equals(gameReleaseJp.substring(0, 4)) && gameReleaseAu.substring(0, 4).equals(gameReleaseNa.substring(0, 4))) {
if (gameReleaseEu.substring(0, 4).equals(gameReleaseJp.substring(0, 4))
&& gameReleaseJp.substring(0, 4).equals(gameReleaseNa.substring(0, 4))
&& gameReleaseEu.substring(0, 4).equals(gameReleaseNa.substring(0, 4))
&& gameReleaseAu.substring(0, 4).equals(gameReleaseEu.substring(0, 4))
&& gameReleaseAu.substring(0, 4).equals(gameReleaseJp.substring(0, 4))
&& gameReleaseAu.substring(0, 4).equals(gameReleaseNa.substring(0, 4))) {
result += gameName + ", ";
}
}
@ -1127,7 +1137,7 @@ public class Games {
return result.substring(0, result.length() - 2);
}
public String checkAllDifferentReleaseYear() {
String result = "";
String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU FROM Games";
@ -1144,13 +1154,16 @@ public class Games {
String gameReleaseJp = resultSet.getString("Game_Release_JP");
String gameReleaseNa = resultSet.getString("Game_Release_NA");
String gameReleaseAu = resultSet.getString("Game_Release_AU");
if (gameReleaseAu == null) {
result += gameName + ", ";
} else {
if (!gameReleaseEu.substring(0, 4).equals(gameReleaseJp.substring(0, 4)) || !gameReleaseJp.substring(0, 4).equals(gameReleaseNa.substring(0, 4))
|| !gameReleaseEu.substring(0, 4).equals(gameReleaseNa.substring(0, 4)) || !gameReleaseAu.substring(0, 4).equals(gameReleaseEu.substring(0, 4))
|| !gameReleaseAu.substring(0, 4).equals(gameReleaseJp.substring(0, 4)) || !gameReleaseAu.substring(0, 4).equals(gameReleaseNa.substring(0, 4))) {
if (!gameReleaseEu.substring(0, 4).equals(gameReleaseJp.substring(0, 4))
|| !gameReleaseJp.substring(0, 4).equals(gameReleaseNa.substring(0, 4))
|| !gameReleaseEu.substring(0, 4).equals(gameReleaseNa.substring(0, 4))
|| !gameReleaseAu.substring(0, 4).equals(gameReleaseEu.substring(0, 4))
|| !gameReleaseAu.substring(0, 4).equals(gameReleaseJp.substring(0, 4))
|| !gameReleaseAu.substring(0, 4).equals(gameReleaseNa.substring(0, 4))) {
result += gameName + ", ";
}
}
@ -1165,7 +1178,7 @@ public class Games {
return result.substring(0, result.length() - 2);
}
public String checkOnePlayer() {
String result = "";
String query = "SELECT Game_Name, Game_Players FROM Games";
@ -1180,7 +1193,8 @@ public class Games {
String gameName = resultSet.getString("Game_Name");
String gamePlayers = resultSet.getString("Game_Players");
if (gamePlayers.equals("1") || gamePlayers.equals("1-2") || gamePlayers.equals("1-4") || gamePlayers.equals("1-8")) {
if (gamePlayers.equals("1") || gamePlayers.equals("1-2") || gamePlayers.equals("1-4")
|| gamePlayers.equals("1-8")) {
result += gameName + ", ";
}
@ -1194,7 +1208,7 @@ public class Games {
return result.substring(0, result.length() - 2);
}
public String checkTwoPlayer() {
String result = "";
String query = "SELECT Game_Name, Game_Players FROM Games";
@ -1223,7 +1237,7 @@ public class Games {
return result.substring(0, result.length() - 2);
}
public String checkFourPlayer() {
String result = "";
String query = "SELECT Game_Name, Game_Players FROM Games";
@ -1252,7 +1266,7 @@ public class Games {
return result.substring(0, result.length() - 2);
}
public String checkEightPlayer() {
String result = "";
String query = "SELECT Game_Name, Game_Players FROM Games";
@ -1281,7 +1295,7 @@ public class Games {
return result.substring(0, result.length() - 2);
}
public String checkOnePlayerOnly() {
String result = "";
String query = "SELECT Game_Name, Game_Players FROM Games";

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

@ -177,49 +177,49 @@ public class GamesTest extends TestCase {
String actual = testObject.checkReleaseDateUnknown();
assertEquals(expected, actual);
}
public void test_checkAllSameReleaseYear() {
Games testObject = new Games();
String expected = "Ratchet & Clank, Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Super Smash Bros. Ultimate, Jet Set Radio Future, AI: The Somnium Files, Crash Bandicoot N. Sane Trilogy";
String actual = testObject.checkAllSameReleaseYear();
assertEquals(expected, actual);
}
public void test_checkAllDifferentReleaseYear() {
Games testObject = new Games();
String expected = "Persona 5 Royal, Rhythm Paradise, Yakuza: Dead Souls, Breakdown, Persona 3 Portable, Tomodachi Life, Beautiful Katamari, Atelier Totori Plus";
String actual = testObject.checkAllDifferentReleaseYear();
assertEquals(expected, actual);
}
public void test_checkOnePlayer() {
Games testObject = new Games();
String expected = "Persona 5 Royal, Ratchet & Clank, Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Rhythm Paradise, Super Smash Bros. Ultimate, Yakuza: Dead Souls, Jet Set Radio Future, Breakdown, AI: The Somnium Files, Persona 3 Portable, Tomodachi Life, Beautiful Katamari, Atelier Totori Plus, Crash Bandicoot N. Sane Trilogy";
String actual = testObject.checkOnePlayer();
assertEquals(expected, actual);
}
public void test_checkTwoPlayer() {
Games testObject = new Games();
String expected = "Astral Chain, Super Smash Bros. Ultimate, Jet Set Radio Future";
String actual = testObject.checkTwoPlayer();
assertEquals(expected, actual);
}
public void test_checkFourPlayer() {
Games testObject = new Games();
String expected = "Super Smash Bros. Ultimate, Jet Set Radio Future";
String actual = testObject.checkFourPlayer();
assertEquals(expected, actual);
}
public void test_checkEightPlayer() {
Games testObject = new Games();
String expected = "Super Smash Bros. Ultimate";
String actual = testObject.checkEightPlayer();
assertEquals(expected, actual);
}
public void test_checkOnePlayerOnly() {
Games testObject = new Games();
String expected = "Persona 5 Royal, Ratchet & Clank, Fire Emblem: Three Houses, Triangle Strategy, Rhythm Paradise, Yakuza: Dead Souls, Breakdown, AI: The Somnium Files, Persona 3 Portable, Tomodachi Life, Beautiful Katamari, Atelier Totori Plus, Crash Bandicoot N. Sane Trilogy";

Loading…
Cancel
Save