From c145c2b5102c505ee2e0b8f3a981ec85c6ab8eae Mon Sep 17 00:00:00 2001 From: Adem Berber Date: Mon, 14 Feb 2022 00:22:12 +0100 Subject: [PATCH] Added One Player Only Checker + Test --- .../java/de/hs_fulda/ciip/projjpn/Games.java | 29 +++++++++++++++++++ .../de/hs_fulda/ciip/projjpn/GamesTest.java | 7 +++++ 2 files changed, 36 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 d0b8433..f46e4b4 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 @@ -1281,4 +1281,33 @@ public class Games { return result.substring(0, result.length() - 2); } + + public String checkOnePlayerOnly() { + String result = ""; + String query = "SELECT Game_Name, Game_Players 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 gamePlayers = resultSet.getString("Game_Players"); + + if (gamePlayers.equals("1")) { + result += gameName + ", "; + } + + } + 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 5d3cb23..ddc27a2 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 @@ -219,4 +219,11 @@ public class GamesTest extends TestCase { 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"; + String actual = testObject.checkOnePlayerOnly(); + assertEquals(expected, actual); + } }