From 576c24abcdecf3850b27d6fccad49c7ec308c492 Mon Sep 17 00:00:00 2001 From: Adem Berber Date: Sat, 12 Feb 2022 02:34:14 +0100 Subject: [PATCH] Refactored Class and Test Class --- .../java/de/hs_fulda/ciip/projjpn/Games.java | 212 +++++++++--------- .../de/hs_fulda/ciip/projjpn/GamesTest.java | 13 +- 2 files changed, 112 insertions(+), 113 deletions(-) diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java index 0b0de1f..165d0e7 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Games.java @@ -8,7 +8,7 @@ import java.sql.Statement; public class Games { private String databaseURL = "jdbc:ucanaccess://GamesDB.accdb"; - + public boolean checkConnection() { try { Connection connection = DriverManager.getConnection(databaseURL); @@ -20,7 +20,7 @@ public class Games { return false; } } - + public String checkConsoles() { String result = ""; String query = "SELECT Game_Console FROM Games"; @@ -35,32 +35,30 @@ public class Games { 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 + ", "; - + 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(); @@ -68,10 +66,10 @@ public class Games { } catch (SQLException e) { e.printStackTrace(); } - // The substring removes the last New line in the String. + 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"; @@ -83,17 +81,16 @@ public class Games { 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 + ", "; - } - + 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(); @@ -101,10 +98,10 @@ public class Games { } 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"; @@ -116,17 +113,16 @@ public class Games { 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 + ", "; - } - + 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(); @@ -134,10 +130,10 @@ public class Games { } catch (SQLException e) { e.printStackTrace(); } - // The substring removes the last New line in the String. + return result.substring(0, result.length() - 2); } - + public String checkAllDifferentPublishersDeveloper() { String result = ""; 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); 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(); connection.close(); @@ -168,10 +164,10 @@ public class Games { } catch (SQLException e) { e.printStackTrace(); } - // The substring removes the last New line in the String. + return result.substring(0, result.length() - 2); } - + public String checkAllSameReleaseDates() { String result = ""; 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); 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(); connection.close(); @@ -208,10 +205,10 @@ public class Games { } catch (SQLException e) { e.printStackTrace(); } - // The substring removes the last New line in the String. + return result.substring(0, result.length() - 2); } - + public String checkAllDifferentReleaseDates() { String result = ""; 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); 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(); connection.close(); @@ -248,7 +246,7 @@ public class Games { } catch (SQLException e) { e.printStackTrace(); } - // The substring removes the last New line in the String. + return result.substring(0, result.length() - 2); } } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java index 895ef66..5acfde4 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/GamesTest.java @@ -1,4 +1,5 @@ package de.hs_fulda.ciip.projjpn; + import junit.framework.TestCase; public class GamesTest extends TestCase { @@ -8,42 +9,42 @@ public class GamesTest extends TestCase { boolean actual = testObject.checkConnection(); assertEquals(expected, actual); } - + public void test_checkConsoles() { 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.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); } - + public void test_checkAllSamePublishersDeveloper() { Games testObject = new Games(); String expected = "Beautiful Katamari"; String actual = testObject.checkAllDifferentPublishersDeveloper(); assertEquals(expected, actual); } - + public void test_checkAllSameReleaseDates() { Games testObject = new Games(); String expected = "Astral Chain, Fire Emblem: Three Houses, Triangle Strategy, Super Smash Bros. Ultimate"; String actual = testObject.checkAllSameReleaseDates(); assertEquals(expected, actual); } - + public void test_checkAllDifferentReleaseDates() { Games testObject = new Games(); String expected = "Rhythm Paradise, Yakuza: Dead Souls, Breakdown, Persona 3 Portable, Beautiful Katamari, Atelier Totori Plus";