From 46d24fcdae0ad24ba0c56e216f1b91b45cb81b09 Mon Sep 17 00:00:00 2001 From: Adem Berber Date: Sat, 12 Feb 2022 19:41:06 +0100 Subject: [PATCH] Added Developers Checker + Test --- .../java/de/hs_fulda/ciip/projjpn/Games.java | 43 +++++++++++++++++++ .../de/hs_fulda/ciip/projjpn/GamesTest.java | 7 +++ 2 files changed, 50 insertions(+) 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 aa5f764..ec367ab 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 @@ -538,4 +538,47 @@ public class Games { return result.substring(0, result.length() - 2); } + + public String checkDevelopers() { + String result = ""; + String query = "SELECT Game_Developer FROM Games"; + boolean atlus = false; + boolean nintendoSpd = false; + + try { + Connection connection = DriverManager.getConnection(databaseURL); + + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(query); + + while (resultSet.next()) { + String gameDeveloper = resultSet.getString("Game_Developer"); + + if (atlus && gameDeveloper.equals("Atlus")) { + continue; + } else if (nintendoSpd && gameDeveloper.equals("Nintendo SPD")) { + continue; + } + + switch (gameDeveloper) { + case "Atlus": + atlus = true; + break; + case "Nintendo SPD": + nintendoSpd = true; + break; + } + + result += gameDeveloper + ", "; + + } + statement.close(); + connection.close(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + 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 66c06e2..bb0b6b8 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 @@ -114,4 +114,11 @@ public class GamesTest extends TestCase { String actual = testObject.checkDeveloperAtlus(); assertEquals(expected, actual); } + + public void test_checkDevelopers() { + Games testObject = new Games(); + String expected = "Atlus, Insomniac Games, Platinum Games, Intelligent Systems, Artdink, Nintendo SPD, Sora Ltd., Ryu Ga Gotoku Studio, Sega Sports R&D, Namco, Spike Chunsoft, Bandai Namco Games, Gust Co. Ltd., Vicarious Visions"; + String actual = testObject.checkDevelopers(); + assertEquals(expected, actual); + } }