Browse Source

Refactored Class and Test Class

dev
Adem Berber 3 years ago
parent
commit
576c24abcd
  1. 212
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java
  2. 13
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java

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

@ -8,7 +8,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 checkConnection() { public boolean checkConnection() {
try { try {
Connection connection = DriverManager.getConnection(databaseURL); Connection connection = DriverManager.getConnection(databaseURL);
@ -20,7 +20,7 @@ public class Games {
return false; return false;
} }
} }
public String checkConsoles() { public String checkConsoles() {
String result = ""; String result = "";
String query = "SELECT Game_Console FROM Games"; String query = "SELECT Game_Console FROM Games";
@ -35,32 +35,30 @@ public class Games {
ResultSet resultSet = statement.executeQuery(query); ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) { 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 + ", ";
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(); statement.close();
connection.close(); connection.close();
@ -68,10 +66,10 @@ public class Games {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
// 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() { public String checkAllSamePublishers() {
String result = ""; String result = "";
String query = "SELECT Game_Name, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA FROM Games"; String query = "SELECT Game_Name, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA FROM Games";
@ -83,17 +81,16 @@ public class Games {
ResultSet resultSet = statement.executeQuery(query); ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) { 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 + ", ";
}
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(); statement.close();
connection.close(); connection.close();
@ -101,10 +98,10 @@ public class Games {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
// 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 checkAllDifferentPublishers() { public String checkAllDifferentPublishers() {
String result = ""; String result = "";
String query = "SELECT Game_Name, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA FROM Games"; String query = "SELECT Game_Name, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA FROM Games";
@ -116,17 +113,16 @@ public class Games {
ResultSet resultSet = statement.executeQuery(query); ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) { 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 + ", ";
}
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(); statement.close();
connection.close(); connection.close();
@ -134,10 +130,10 @@ public class Games {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
// 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 checkAllDifferentPublishersDeveloper() { public String checkAllDifferentPublishersDeveloper() {
String result = ""; String result = "";
String query = "SELECT Game_Name, Game_Developer, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA FROM Games"; String query = "SELECT Game_Name, Game_Developer, Game_Publisher_EU, Game_Publisher_JP, Game_Publisher_NA FROM Games";
@ -149,18 +145,18 @@ public class Games {
ResultSet resultSet = statement.executeQuery(query); ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) { while (resultSet.next()) {
String gameName = resultSet.getString("Game_Name");
String gameDeveloper = resultSet.getString("Game_Developer");
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) && gameDeveloper.equals(gamePublisherEu) && gameDeveloper.equals(gamePublisherJp) && gameDeveloper.equals(gamePublisherNa) ) {
result += gameName + ", ";
}
String gameName = resultSet.getString("Game_Name");
String gameDeveloper = resultSet.getString("Game_Developer");
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) && gameDeveloper.equals(gamePublisherEu)
&& gameDeveloper.equals(gamePublisherJp) && gameDeveloper.equals(gamePublisherNa)) {
result += gameName + ", ";
}
} }
statement.close(); statement.close();
connection.close(); connection.close();
@ -168,10 +164,10 @@ public class Games {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
// 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 checkAllSameReleaseDates() { public String checkAllSameReleaseDates() {
String result = ""; String result = "";
String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU FROM Games"; String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU FROM Games";
@ -183,24 +179,25 @@ public class Games {
ResultSet resultSet = statement.executeQuery(query); ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) { while (resultSet.next()) {
String gameName = resultSet.getString("Game_Name");
String gameReleaseEu = resultSet.getString("Game_Release_EU");
String gameReleaseJp = resultSet.getString("Game_Release_JP");
String gameReleaseNa = resultSet.getString("Game_Release_NA");
String gameReleaseAu = resultSet.getString("Game_Release_AU");
if (gameReleaseAu == null) {
if (gameReleaseEu.equals(gameReleaseJp) && gameReleaseJp.equals(gameReleaseNa) && gameReleaseEu.equals(gameReleaseNa)) {
result += gameName + ", ";
}
} else {
if (gameReleaseEu.equals(gameReleaseJp) && gameReleaseJp.equals(gameReleaseNa) && gameReleaseEu.equals(gameReleaseNa) && gameReleaseAu.equals(gameReleaseEu) && gameReleaseAu.equals(gameReleaseJp) && gameReleaseAu.equals(gameReleaseNa) ) {
result += gameName + ", ";
}
String gameName = resultSet.getString("Game_Name");
String gameReleaseEu = resultSet.getString("Game_Release_EU");
String gameReleaseJp = resultSet.getString("Game_Release_JP");
String gameReleaseNa = resultSet.getString("Game_Release_NA");
String gameReleaseAu = resultSet.getString("Game_Release_AU");
if (gameReleaseAu == null) {
if (gameReleaseEu.equals(gameReleaseJp) && gameReleaseJp.equals(gameReleaseNa)
&& gameReleaseEu.equals(gameReleaseNa)) {
result += gameName + ", ";
}
} else {
if (gameReleaseEu.equals(gameReleaseJp) && gameReleaseJp.equals(gameReleaseNa)
&& gameReleaseEu.equals(gameReleaseNa) && gameReleaseAu.equals(gameReleaseEu)
&& gameReleaseAu.equals(gameReleaseJp) && gameReleaseAu.equals(gameReleaseNa)) {
result += gameName + ", ";
} }
}
} }
statement.close(); statement.close();
connection.close(); connection.close();
@ -208,10 +205,10 @@ public class Games {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
// 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 checkAllDifferentReleaseDates() { public String checkAllDifferentReleaseDates() {
String result = ""; String result = "";
String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU FROM Games"; String query = "SELECT Game_Name, Game_Release_EU, Game_Release_JP, Game_Release_NA, Game_Release_AU FROM Games";
@ -223,24 +220,25 @@ public class Games {
ResultSet resultSet = statement.executeQuery(query); ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) { while (resultSet.next()) {
String gameName = resultSet.getString("Game_Name");
String gameReleaseEu = resultSet.getString("Game_Release_EU");
String gameReleaseJp = resultSet.getString("Game_Release_JP");
String gameReleaseNa = resultSet.getString("Game_Release_NA");
String gameReleaseAu = resultSet.getString("Game_Release_AU");
if (gameReleaseAu == null) {
if (!gameReleaseEu.equals(gameReleaseJp) && !gameReleaseJp.equals(gameReleaseNa) && !gameReleaseEu.equals(gameReleaseNa)) {
result += gameName + ", ";
}
} else {
if (!gameReleaseEu.equals(gameReleaseJp) && !gameReleaseJp.equals(gameReleaseNa) && !gameReleaseEu.equals(gameReleaseNa) && !gameReleaseAu.equals(gameReleaseEu) && !gameReleaseAu.equals(gameReleaseJp) && !gameReleaseAu.equals(gameReleaseNa) ) {
result += gameName + ", ";
}
String gameName = resultSet.getString("Game_Name");
String gameReleaseEu = resultSet.getString("Game_Release_EU");
String gameReleaseJp = resultSet.getString("Game_Release_JP");
String gameReleaseNa = resultSet.getString("Game_Release_NA");
String gameReleaseAu = resultSet.getString("Game_Release_AU");
if (gameReleaseAu == null) {
if (!gameReleaseEu.equals(gameReleaseJp) && !gameReleaseJp.equals(gameReleaseNa)
&& !gameReleaseEu.equals(gameReleaseNa)) {
result += gameName + ", ";
} }
} else {
if (!gameReleaseEu.equals(gameReleaseJp) && !gameReleaseJp.equals(gameReleaseNa)
&& !gameReleaseEu.equals(gameReleaseNa) && !gameReleaseAu.equals(gameReleaseEu)
&& !gameReleaseAu.equals(gameReleaseJp) && !gameReleaseAu.equals(gameReleaseNa)) {
result += gameName + ", ";
}
}
} }
statement.close(); statement.close();
connection.close(); connection.close();
@ -248,7 +246,7 @@ public class Games {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
// The substring removes the last New line in the String.
return result.substring(0, result.length() - 2); return result.substring(0, result.length() - 2);
} }
} }

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

@ -1,4 +1,5 @@
package de.hs_fulda.ciip.projjpn; package de.hs_fulda.ciip.projjpn;
import junit.framework.TestCase; import junit.framework.TestCase;
public class GamesTest extends TestCase { public class GamesTest extends TestCase {
@ -8,42 +9,42 @@ public class GamesTest extends TestCase {
boolean actual = testObject.checkConnection(); boolean actual = testObject.checkConnection();
assertEquals(expected, actual); assertEquals(expected, actual);
} }
public void test_checkConsoles() { 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.checkConsoles(); String actual = testObject.checkConsoles();
assertEquals(expected, actual); assertEquals(expected, actual);
} }
public void test_checkAllSamePublishers() { public void test_checkAllSamePublishers() {
Games testObject = new Games(); 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 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(); String actual = testObject.checkAllSamePublishers();
assertEquals(expected, actual); assertEquals(expected, actual);
} }
public void test_checkAllDifferentPublishers() { public void test_checkAllDifferentPublishers() {
Games testObject = new Games(); Games testObject = new Games();
String expected = "Atelier Totori Plus"; String expected = "Atelier Totori Plus";
String actual = testObject.checkAllDifferentPublishers(); String actual = testObject.checkAllDifferentPublishers();
assertEquals(expected, actual); assertEquals(expected, actual);
} }
public void test_checkAllSamePublishersDeveloper() { public void test_checkAllSamePublishersDeveloper() {
Games testObject = new Games(); Games testObject = new Games();
String expected = "Beautiful Katamari"; String expected = "Beautiful Katamari";
String actual = testObject.checkAllDifferentPublishersDeveloper(); String actual = testObject.checkAllDifferentPublishersDeveloper();
assertEquals(expected, actual); assertEquals(expected, actual);
} }
public void test_checkAllSameReleaseDates() { public void test_checkAllSameReleaseDates() {
Games testObject = new Games(); Games testObject = new Games();
String expected = "Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Super Smash Bros. Ultimate"; String expected = "Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Super Smash Bros. Ultimate";
String actual = testObject.checkAllSameReleaseDates(); String actual = testObject.checkAllSameReleaseDates();
assertEquals(expected, actual); assertEquals(expected, actual);
} }
public void test_checkAllDifferentReleaseDates() { public void test_checkAllDifferentReleaseDates() {
Games testObject = new Games(); Games testObject = new Games();
String expected = "Rhythm Paradise, Yakuza: Dead Souls, Breakdown, Persona 3 Portable, Beautiful Katamari, Atelier Totori Plus"; String expected = "Rhythm Paradise, Yakuza: Dead Souls, Breakdown, Persona 3 Portable, Beautiful Katamari, Atelier Totori Plus";

Loading…
Cancel
Save