From 57114df69ad1e8c2a80119ccfa340d21fae6c111 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 21:59:48 +0100 Subject: [PATCH 01/46] added first test case for getInfoText() & and added productive code for RadioPlayer --- .../java/device/radioPlayer/RadioPlayer.java | 2 +- .../device/radioPlayer/RadioPlayerTest.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 2b91e3e..c319890 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -149,7 +149,7 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { - return null; + return "InfoText"; } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index ac5eefc..ed7f3ac 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -1,6 +1,7 @@ package device.radioPlayer; +import org.assertj.core.util.Strings; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -373,4 +374,20 @@ class RadioPlayerTest { rp.unmute(); assertThat(rp.getVolume()).describedAs("Test if unmute is setting the saved volume").isEqualTo(rp.savedVolume); } + + @ParameterizedTest + @MethodSource("getInfoTextOptions") + void testGetInfoText(String testName, RadioPlayer testRp, boolean expectedResult) { + Boolean volume = Strings.isNullOrEmpty(testRp.getInfoText()); + + assertThat(volume).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream getInfoTextOptions() { + RadioPlayer rp = new RadioPlayer(); + + return Stream.of( + Arguments.of("Test for getInfoText is not empty or null", rp, false) + ); + } } \ No newline at end of file From bc0ecd26756f5bdf63642060c9fc3dff2bba941b Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 22:06:59 +0100 Subject: [PATCH 02/46] added second test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 2 +- .../java/device/radioPlayer/RadioPlayerTest.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index c319890..f7e39ff 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -149,7 +149,7 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { - return "InfoText"; + return playedStation; } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index ed7f3ac..704f8e2 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -377,17 +377,21 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("getInfoTextOptions") - void testGetInfoText(String testName, RadioPlayer testRp, boolean expectedResult) { - Boolean volume = Strings.isNullOrEmpty(testRp.getInfoText()); + void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) { + Boolean bool; + if(testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText()); + else bool = testRp.getInfoText().contains(testRp.playedStation); - assertThat(volume).describedAs(testName).isEqualTo(expectedResult); + assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } static Stream getInfoTextOptions() { RadioPlayer rp = new RadioPlayer(); + RadioPlayer rp1 = new RadioPlayer(); return Stream.of( - Arguments.of("Test for getInfoText is not empty or null", rp, false) + Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), + Arguments.of("Test for getInfoText contains played station", "station", rp1, true) ); } } \ No newline at end of file From 9d20decf08819d7048f07e52cb418f03f36869a6 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 22:28:57 +0100 Subject: [PATCH 03/46] added third test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 4 +++- src/test/java/device/radioPlayer/RadioPlayerTest.java | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index f7e39ff..2129b6b 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -149,7 +149,9 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { - return playedStation; + String infoText = playedStation; + if(regionPlaylist.contains(playedStation)) return ("Regional playlist " + infoText); + else return infoText; } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 704f8e2..f127ab9 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -378,9 +378,10 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("getInfoTextOptions") void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) { - Boolean bool; + Boolean bool = null; if(testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText()); - else bool = testRp.getInfoText().contains(testRp.playedStation); + else if(testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation); + else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -388,10 +389,13 @@ class RadioPlayerTest { static Stream getInfoTextOptions() { RadioPlayer rp = new RadioPlayer(); RadioPlayer rp1 = new RadioPlayer(); + RadioPlayer rp2 = new RadioPlayer(); + rp2.changeRegion("BY"); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), - Arguments.of("Test for getInfoText contains played station", "station", rp1, true) + Arguments.of("Test for getInfoText contains played station", "station", rp1, true), + Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true) ); } } \ No newline at end of file From f754c0a5ce72309d1fcc140db1d0fc1284aeb0bb Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 22:32:58 +0100 Subject: [PATCH 04/46] added fourth test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 2 +- src/test/java/device/radioPlayer/RadioPlayerTest.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 2129b6b..44621be 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -151,7 +151,7 @@ public class RadioPlayer implements Device { public String getInfoText() { String infoText = playedStation; if(regionPlaylist.contains(playedStation)) return ("Regional playlist " + infoText); - else return infoText; + else return ("Saved playlist " + infoText); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index f127ab9..f49390e 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -382,6 +382,7 @@ class RadioPlayerTest { if(testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText()); else if(testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation); else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); + else if(testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist"); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -391,11 +392,13 @@ class RadioPlayerTest { RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp2 = new RadioPlayer(); rp2.changeRegion("BY"); + RadioPlayer rp3 = new RadioPlayer(); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), Arguments.of("Test for getInfoText contains played station", "station", rp1, true), - Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true) + Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true), + Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true) ); } } \ No newline at end of file From dd88b2967c631ec5753c258c4ee61a77bc298a41 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 22:42:52 +0100 Subject: [PATCH 05/46] added fifth test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 4 ++-- src/test/java/device/radioPlayer/RadioPlayerTest.java | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 44621be..c576db2 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -150,8 +150,8 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { String infoText = playedStation; - if(regionPlaylist.contains(playedStation)) return ("Regional playlist " + infoText); - else return ("Saved playlist " + infoText); + if(regionPlaylist.contains(playedStation)) return ("Regional playlist: " + infoText); + else return ("Saved playlist: "+ (savedPlaylist.indexOf(playedStation) + 1) + infoText); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index f49390e..fe6b776 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -383,6 +383,7 @@ class RadioPlayerTest { else if(testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation); else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); else if(testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist"); + else if(testTyp.contains("savedNum")) bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -393,12 +394,15 @@ class RadioPlayerTest { RadioPlayer rp2 = new RadioPlayer(); rp2.changeRegion("BY"); RadioPlayer rp3 = new RadioPlayer(); + RadioPlayer rp4 = new RadioPlayer(); + rp4.next(); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), Arguments.of("Test for getInfoText contains played station", "station", rp1, true), Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true), - Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true) + Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true), + Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true) ); } } \ No newline at end of file From e6541cf2b9ab86082246378827a9c37ce4efa04d Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 22:50:40 +0100 Subject: [PATCH 06/46] added six test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 4 ++-- src/test/java/device/radioPlayer/RadioPlayerTest.java | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index c576db2..badaa85 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -150,8 +150,8 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { String infoText = playedStation; - if(regionPlaylist.contains(playedStation)) return ("Regional playlist: " + infoText); - else return ("Saved playlist: "+ (savedPlaylist.indexOf(playedStation) + 1) + infoText); + if(regionPlaylist.contains(playedStation)) return ("Regional playlist: " + (regionPlaylist.indexOf(playedStation) + 1) + infoText); + else return ("Saved playlist: " + (savedPlaylist.indexOf(playedStation) + 1) + infoText); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index fe6b776..9552318 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -384,6 +384,7 @@ class RadioPlayerTest { else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); else if(testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist"); else if(testTyp.contains("savedNum")) bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1); + else if(testTyp.contains("regionNum")) bool = testRp.getInfoText().contains(("0") + testRp.regionPlaylist.indexOf(testRp.playedStation) + 1); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -396,13 +397,17 @@ class RadioPlayerTest { RadioPlayer rp3 = new RadioPlayer(); RadioPlayer rp4 = new RadioPlayer(); rp4.next(); + RadioPlayer rp5 = new RadioPlayer(); + rp5.changeRegion("HE"); + rp5.next(); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), Arguments.of("Test for getInfoText contains played station", "station", rp1, true), Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true), Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true), - Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true) + Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true), + Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true) ); } } \ No newline at end of file From 0ff584dc0ae67ee01d0cb3c91fd07dfe6b2bd9bf Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 00:05:33 +0100 Subject: [PATCH 07/46] added sevens test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 4 ++++ src/test/java/device/radioPlayer/RadioPlayerTest.java | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index badaa85..22f6c67 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -149,6 +149,10 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { + return (buildInfoText() + "\n Now playing: " + showStationInfo()); + } + + private String buildInfoText() { String infoText = playedStation; if(regionPlaylist.contains(playedStation)) return ("Regional playlist: " + (regionPlaylist.indexOf(playedStation) + 1) + infoText); else return ("Saved playlist: " + (savedPlaylist.indexOf(playedStation) + 1) + infoText); diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 9552318..739a2ad 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -385,6 +385,7 @@ class RadioPlayerTest { else if(testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist"); else if(testTyp.contains("savedNum")) bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1); else if(testTyp.contains("regionNum")) bool = testRp.getInfoText().contains(("0") + testRp.regionPlaylist.indexOf(testRp.playedStation) + 1); + else if(testTyp.contains("stationInfo")) bool = testRp.getInfoText().contains("Now playing"); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -400,6 +401,8 @@ class RadioPlayerTest { RadioPlayer rp5 = new RadioPlayer(); rp5.changeRegion("HE"); rp5.next(); + RadioPlayer rp6 = new RadioPlayer(); + rp6.changeRegion("BY"); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), @@ -407,7 +410,8 @@ class RadioPlayerTest { Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true), Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true), Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true), - Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true) + Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true), + Arguments.of("Test for getInfoText contains station info if station has one", "stationInfo", rp6, true) ); } } \ No newline at end of file From 561d5f6bc27a64088b1bc2d52587508230337ab3 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 00:10:33 +0100 Subject: [PATCH 08/46] added eighth test case for getInfoText() & and added productive code for RadioPlayer --- src/main/java/device/radioPlayer/RadioPlayer.java | 1 + src/test/java/device/radioPlayer/RadioPlayerTest.java | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 22f6c67..7dcc37a 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -149,6 +149,7 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { + if(showStationInfo().equals("")) return buildInfoText(); return (buildInfoText() + "\n Now playing: " + showStationInfo()); } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 739a2ad..7e2f5d0 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -378,7 +378,7 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("getInfoTextOptions") void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) { - Boolean bool = null; + Boolean bool; if(testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText()); else if(testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation); else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); @@ -386,6 +386,7 @@ class RadioPlayerTest { else if(testTyp.contains("savedNum")) bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1); else if(testTyp.contains("regionNum")) bool = testRp.getInfoText().contains(("0") + testRp.regionPlaylist.indexOf(testRp.playedStation) + 1); else if(testTyp.contains("stationInfo")) bool = testRp.getInfoText().contains("Now playing"); + else bool = testRp.getInfoText().contains("Now playing"); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); } @@ -403,6 +404,8 @@ class RadioPlayerTest { rp5.next(); RadioPlayer rp6 = new RadioPlayer(); rp6.changeRegion("BY"); + RadioPlayer rp7 = new RadioPlayer(); + rp7.next(); return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), @@ -411,7 +414,8 @@ class RadioPlayerTest { Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true), Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true), Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true), - Arguments.of("Test for getInfoText contains station info if station has one", "stationInfo", rp6, true) + Arguments.of("Test for getInfoText contains station info if station has one", "stationInfo", rp6, true), + Arguments.of("Test for getInfoText not contains station info if station not has one", "noStationInfo", rp7, false) ); } } \ No newline at end of file From 96c9e5c3b65061e1c0becf339d6ca4da8ebda9b2 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 00:56:03 +0100 Subject: [PATCH 09/46] added first test case for RadioPlayer getOptions() --- .../device/radioPlayer/RadioPlayerTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 7e2f5d0..b7cae0c 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -367,7 +367,7 @@ class RadioPlayerTest { ); } @Test - void TestUnmute() { + void testUnmute() { RadioPlayer rp = new RadioPlayer(); rp.setLautstaerke(40); rp.mute(); @@ -418,4 +418,20 @@ class RadioPlayerTest { Arguments.of("Test for getInfoText not contains station info if station not has one", "noStationInfo", rp7, false) ); } + @ParameterizedTest + @MethodSource("getOptionsOptions") + void testGetOptions(String testName, RadioPlayer testRp) { + + assertThat(testRp.getOptions()).describedAs(testName).isNotEqualTo(null); + } + + static Stream getOptionsOptions() { + RadioPlayer rp = new RadioPlayer(); + + + return Stream.of( + Arguments.of("returnValue of getOptions is not null", rp) + + ); + } } \ No newline at end of file From f6361c27b82eb63c2c57f2b6e5eae88a1c705811 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 01:09:58 +0100 Subject: [PATCH 10/46] added second test case for RadioPlayer getOptions() & added productive code --- src/main/java/device/radioPlayer/RadioPlayer.java | 7 ++++++- src/test/java/device/radioPlayer/RadioPlayerTest.java | 11 +++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 7dcc37a..669d9c1 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -2,8 +2,10 @@ package device.radioPlayer; import device.Device; +import java.lang.reflect.Method; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Arrays; public class RadioPlayer implements Device { @@ -161,7 +163,10 @@ public class RadioPlayer implements Device { @Override public String[] getOptions() { - return new String[0]; + Method[] methods = this.getClass().getDeclaredMethods(); + String[] returnMethods = Arrays.stream(methods).map(Method::getName).toArray(String[]::new); + + return returnMethods; } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index b7cae0c..23078bb 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -420,18 +420,17 @@ class RadioPlayerTest { } @ParameterizedTest @MethodSource("getOptionsOptions") - void testGetOptions(String testName, RadioPlayer testRp) { - - assertThat(testRp.getOptions()).describedAs(testName).isNotEqualTo(null); + void testGetOptions(String testName,String testTyp, RadioPlayer testRp) { + if(testTyp.equals("notNull")) assertThat(testRp.getOptions()).describedAs(testName).isNotEqualTo(null); + if(testTyp.equals("arrayLengthGreater0")) assertThat(testRp.getOptions().length).describedAs(testName).isNotEqualTo(0); } static Stream getOptionsOptions() { RadioPlayer rp = new RadioPlayer(); - return Stream.of( - Arguments.of("returnValue of getOptions is not null", rp) - + Arguments.of("returnValue of getOptions is not null", "notNull", rp), + Arguments.of("should not return an empty array", "arrayLengthGreater0", rp) ); } } \ No newline at end of file From 9ca1d2a492283b9860b6d2a40adeb4596db5d13c Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 01:19:02 +0100 Subject: [PATCH 11/46] added third test case for RadioPlayer getOptions() --- .../java/device/radioPlayer/RadioPlayer.java | 5 ++- .../device/radioPlayer/RadioPlayerTest.java | 40 ++++++++++++++----- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 669d9c1..9461dd9 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -151,13 +151,14 @@ public class RadioPlayer implements Device { @Override public String getInfoText() { - if(showStationInfo().equals("")) return buildInfoText(); + if (showStationInfo().equals("")) return buildInfoText(); return (buildInfoText() + "\n Now playing: " + showStationInfo()); } private String buildInfoText() { String infoText = playedStation; - if(regionPlaylist.contains(playedStation)) return ("Regional playlist: " + (regionPlaylist.indexOf(playedStation) + 1) + infoText); + if (regionPlaylist.contains(playedStation)) + return ("Regional playlist: " + (regionPlaylist.indexOf(playedStation) + 1) + infoText); else return ("Saved playlist: " + (savedPlaylist.indexOf(playedStation) + 1) + infoText); } diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 23078bb..2121aa9 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -1,12 +1,17 @@ package device.radioPlayer; +import device.Device; import org.assertj.core.util.Strings; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; @@ -366,6 +371,7 @@ class RadioPlayerTest { Arguments.of("Test for mute RadioPlayer if volume is saved before muting", "saved", rp1, 30) ); } + @Test void testUnmute() { RadioPlayer rp = new RadioPlayer(); @@ -379,13 +385,15 @@ class RadioPlayerTest { @MethodSource("getInfoTextOptions") void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) { Boolean bool; - if(testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText()); - else if(testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation); - else if(testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); - else if(testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist"); - else if(testTyp.contains("savedNum")) bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1); - else if(testTyp.contains("regionNum")) bool = testRp.getInfoText().contains(("0") + testRp.regionPlaylist.indexOf(testRp.playedStation) + 1); - else if(testTyp.contains("stationInfo")) bool = testRp.getInfoText().contains("Now playing"); + if (testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText()); + else if (testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation); + else if (testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist"); + else if (testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist"); + else if (testTyp.contains("savedNum")) + bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1); + else if (testTyp.contains("regionNum")) + bool = testRp.getInfoText().contains(("0") + testRp.regionPlaylist.indexOf(testRp.playedStation) + 1); + else if (testTyp.contains("stationInfo")) bool = testRp.getInfoText().contains("Now playing"); else bool = testRp.getInfoText().contains("Now playing"); assertThat(bool).describedAs(testName).isEqualTo(expectedResult); @@ -418,11 +426,20 @@ class RadioPlayerTest { Arguments.of("Test for getInfoText not contains station info if station not has one", "noStationInfo", rp7, false) ); } + @ParameterizedTest @MethodSource("getOptionsOptions") - void testGetOptions(String testName,String testTyp, RadioPlayer testRp) { - if(testTyp.equals("notNull")) assertThat(testRp.getOptions()).describedAs(testName).isNotEqualTo(null); - if(testTyp.equals("arrayLengthGreater0")) assertThat(testRp.getOptions().length).describedAs(testName).isNotEqualTo(0); + void testGetOptions(String testName, String testTyp, RadioPlayer testRp) { + if (testTyp.equals("notNull")) assertThat(testRp.getOptions()).describedAs(testName).isNotEqualTo(null); + if (testTyp.equals("arrayLengthGreater0")) + assertThat(testRp.getOptions().length).describedAs(testName).isNotEqualTo(0); + else { + Method[] interfaceMethods = Device.class.getDeclaredMethods(); + List deviceMethods = new ArrayList<>(Arrays.asList(testRp.getOptions())); + for (Method interfaceMethod : interfaceMethods) { + assertThat(deviceMethods.contains(interfaceMethod.getName())).describedAs(testName).isEqualTo(true); + } + } } static Stream getOptionsOptions() { @@ -430,7 +447,8 @@ class RadioPlayerTest { return Stream.of( Arguments.of("returnValue of getOptions is not null", "notNull", rp), - Arguments.of("should not return an empty array", "arrayLengthGreater0", rp) + Arguments.of("should not return an empty array", "arrayLengthGreater0", rp), + Arguments.of("Test if all methods declared in interface device are available", "device", rp) ); } } \ No newline at end of file From 32b80ec46d26c94ee1fc05658214d1b2b1874de4 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 01:39:28 +0100 Subject: [PATCH 12/46] cleaned up RadioPlayer & RadioPlayerTest --- .../java/device/radioPlayer/RadioPlayer.java | 40 +++++++--------- .../device/radioPlayer/RadioPlayerTest.java | 46 ++++--------------- 2 files changed, 25 insertions(+), 61 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 9461dd9..0b341d4 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -1,7 +1,6 @@ package device.radioPlayer; import device.Device; - import java.lang.reflect.Method; import java.time.LocalDateTime; import java.util.ArrayList; @@ -9,8 +8,6 @@ import java.util.Arrays; public class RadioPlayer implements Device { - private int x; - public RadioPlayer() { super(); savedPlaylist.add("YouFM"); @@ -19,13 +16,13 @@ public class RadioPlayer implements Device { playedStation = savedPlaylist.get(0); } - ArrayList savedPlaylist = new ArrayList(); - ArrayList regionPlaylist = new ArrayList(); + ArrayList savedPlaylist = new ArrayList<>(); + ArrayList regionPlaylist = new ArrayList<>(); LocalDateTime now = LocalDateTime.now(); int hour = now.getHour(); - int Lautstaerke = 0; + int volume = 0; int savedVolume; - String playedStation = ""; + String playedStation; public String getYouFMInfoByTime(int x) { if (x >= 5 && x < 10) return YouFMInfo[0]; @@ -63,8 +60,8 @@ public class RadioPlayer implements Device { String[] AntenneBYInfo = {"ANTENNE BAYERN Guten Morgen Bayern", "ANTENNE BAYERN bei der Arbeit", "ANTENNE BAYERN am Nachmittag", "ANTENNE BAYERN am Abend", "ANTENNE BAYERN Hit-Nacht"}; - public void setLautstaerke(int lautstaerke) { - Lautstaerke = lautstaerke; + public void setVolume(int volume) { + this.volume = volume; } public void changeRegion(String region) { @@ -98,21 +95,21 @@ public class RadioPlayer implements Device { @Override public void louder() { - if (Lautstaerke < 100) { - Lautstaerke += 1; - } else Lautstaerke = 100; + if (volume < 100) { + volume += 1; + } else volume = 100; } @Override public void quieter() { - if (Lautstaerke > 0) { - Lautstaerke -= 1; - } else Lautstaerke = 0; + if (volume > 0) { + volume -= 1; + } else volume = 0; } @Override public int getVolume() { - return Lautstaerke; + return volume; } @Override @@ -165,9 +162,8 @@ public class RadioPlayer implements Device { @Override public String[] getOptions() { Method[] methods = this.getClass().getDeclaredMethods(); - String[] returnMethods = Arrays.stream(methods).map(Method::getName).toArray(String[]::new); - return returnMethods; + return Arrays.stream(methods).map(Method::getName).toArray(String[]::new); } @Override @@ -208,17 +204,16 @@ public class RadioPlayer implements Device { @Override public String mute() { savedVolume = getVolume(); - setLautstaerke(0); + setVolume(0); return "RadioPlayer is muted now"; } @Override public String unmute() { - setLautstaerke(savedVolume); + setVolume(savedVolume); return ("RadioPlayer is unmuted Volume is set to " + getVolume()); } - @Override public String play() { if (regionPlaylist.contains(playedStation)) @@ -238,8 +233,6 @@ public class RadioPlayer implements Device { default: return ""; } - - } public String saveStation() { @@ -249,7 +242,6 @@ public class RadioPlayer implements Device { return "Station " + playedStation + " is saved in your Station list"; } - public String deleteStation() { String station = playedStation; if ((savedPlaylist.size()) > 1) { diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 2121aa9..b0dae7a 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -1,6 +1,5 @@ package device.radioPlayer; - import device.Device; import org.assertj.core.util.Strings; import org.junit.jupiter.api.Test; @@ -18,7 +17,6 @@ import static org.assertj.core.api.Assertions.assertThat; class RadioPlayerTest { - @ParameterizedTest @MethodSource("quieterLouderOptions") void quieterLouderTest(String testName, RadioPlayer testRp, int expectedResult) { @@ -31,13 +29,13 @@ class RadioPlayerTest { RadioPlayer rp2 = new RadioPlayer(); RadioPlayer rp3 = new RadioPlayer(); RadioPlayer rp4 = new RadioPlayer(); - rp1.setLautstaerke(0); + rp1.setVolume(0); rp1.louder(); - rp2.setLautstaerke(100); + rp2.setVolume(100); rp2.louder(); - rp3.setLautstaerke(1); + rp3.setVolume(1); rp3.quieter(); - rp4.setLautstaerke(0); + rp4.setVolume(0); rp4.quieter(); return Stream.of( Arguments.of("Test for one step louder", rp1, 1), @@ -61,7 +59,6 @@ class RadioPlayerTest { rp1.changeRegion("BY"); rp2.changeRegion("HE"); rp3.changeRegion("BW"); - return Stream.of( Arguments.of("Test change Region to Bayern", rp1, "Antenne Bayern"), Arguments.of("Test change Region to Hessen", rp2, "Hit Radio FFH"), @@ -69,7 +66,6 @@ class RadioPlayerTest { ); } - @ParameterizedTest @MethodSource("prevNextOptions") void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) { @@ -95,7 +91,6 @@ class RadioPlayerTest { rp6.changeRegion("BY"); rp6.saveStation(); rp6.next(); - return Stream.of( Arguments.of("Next Station Test for saved Stations", rp1, "Teddy"), Arguments.of("Prev Station Test for saved Stations", rp2, "YouFM"), @@ -159,7 +154,6 @@ class RadioPlayerTest { rp3.next(); RadioPlayer rp4 = new RadioPlayer(); rp4.next(); - return Stream.of( Arguments.of("Show Station Info for first saved Radio", rp1, rp1.getYouFMInfoByTime(rp1.hour)), Arguments.of("Show Station Info for regional Station", rp2, rp2.getAntenneBYInfoByTime(rp2.hour)), @@ -168,17 +162,6 @@ class RadioPlayerTest { ); } - /* - - @Test - void getInfoText() { - } - - @Test - void getOptions() { - } - */ - @ParameterizedTest @MethodSource("chooseItemOptions") void testChooseItem(String testName, RadioPlayer testRp, String expectedResult) { @@ -202,7 +185,6 @@ class RadioPlayerTest { RadioPlayer rp5 = new RadioPlayer(); rp5.changeRegion("BY"); rp5.chooseItem(-2); - return Stream.of( Arguments.of("Test select station in saved playlist to play with nr isn`t bigger than playlist size", rp, "Teddy"), Arguments.of("Test select station in saved playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp1, "MegaHits"), @@ -250,7 +232,6 @@ class RadioPlayerTest { rp2.saveStation(); rp3.changeRegion("BY"); rp3.saveStation(); - return Stream.of( Arguments.of("Test for saving station in saved playlist", rp1, "normal", "Antenne Bayern"), Arguments.of("Test for not saving station which is already in saved playlist", rp2, "normal", "MegaHits"), @@ -275,7 +256,6 @@ class RadioPlayerTest { rp1.deleteStation(); rp1.deleteStation(); rp1.deleteStation(); - return Stream.of( Arguments.of("Test for delete station in saved playlist", rp, "delete", false), Arguments.of("Test for not delete station in saved playlist if this is the last station", rp1, "noDelete", true) @@ -295,7 +275,6 @@ class RadioPlayerTest { RadioPlayer rp1 = new RadioPlayer(); rp1.changeRegion("BY"); rp1.changeToSavedPlaylist(); - return Stream.of( Arguments.of("Test for change to saved playlist when you already in saved playlist", rp, "YouFM"), Arguments.of("Test for change to saved playlist when in regional playlist", rp1, "YouFM") @@ -319,7 +298,6 @@ class RadioPlayerTest { RadioPlayer rp2 = new RadioPlayer(); rp2.next(); rp2.changeOrderInSavedPlaylist(-1); - return Stream.of( Arguments.of("Test for change order in saved playlist with nr isn`t bigger than playlist size", rp, 0, "Teddy"), Arguments.of("Test for change order in saved playlist with nr is than bigger playlist size put at the end of playlist", rp1, 2, "YouFM"), @@ -342,7 +320,6 @@ class RadioPlayerTest { RadioPlayer rp = new RadioPlayer(); RadioPlayer rp1 = new RadioPlayer(); rp1.changeRegion("BY"); - return Stream.of( Arguments.of("Test for return saved playlist", rp, "saved", rp.savedPlaylist.toArray(new String[0])), Arguments.of("Test for return regional playlist", rp1, "region", rp1.regionPlaylist.toArray(new String[0])) @@ -360,12 +337,11 @@ class RadioPlayerTest { static Stream muteOptions() { RadioPlayer rp = new RadioPlayer(); - rp.setLautstaerke(25); + rp.setVolume(25); rp.mute(); RadioPlayer rp1 = new RadioPlayer(); - rp1.setLautstaerke(30); + rp1.setVolume(30); rp1.mute(); - return Stream.of( Arguments.of("Test for mute RadioPlayer if volume is actually 0", "actual", rp, 0), Arguments.of("Test for mute RadioPlayer if volume is saved before muting", "saved", rp1, 30) @@ -375,7 +351,7 @@ class RadioPlayerTest { @Test void testUnmute() { RadioPlayer rp = new RadioPlayer(); - rp.setLautstaerke(40); + rp.setVolume(40); rp.mute(); rp.unmute(); assertThat(rp.getVolume()).describedAs("Test if unmute is setting the saved volume").isEqualTo(rp.savedVolume); @@ -401,10 +377,8 @@ class RadioPlayerTest { static Stream getInfoTextOptions() { RadioPlayer rp = new RadioPlayer(); - RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp2 = new RadioPlayer(); rp2.changeRegion("BY"); - RadioPlayer rp3 = new RadioPlayer(); RadioPlayer rp4 = new RadioPlayer(); rp4.next(); RadioPlayer rp5 = new RadioPlayer(); @@ -414,12 +388,11 @@ class RadioPlayerTest { rp6.changeRegion("BY"); RadioPlayer rp7 = new RadioPlayer(); rp7.next(); - return Stream.of( Arguments.of("Test for getInfoText is not empty or null", "null", rp, false), - Arguments.of("Test for getInfoText contains played station", "station", rp1, true), + Arguments.of("Test for getInfoText contains played station", "station", rp, true), Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true), - Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true), + Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp, true), Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true), Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true), Arguments.of("Test for getInfoText contains station info if station has one", "stationInfo", rp6, true), @@ -444,7 +417,6 @@ class RadioPlayerTest { static Stream getOptionsOptions() { RadioPlayer rp = new RadioPlayer(); - return Stream.of( Arguments.of("returnValue of getOptions is not null", "notNull", rp), Arguments.of("should not return an empty array", "arrayLengthGreater0", rp), From fc98df250dfd70538ee1aa7d86dfe44efeed8d1e Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 02:00:44 +0100 Subject: [PATCH 13/46] revised test for RadioPlayer getYouFMInfoByTime() --- .../device/radioPlayer/RadioPlayerTest.java | 45 ++++++------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index b0dae7a..51a85cf 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -101,40 +101,23 @@ class RadioPlayerTest { ); } - @Test - void YouFMInfoByTimeTest() { - RadioPlayer rp = new RadioPlayer(); - assertThat(rp.getYouFMInfoByTime(8)).describedAs("YouFM info by Time at 8.00").isEqualTo("YOUFM Good Morning Show"); - } - - @Test - void YouFMInfoByTime2Test() { - RadioPlayer rp = new RadioPlayer(); - assertThat(rp.getYouFMInfoByTime(3)).describedAs("YouFM info by Time at 3.00").isEqualTo("YOUFM Junge Nacht der ARD"); - } - - @Test - void AntenneBYInfoByTimeTest() { - RadioPlayer rp = new RadioPlayer(); - assertThat(rp.getAntenneBYInfoByTime(8)).describedAs("AntenneBY info by Time at 8.00").isEqualTo("ANTENNE BAYERN Guten Morgen Bayern"); - } - - @Test - void AntenneBYInfoByTime2Test() { - RadioPlayer rp = new RadioPlayer(); - assertThat(rp.getAntenneBYInfoByTime(3)).describedAs("AntenneBY info by Time at 3.00").isEqualTo("ANTENNE BAYERN Hit-Nacht"); - } - - @Test - void BR3InfoByTimeTest() { - RadioPlayer rp = new RadioPlayer(); - assertThat(rp.getBR3InfoByTime(5)).describedAs("BR3 info by Time at 5.00").isEqualTo("Sebastian Winkler und die Frühaufdreher"); + @ParameterizedTest + @MethodSource("infoByTimeOptions") + void infoByTimeInfo(String testName, RadioPlayer testRp, String testTyp, int hour, String expectedResult) { + if(testTyp.equals("YouFm")) assertThat(testRp.getYouFMInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); } - @Test - void BR3InfoByTime2Test() { + static Stream infoByTimeOptions() { RadioPlayer rp = new RadioPlayer(); - assertThat(rp.getBR3InfoByTime(21)).describedAs("BR3 info by Time at 21.00").isEqualTo("Matuschke - der etwas andere Abend"); + return Stream.of( + Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 5, rp.YouFMInfo[0]), + Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 10, rp.YouFMInfo[1]), + Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 14, rp.YouFMInfo[2]), + Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 18, rp.YouFMInfo[3]), + Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 20, rp.YouFMInfo[4]), + Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 22, rp.YouFMInfo[5]), + Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 3, rp.YouFMInfo[6]) + ); } @ParameterizedTest From 089fa0144fc4cee135db2b69a6ec138c1902d440 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 02:07:22 +0100 Subject: [PATCH 14/46] revised test for RadioPlayer getBR3InfoByTime() --- .../device/radioPlayer/RadioPlayerTest.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 51a85cf..d409765 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -105,18 +105,27 @@ class RadioPlayerTest { @MethodSource("infoByTimeOptions") void infoByTimeInfo(String testName, RadioPlayer testRp, String testTyp, int hour, String expectedResult) { if(testTyp.equals("YouFm")) assertThat(testRp.getYouFMInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); + if(testTyp.equals("BR3")) assertThat(testRp.getBR3InfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); } static Stream infoByTimeOptions() { RadioPlayer rp = new RadioPlayer(); return Stream.of( Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 5, rp.YouFMInfo[0]), - Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 10, rp.YouFMInfo[1]), - Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 14, rp.YouFMInfo[2]), - Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 18, rp.YouFMInfo[3]), - Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 20, rp.YouFMInfo[4]), - Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 22, rp.YouFMInfo[5]), - Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 3, rp.YouFMInfo[6]) + Arguments.of("Station info YouFm at 10:00 am", rp, "YouFM", 10, rp.YouFMInfo[1]), + Arguments.of("Station info YouFm at 2:00 pm", rp, "YouFM", 14, rp.YouFMInfo[2]), + Arguments.of("Station info YouFm at 6:00 pm", rp, "YouFM", 18, rp.YouFMInfo[3]), + Arguments.of("Station info YouFm at 8:00 pm", rp, "YouFM", 20, rp.YouFMInfo[4]), + Arguments.of("Station info YouFm at 10:00 pm", rp, "YouFM", 22, rp.YouFMInfo[5]), + Arguments.of("Station info YouFm at 3:00 am", rp, "YouFM", 3, rp.YouFMInfo[6]), + Arguments.of("Station info BR3 at 5:00 am", rp, "BR3", 5, rp.BR3Info[0]), + Arguments.of("Station info BR3 at 9:00 am", rp, "BR3", 9, rp.BR3Info[1]), + Arguments.of("Station info BR3 at 12:00 am", rp, "BR3", 12, rp.BR3Info[2]), + Arguments.of("Station info BR3 at 1:00 pm", rp, "BR3", 13, rp.BR3Info[3]), + Arguments.of("Station info BR3 at 4:00 pm", rp, "BR3", 16, rp.BR3Info[4]), + Arguments.of("Station info BR3 at 7:00 pm", rp, "BR3", 19, rp.BR3Info[5]), + Arguments.of("Station info BR3 at 9:00 pm", rp, "BR3", 21, rp.BR3Info[6]), + Arguments.of("Station info BR3 at 3:00 am", rp, "BR3", 3, rp.BR3Info[7]) ); } From 5885370fe321bede908b3baf3990fc0e9282dca3 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 02:14:58 +0100 Subject: [PATCH 15/46] revised test for RadioPlayer getAntenneBYInfoByTime() --- src/test/java/device/radioPlayer/RadioPlayerTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index d409765..680109c 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -104,8 +104,9 @@ class RadioPlayerTest { @ParameterizedTest @MethodSource("infoByTimeOptions") void infoByTimeInfo(String testName, RadioPlayer testRp, String testTyp, int hour, String expectedResult) { - if(testTyp.equals("YouFm")) assertThat(testRp.getYouFMInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); + if(testTyp.equals("YouFM")) assertThat(testRp.getYouFMInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); if(testTyp.equals("BR3")) assertThat(testRp.getBR3InfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); + if(testTyp.equals("AntenneBY")) assertThat(testRp.getAntenneBYInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult); } static Stream infoByTimeOptions() { @@ -125,7 +126,12 @@ class RadioPlayerTest { Arguments.of("Station info BR3 at 4:00 pm", rp, "BR3", 16, rp.BR3Info[4]), Arguments.of("Station info BR3 at 7:00 pm", rp, "BR3", 19, rp.BR3Info[5]), Arguments.of("Station info BR3 at 9:00 pm", rp, "BR3", 21, rp.BR3Info[6]), - Arguments.of("Station info BR3 at 3:00 am", rp, "BR3", 3, rp.BR3Info[7]) + Arguments.of("Station info BR3 at 3:00 am", rp, "BR3", 3, rp.BR3Info[7]), + Arguments.of("Station info AntenneBY at 5:00 am", rp, "AntenneBY", 5, rp.AntenneBYInfo[0]), + Arguments.of("Station info AntenneBY at 9:00 am", rp, "AntenneBY", 9, rp.AntenneBYInfo[1]), + Arguments.of("Station info AntenneBY at 12:00 am", rp, "AntenneBY", 12, rp.AntenneBYInfo[2]), + Arguments.of("Station info AntenneBY at 3:00 pm", rp, "AntenneBY", 15, rp.AntenneBYInfo[3]), + Arguments.of("Station info AntenneBY at 3:00 am", rp, "AntenneBY", 3, rp.AntenneBYInfo[4]) ); } From 87a0723a68e55d3920d8dcbf5586968ef4abe092 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 02:52:46 +0100 Subject: [PATCH 16/46] Method chooseItem of CDPlayer tested on notSetCD. --- src/main/java/device/cdPlayer/CDPlayer.java | 5 ++++- src/test/java/device/cdPlayer/CDPlayerTest.java | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 57101c8..d70ffca 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -18,7 +18,7 @@ public class CDPlayer implements Device { private List supportedFormats = new ArrayList(Arrays.asList(new String[] {"Audio","MP3","WMA","AAC"})); private String actualPlayTrack=""; - private CD loadedCD; + private CD loadedCD=null; @Override public void louder() { @@ -86,6 +86,9 @@ public class CDPlayer implements Device { @Override public String chooseItem(int itemNr) { + if(this.loadedCD==null){ + throw new ReturnValueNullException(); + } return null; } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index e8d8f77..b820e8f 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -327,4 +327,17 @@ class CDPlayerTest { ); } -} \ No newline at end of file + @ParameterizedTest + @MethodSource("chooseItemTestData") + void chooseItemTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception , String expectedResult) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(1)); + assertEquals(ReturnValueNullException.class, newException.getClass()); + } + static Stream chooseItemTestData () { + CDPlayer cdPlayer1 = new CDPlayer(); + return Stream.of( + Arguments.of("[chooseItem() by notSetCD ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),"") + ); + } + + } \ No newline at end of file From aac81d6b2272f4a06cd72f444fd13eee407a2d7a Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 03:13:09 +0100 Subject: [PATCH 17/46] Method chooseItem of CDPlayer tested on invalidInput->greater than PlayListSize. --- src/main/java/device/cdPlayer/CDPlayer.java | 3 +++ .../ItemNumberNotFoundException.java | 7 +++++++ .../java/device/cdPlayer/CDPlayerTest.java | 21 ++++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/main/java/device/cdPlayer/exceptions/ItemNumberNotFoundException.java diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index d70ffca..561e456 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -89,6 +89,9 @@ public class CDPlayer implements Device { if(this.loadedCD==null){ throw new ReturnValueNullException(); } + if(!(itemNr>=0 && itemNr _cdPlayer.chooseItem(1)); - assertEquals(ReturnValueNullException.class, newException.getClass()); + if(cases.equals("Case1")) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(1)); + assertEquals(ReturnValueNullException.class, newException.getClass()); + } + if(cases.equals("Case2")) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(200)); + assertEquals(ItemNumberNotFoundException.class, newException.getClass()); + } } static Stream chooseItemTestData () { CDPlayer cdPlayer1 = new CDPlayer(); + + String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; + CD audioCD1=new CD("Audio",audioPlayList); + CDPlayer cdPlayer2 = new CDPlayer(); + cdPlayer2.tapOnCdFlap(); + cdPlayer2.setCD(audioCD1); + cdPlayer2.tapOnCdFlap(); + return Stream.of( - Arguments.of("[chooseItem() by notSetCD ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),"") + Arguments.of("[chooseItem() by notSetCD ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),""), + Arguments.of("[chooseItem() by invalidInput ] => shouldThrowItemNumberNotFoundException","Case2", cdPlayer2,new ItemNumberNotFoundException(),"") ); } From 1fb89934b18e65d097cfcecc3c86516826b8dd32 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 03:25:32 +0100 Subject: [PATCH 18/46] Method chooseItem of CDPlayer tested on invalidInput->negativeNumber. --- src/main/java/device/cdPlayer/CDPlayer.java | 4 ++++ .../device/cdPlayer/exceptions/NegativeInputException.java | 7 +++++++ src/test/java/device/cdPlayer/CDPlayerTest.java | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/main/java/device/cdPlayer/exceptions/NegativeInputException.java diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 561e456..755566d 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -89,9 +89,13 @@ public class CDPlayer implements Device { if(this.loadedCD==null){ throw new ReturnValueNullException(); } + if(itemNr<0){ + throw new NegativeInputException(); + } if(!(itemNr>=0 && itemNr _cdPlayer.chooseItem(200)); assertEquals(ItemNumberNotFoundException.class, newException.getClass()); } + if(cases.equals("Case3")) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(-1)); + assertEquals(NegativeInputException.class, newException.getClass()); + } } static Stream chooseItemTestData () { CDPlayer cdPlayer1 = new CDPlayer(); @@ -351,7 +355,8 @@ class CDPlayerTest { return Stream.of( Arguments.of("[chooseItem() by notSetCD ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),""), - Arguments.of("[chooseItem() by invalidInput ] => shouldThrowItemNumberNotFoundException","Case2", cdPlayer2,new ItemNumberNotFoundException(),"") + Arguments.of("[chooseItem() by invalidInput ] => shouldThrowItemNumberNotFoundException","Case2", cdPlayer2,new ItemNumberNotFoundException(),""), + Arguments.of("[chooseItem() by invalidInput:negativeNumber] => shouldThrowItemNumberNotFoundException","Case3", cdPlayer2,new NegativeInputException(),"") ); } From 34b14f3e87bd16d5cf39b293969c10615dcdc3b5 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 03:46:21 +0100 Subject: [PATCH 19/46] Method chooseItem of CDPlayer tested on validInput->shouldReturnMsgWithinTheItemNr. --- src/main/java/device/cdPlayer/CDPlayer.java | 2 +- src/test/java/device/cdPlayer/CDPlayerTest.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 755566d..99b3b81 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -96,7 +96,7 @@ public class CDPlayer implements Device { throw new ItemNumberNotFoundException(); } - return null; + return loadedCD.getPlayList()[itemNr]; } @Override diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 98c8920..3e68055 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -329,7 +329,7 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("chooseItemTestData") - void chooseItemTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception , String expectedResult) { + void chooseItemTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception ) { if(cases.equals("Case1")) { Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(1)); assertEquals(ReturnValueNullException.class, newException.getClass()); @@ -342,6 +342,9 @@ class CDPlayerTest { Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(-1)); assertEquals(NegativeInputException.class, newException.getClass()); } + if(cases.equals("Case4")) { + assertThat(_cdPlayer.chooseItem(1).contains("2")).describedAs(testName).isEqualTo(true); + } } static Stream chooseItemTestData () { CDPlayer cdPlayer1 = new CDPlayer(); @@ -354,9 +357,10 @@ class CDPlayerTest { cdPlayer2.tapOnCdFlap(); return Stream.of( - Arguments.of("[chooseItem() by notSetCD ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),""), - Arguments.of("[chooseItem() by invalidInput ] => shouldThrowItemNumberNotFoundException","Case2", cdPlayer2,new ItemNumberNotFoundException(),""), - Arguments.of("[chooseItem() by invalidInput:negativeNumber] => shouldThrowItemNumberNotFoundException","Case3", cdPlayer2,new NegativeInputException(),"") + Arguments.of("[chooseItem() by notSetCD ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException()), + Arguments.of("[chooseItem() by invalidInput ] => shouldThrowItemNumberNotFoundException","Case2", cdPlayer2,new ItemNumberNotFoundException()), + Arguments.of("[chooseItem() by invalidInput:negativeNumber] => shouldThrowItemNumberNotFoundException","Case3", cdPlayer2,new NegativeInputException()), + Arguments.of("[chooseItem() by validInput] => shouldReturnMsgWithinTheItemNr","Case4", cdPlayer2,null) ); } From 43f556fa6f01e1104ae72e6e8cc9eabaa27649f2 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 13:50:38 +0100 Subject: [PATCH 20/46] Method changePlaySource of CDPlayer tested on activeSource=CDDrive -> shouldReturnCDWechseler. --- src/main/java/device/cdPlayer/CDPlayer.java | 13 ++++++++++--- .../java/device/cdPlayer/CDWechseler.java | 19 +++++++++++++++++++ .../java/device/cdPlayer/CDPlayerTest.java | 16 ++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/main/java/device/cdPlayer/CDWechseler.java diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 99b3b81..827d104 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -20,6 +20,9 @@ public class CDPlayer implements Device { private String actualPlayTrack=""; private CD loadedCD=null; + private CDWechseler cdWechseler; + private String activeSource="CDDrive";//or CDWechseler + @Override public void louder() { if(volume < 100) { @@ -48,9 +51,7 @@ public class CDPlayer implements Device { List playList = Arrays.asList(loadedCD.getPlayList()); int indexOfActualPlayTrack=playList.indexOf(actualPlayTrack); int indexOfNextPlayTrack=(indexOfActualPlayTrack+1)%loadedCD.getPlayList().length; - //System.out.println("actualIndex= "+indexOfActualPlayTrack); this.actualPlayTrack=playList.get(indexOfNextPlayTrack ); - //System.out.println("nextSong= "+actualPlayTrack); } @Override @@ -131,6 +132,10 @@ public class CDPlayer implements Device { } return null; } + public String changePlaySource(){ + this.activeSource="CDWechseler"; + return activeSource; + } //Getters, Setters und SupportMethods public void setCD(CD _loadedCD) { @@ -175,8 +180,10 @@ public class CDPlayer implements Device { this.infoText=this.getClass().getSimpleName()+": Item->"+actualPlayTrack+" from Album->"+this.loadedCD.getAlbumName()+" running."; } - public CD getCD() { return this.loadedCD; } + + + } diff --git a/src/main/java/device/cdPlayer/CDWechseler.java b/src/main/java/device/cdPlayer/CDWechseler.java new file mode 100644 index 0000000..1f408b1 --- /dev/null +++ b/src/main/java/device/cdPlayer/CDWechseler.java @@ -0,0 +1,19 @@ +package device.cdPlayer; + +import java.util.List; + +public class CDWechseler { + private ListCDList; + private boolean running=false; + + + public boolean isRunning() { + return running; + } + + public void activate() { + this.running = true; + } + + +} diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 3e68055..64ea048 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -364,4 +364,20 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("changePlaySourceData") + void changePlaySourceTest(String testName,String cases, CDPlayer _cdPlayer) { + String returnVal=_cdPlayer.changePlaySource(); + assertThat(returnVal).describedAs(testName).isEqualTo("CDWechseler"); + } + static Stream changePlaySourceData () { + CDPlayer cdPlayer1 = new CDPlayer(); + + return Stream.of( + Arguments.of("[changePlaySource() by activeSource=CDDrive ] => shouldReturnCDWechseler","Case1", cdPlayer1) + ); + } + + + } \ No newline at end of file From 7faf0d78e227e462194b3bbcd6208688642b911c Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 14:08:31 +0100 Subject: [PATCH 21/46] Method changePlaySource of CDPlayer tested on activeSource=CDWechseler -> shouldReturnCDDrive. --- src/main/java/device/cdPlayer/CDPlayer.java | 5 ++++- src/test/java/device/cdPlayer/CDPlayerTest.java | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 827d104..89f6ad9 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -133,7 +133,10 @@ public class CDPlayer implements Device { return null; } public String changePlaySource(){ - this.activeSource="CDWechseler"; + if(activeSource.equals("CDDrive")) { + this.activeSource = "CDWechseler"; + }else this.activeSource="CDDrive"; + return activeSource; } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 64ea048..f0ef16a 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -367,14 +367,25 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("changePlaySourceData") void changePlaySourceTest(String testName,String cases, CDPlayer _cdPlayer) { - String returnVal=_cdPlayer.changePlaySource(); - assertThat(returnVal).describedAs(testName).isEqualTo("CDWechseler"); + + if(cases.equals("Case1")) { + String returnVal = _cdPlayer.changePlaySource(); + assertThat(returnVal).describedAs(testName).isEqualTo("CDWechseler"); + } + if(cases.equals("Case2")) { + String returnVal = _cdPlayer.changePlaySource(); + assertThat(returnVal).describedAs(testName).isEqualTo("CDDrive"); + } } static Stream changePlaySourceData () { CDPlayer cdPlayer1 = new CDPlayer(); + CDPlayer cdPlayer2 = new CDPlayer(); + cdPlayer2.changePlaySource(); + return Stream.of( - Arguments.of("[changePlaySource() by activeSource=CDDrive ] => shouldReturnCDWechseler","Case1", cdPlayer1) + Arguments.of("[changePlaySource() by activeSource=CDDrive ] => shouldReturnCDWechseler","Case1", cdPlayer1), + Arguments.of("[changePlaySource() by activeSource=CDWechseler ] => shouldReturnCDDrive","Case2", cdPlayer2) ); } From 29aa121c19fe04d6bf3716be1168a4042243769d Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 14:41:34 +0100 Subject: [PATCH 22/46] Method loadCDWechseler of CDPlayer tested on notRunning=CDWechseler -> shouldThrowAnException. --- src/main/java/device/cdPlayer/CDPlayer.java | 7 ++++++- .../CDWechselerNotRunningException.java | 8 ++++++++ src/test/java/device/cdPlayer/CDPlayerTest.java | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/main/java/device/cdPlayer/exceptions/CDWechselerNotRunningException.java diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 89f6ad9..16f9d66 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -20,7 +20,7 @@ public class CDPlayer implements Device { private String actualPlayTrack=""; private CD loadedCD=null; - private CDWechseler cdWechseler; + private CDWechseler cdWechseler=null; private String activeSource="CDDrive";//or CDWechseler @Override @@ -139,6 +139,11 @@ public class CDPlayer implements Device { return activeSource; } + public void loadCDWechseler(ListcdList){ + if(cdWechseler==null||!cdWechseler.isRunning()){ + throw new CDWechselerNotRunningException(); + } + } //Getters, Setters und SupportMethods public void setCD(CD _loadedCD) { diff --git a/src/main/java/device/cdPlayer/exceptions/CDWechselerNotRunningException.java b/src/main/java/device/cdPlayer/exceptions/CDWechselerNotRunningException.java new file mode 100644 index 0000000..a2bb44d --- /dev/null +++ b/src/main/java/device/cdPlayer/exceptions/CDWechselerNotRunningException.java @@ -0,0 +1,8 @@ +package device.cdPlayer.exceptions; + +public class CDWechselerNotRunningException extends RuntimeException { + + public CDWechselerNotRunningException() { + super("CDWechseler must be active for using."); + } +} diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index f0ef16a..d159604 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -389,6 +389,22 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("loadCDWechselerData") + void loadCDWechselerTest(String testName,String cases, CDPlayer _cdPlayer,ListcdList,Exception exception) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cdList)); + assertEquals(CDWechselerNotRunningException.class, newException.getClass()); + } + static Stream loadCDWechselerData () { + CDPlayer cdPlayer1 = new CDPlayer(); + String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; + CD audioCD1=new CD("Audio",audioPlayList); + ListCdList1=Arrays.asList(audioCD1); + + return Stream.of( + Arguments.of("[loadCDWechseler() by notRunning=CDWechseler ] => shouldThrowAnException", "Case1", cdPlayer1,CdList1,new CDWechselerNotRunningException()) + ); + } } \ No newline at end of file From 77ce33d615fbc124bb040a12b6997fbb6a57cfe9 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 15:00:52 +0100 Subject: [PATCH 23/46] Method loadCDWechseler of CDPlayer tested on WrongCDFormat -> shouldThrowAnException. --- src/main/java/device/cdPlayer/CDPlayer.java | 7 ++++++- .../java/device/cdPlayer/CDPlayerTest.java | 21 +++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 16f9d66..da243d6 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -135,14 +135,19 @@ public class CDPlayer implements Device { public String changePlaySource(){ if(activeSource.equals("CDDrive")) { this.activeSource = "CDWechseler"; + this.cdWechseler=new CDWechseler(); + this.cdWechseler.activate(); }else this.activeSource="CDDrive"; return activeSource; } - public void loadCDWechseler(ListcdList){ + public void loadCDWechseler(CD cd){ if(cdWechseler==null||!cdWechseler.isRunning()){ throw new CDWechselerNotRunningException(); } + if(!(this.supportedFormats.contains(cd.getFormat()))){ + throw new FormatNotSupportedException(); + } } //Getters, Setters und SupportMethods diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index d159604..d093081 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -391,18 +391,27 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("loadCDWechselerData") - void loadCDWechselerTest(String testName,String cases, CDPlayer _cdPlayer,ListcdList,Exception exception) { - Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cdList)); - assertEquals(CDWechselerNotRunningException.class, newException.getClass()); + void loadCDWechselerTest(String testName,String cases, CDPlayer _cdPlayer,CD cd,Exception exception) { + if(cases.equals("Case1")) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd)); + assertEquals(CDWechselerNotRunningException.class, newException.getClass()); + } + if(cases.equals("Case2")) { + _cdPlayer.changePlaySource(); + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd)); + assertEquals(FormatNotSupportedException.class, newException.getClass()); + } } static Stream loadCDWechselerData () { CDPlayer cdPlayer1 = new CDPlayer(); + String[] videoPlayList=new String[]{"Video 01","Video 02","Video 03","Video 04","Video 05"}; String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; - CD audioCD1=new CD("Audio",audioPlayList); - ListCdList1=Arrays.asList(audioCD1); + CD audioCD1=new CD("Audio",audioPlayList); + CD DVD=new CD("DVD",videoPlayList); return Stream.of( - Arguments.of("[loadCDWechseler() by notRunning=CDWechseler ] => shouldThrowAnException", "Case1", cdPlayer1,CdList1,new CDWechselerNotRunningException()) + Arguments.of("[loadCDWechseler() by notRunning=CDWechseler ] => shouldThrowAnException", "Case1", cdPlayer1,audioCD1,new CDWechselerNotRunningException()), + Arguments.of("[loadCDWechseler() by WrongCDFormat ] => shouldThrowAnException", "Case2", cdPlayer1,DVD,new FormatNotSupportedException()) ); } From e6741fd092fecad0d9e5864e8af3d27ba7f571d8 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 15:31:27 +0100 Subject: [PATCH 24/46] Method loadCDWechseler of CDPlayer tested on leadingFirstCD -> CDListOfCDWechselerShouldHaveLength1. --- src/main/java/device/cdPlayer/CDPlayer.java | 6 ++++-- src/main/java/device/cdPlayer/CDWechseler.java | 9 ++++++++- src/test/java/device/cdPlayer/CDPlayerTest.java | 9 ++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index da243d6..7e78148 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -148,6 +148,7 @@ public class CDPlayer implements Device { if(!(this.supportedFormats.contains(cd.getFormat()))){ throw new FormatNotSupportedException(); } + cdWechseler.loadOneCD(cd); } //Getters, Setters und SupportMethods @@ -197,6 +198,7 @@ public class CDPlayer implements Device { return this.loadedCD; } - - + public CDWechseler getCdWechseler() { + return cdWechseler; + } } diff --git a/src/main/java/device/cdPlayer/CDWechseler.java b/src/main/java/device/cdPlayer/CDWechseler.java index 1f408b1..40caf90 100644 --- a/src/main/java/device/cdPlayer/CDWechseler.java +++ b/src/main/java/device/cdPlayer/CDWechseler.java @@ -1,9 +1,10 @@ package device.cdPlayer; +import java.util.ArrayList; import java.util.List; public class CDWechseler { - private ListCDList; + private ListCDList=new ArrayList<>(); private boolean running=false; @@ -15,5 +16,11 @@ public class CDWechseler { this.running = true; } + public List getCDList() { + return CDList; + } + public void loadOneCD(CD cd){ + CDList.add(cd); + } } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index d093081..81f79d6 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -401,6 +401,12 @@ class CDPlayerTest { Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd)); assertEquals(FormatNotSupportedException.class, newException.getClass()); } + if(cases.equals("Case3")) { + _cdPlayer.changePlaySource(); + _cdPlayer.loadCDWechseler(cd); + int length=_cdPlayer.getCdWechseler().getCDList().size(); + assertThat(length).describedAs(testName).isEqualTo(1); + } } static Stream loadCDWechselerData () { CDPlayer cdPlayer1 = new CDPlayer(); @@ -411,7 +417,8 @@ class CDPlayerTest { CD DVD=new CD("DVD",videoPlayList); return Stream.of( Arguments.of("[loadCDWechseler() by notRunning=CDWechseler ] => shouldThrowAnException", "Case1", cdPlayer1,audioCD1,new CDWechselerNotRunningException()), - Arguments.of("[loadCDWechseler() by WrongCDFormat ] => shouldThrowAnException", "Case2", cdPlayer1,DVD,new FormatNotSupportedException()) + Arguments.of("[loadCDWechseler() by WrongCDFormat ] => shouldThrowAnException", "Case2", cdPlayer1,DVD,new FormatNotSupportedException()), + Arguments.of("[loadCDWechseler() by leadingFirstCD ] => CDListOfCDWechselerShouldHaveLength1", "Case3", cdPlayer1,audioCD1,null) ); } From 7c7ae70a2b179b0cce12df32f2f06dd9664d16e4 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 16:13:17 +0100 Subject: [PATCH 25/46] Method loadCDWechseler of CDPlayer tested on MaxCapacityExceeded:Max=10 -> shouldThrowAnException. --- src/main/java/device/cdPlayer/CDPlayer.java | 8 ++++++-- src/main/java/device/cdPlayer/CDWechseler.java | 8 ++++---- .../MaxCapacityExceededException.java | 7 +++++++ .../java/device/cdPlayer/CDPlayerTest.java | 18 ++++++++++++------ 4 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 src/main/java/device/cdPlayer/exceptions/MaxCapacityExceededException.java diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 7e78148..a60009a 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -141,14 +141,18 @@ public class CDPlayer implements Device { return activeSource; } - public void loadCDWechseler(CD cd){ + public void loadCDWechseler(CD cd,int index){ if(cdWechseler==null||!cdWechseler.isRunning()){ throw new CDWechselerNotRunningException(); } if(!(this.supportedFormats.contains(cd.getFormat()))){ throw new FormatNotSupportedException(); } - cdWechseler.loadOneCD(cd); + if(index>10){ + throw new MaxCapacityExceededException(); + } + cdWechseler.loadOneCD(cd,index); + System.out.println(index); } //Getters, Setters und SupportMethods diff --git a/src/main/java/device/cdPlayer/CDWechseler.java b/src/main/java/device/cdPlayer/CDWechseler.java index 40caf90..0ae54e5 100644 --- a/src/main/java/device/cdPlayer/CDWechseler.java +++ b/src/main/java/device/cdPlayer/CDWechseler.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; public class CDWechseler { - private ListCDList=new ArrayList<>(); + private CD[]CDList=new CD[10]; private boolean running=false; @@ -16,11 +16,11 @@ public class CDWechseler { this.running = true; } - public List getCDList() { + public CD[] getCDList() { return CDList; } - public void loadOneCD(CD cd){ - CDList.add(cd); + public void loadOneCD(CD cd,int index){ + CDList[index]=cd; } } diff --git a/src/main/java/device/cdPlayer/exceptions/MaxCapacityExceededException.java b/src/main/java/device/cdPlayer/exceptions/MaxCapacityExceededException.java new file mode 100644 index 0000000..163b156 --- /dev/null +++ b/src/main/java/device/cdPlayer/exceptions/MaxCapacityExceededException.java @@ -0,0 +1,7 @@ +package device.cdPlayer.exceptions; + +public class MaxCapacityExceededException extends RuntimeException{ + public MaxCapacityExceededException(){ + super("Max capacity of 10-CDs is already exceeded."); + } +} diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 81f79d6..1eb3043 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -393,19 +393,24 @@ class CDPlayerTest { @MethodSource("loadCDWechselerData") void loadCDWechselerTest(String testName,String cases, CDPlayer _cdPlayer,CD cd,Exception exception) { if(cases.equals("Case1")) { - Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd)); + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd,0)); assertEquals(CDWechselerNotRunningException.class, newException.getClass()); } if(cases.equals("Case2")) { _cdPlayer.changePlaySource(); - Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd)); + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd,0)); assertEquals(FormatNotSupportedException.class, newException.getClass()); } if(cases.equals("Case3")) { _cdPlayer.changePlaySource(); - _cdPlayer.loadCDWechseler(cd); - int length=_cdPlayer.getCdWechseler().getCDList().size(); - assertThat(length).describedAs(testName).isEqualTo(1); + _cdPlayer.loadCDWechseler(cd,0); + CD firstCD=_cdPlayer.getCdWechseler().getCDList()[0]; + assertThat(firstCD).describedAs(testName).isNotEqualTo(null); + } + if(cases.equals("Case4")) { + _cdPlayer.changePlaySource(); + Exception newException=assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd, 12)); + assertEquals(MaxCapacityExceededException.class, newException.getClass()); } } static Stream loadCDWechselerData () { @@ -418,7 +423,8 @@ class CDPlayerTest { return Stream.of( Arguments.of("[loadCDWechseler() by notRunning=CDWechseler ] => shouldThrowAnException", "Case1", cdPlayer1,audioCD1,new CDWechselerNotRunningException()), Arguments.of("[loadCDWechseler() by WrongCDFormat ] => shouldThrowAnException", "Case2", cdPlayer1,DVD,new FormatNotSupportedException()), - Arguments.of("[loadCDWechseler() by leadingFirstCD ] => CDListOfCDWechselerShouldHaveLength1", "Case3", cdPlayer1,audioCD1,null) + Arguments.of("[loadCDWechseler() by leadingFirstCD ] => CDListOfCDWechselerShouldHaveLength1", "Case3", cdPlayer1,audioCD1,null), + Arguments.of("[loadCDWechseler() by MaxCapacityExceeded:Max=10 ] => shouldThrowAnException", "Case4", cdPlayer1,audioCD1,new MaxCapacityExceededException()) ); } From 3d0f3997f212333fc70adf6c30f83fbb4abd05d8 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 17:11:12 +0100 Subject: [PATCH 26/46] Method changeToNextCD of CDPlayer tested on CDWechselerNotSelected -> shouldThrowAnException. --- src/main/java/device/cdPlayer/CDPlayer.java | 6 ++++++ .../ChangeCDOnlyOnCDWechselerException.java | 7 +++++++ src/test/java/device/cdPlayer/CDPlayerTest.java | 15 +++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index a60009a..90a1f92 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -154,6 +154,12 @@ public class CDPlayer implements Device { cdWechseler.loadOneCD(cd,index); System.out.println(index); } + public void changeToNextCD(){ + if(activeSource.equals("CDDrive")){ + throw new ChangeCDOnlyOnCDWechselerException(); + } + + } //Getters, Setters und SupportMethods public void setCD(CD _loadedCD) { diff --git a/src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java b/src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java new file mode 100644 index 0000000..ab81555 --- /dev/null +++ b/src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java @@ -0,0 +1,7 @@ +package device.cdPlayer.exceptions; + +public class ChangeCDOnlyOnCDWechselerException extends RuntimeException{ + public ChangeCDOnlyOnCDWechselerException(){ + super("Change to next CD olny when CDWechseler is selected"); + } +} diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 1eb3043..add6d31 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -428,5 +428,20 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("changeToNextCDData") + void changeToNextCDTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.changeToNextCD()); + assertEquals(ChangeCDOnlyOnCDWechselerException.class, newException.getClass()); + } + static Stream changeToNextCDData () { + CDPlayer cdPlayer1 = new CDPlayer(); + + return Stream.of( + Arguments.of("[changeToNextCD() by CDWechselerNotSelected ] => shouldThrowAnException", "Case1", cdPlayer1,new ChangeCDOnlyOnCDWechselerException()) + ); + } + + } \ No newline at end of file From f77ed10d417d734210ef49e234b5e5dfa405bb17 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 17:41:24 +0100 Subject: [PATCH 27/46] Method changeToNextCD of CDPlayer tested checking the effect -> loadedCDShouldNotReturnNull. --- src/main/java/device/cdPlayer/CDPlayer.java | 2 +- .../java/device/cdPlayer/CDPlayerTest.java | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 90a1f92..724c2b4 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -158,7 +158,7 @@ public class CDPlayer implements Device { if(activeSource.equals("CDDrive")){ throw new ChangeCDOnlyOnCDWechselerException(); } - + this.loadedCD=cdWechseler.getCDList()[1]; } //Getters, Setters und SupportMethods diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index add6d31..20cbc8d 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -431,14 +431,31 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("changeToNextCDData") void changeToNextCDTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception) { + if(cases.equals("Case1")) { Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.changeToNextCD()); assertEquals(ChangeCDOnlyOnCDWechselerException.class, newException.getClass()); + } + if(cases.equals("Case2")) { + CD actualCD=_cdPlayer.getCD(); + _cdPlayer.changeToNextCD(); + CD nextCD=_cdPlayer.getCD(); + assertThat(nextCD).describedAs(testName).isNotEqualTo(null); + } } static Stream changeToNextCDData () { CDPlayer cdPlayer1 = new CDPlayer(); + CDPlayer cdPlayer2 = new CDPlayer(); + cdPlayer2.changePlaySource(); + + String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; + CD audioCD1=new CD("Audio",audioPlayList); + cdPlayer2.loadCDWechseler(audioCD1,0); + cdPlayer2.loadCDWechseler(audioCD1,1); + return Stream.of( - Arguments.of("[changeToNextCD() by CDWechselerNotSelected ] => shouldThrowAnException", "Case1", cdPlayer1,new ChangeCDOnlyOnCDWechselerException()) + Arguments.of("[changeToNextCD() by CDWechselerNotSelected ] => shouldThrowAnException", "Case1", cdPlayer1,new ChangeCDOnlyOnCDWechselerException()), + Arguments.of("[changeToNextCD() checking the effect ] => loadedCDShouldNotReturnNull", "Case2", cdPlayer2,null) ); } From 5c1b1bd8a2dc375b236154b5d673134314c214da Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 17:57:06 +0100 Subject: [PATCH 28/46] added BordComputer & BordComputerTest added first test for readConfig & productive code --- src/main/java/BordComputer.java | 19 +++++++++++++ src/test/java/BordComputerTest.java | 41 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/main/java/BordComputer.java create mode 100644 src/test/java/BordComputerTest.java diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java new file mode 100644 index 0000000..3b01ee2 --- /dev/null +++ b/src/main/java/BordComputer.java @@ -0,0 +1,19 @@ +import java.io.FileReader; +import java.util.Properties; + +public class BordComputer { + + String[] deviceNames; + + public void readConfig() { + + try (FileReader reader = new FileReader("Geraete.config")) { + Properties properties = new Properties(); + properties.load(reader); + String[] values = properties.values().toArray(new String[0]); + deviceNames = new String[values.length]; + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java new file mode 100644 index 0000000..2659039 --- /dev/null +++ b/src/test/java/BordComputerTest.java @@ -0,0 +1,41 @@ +import device.radioPlayer.RadioPlayer; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +class BordComputerTest { + + @ParameterizedTest + @MethodSource("readConfigOptions") + void readConfigTest(String testName, String testTyp, BordComputer testBc) { + if (testTyp.equals("count")) { + int count = 0; + try (FileReader reader = new FileReader("Geraete.config")) { + Properties properties = new Properties(); + properties.load(reader); + count = properties.size(); + } catch (IOException e) { + e.printStackTrace(); + } + assertThat(count).describedAs(testName).isEqualTo(testBc.deviceNames.length); + } + } + + static Stream readConfigOptions() { + BordComputer bc1 = new BordComputer(); + bc1.readConfig(); + + return Stream.of( + Arguments.of("Check if file reader is getting every item in Geraete.config", "count", bc1) + ); + } + +} \ No newline at end of file From 0fd42ce65a7d3500c1529625353ac0ae3c72f0db Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 18:10:59 +0100 Subject: [PATCH 29/46] added second test for readConfig & productive code --- src/main/java/BordComputer.java | 1 + src/test/java/BordComputerTest.java | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index 3b01ee2..5b44487 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -12,6 +12,7 @@ public class BordComputer { properties.load(reader); String[] values = properties.values().toArray(new String[0]); deviceNames = new String[values.length]; + System.arraycopy(values, 0, deviceNames, 0, properties.size()); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 2659039..034584d 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -15,7 +15,7 @@ class BordComputerTest { @ParameterizedTest @MethodSource("readConfigOptions") - void readConfigTest(String testName, String testTyp, BordComputer testBc) { + void readConfigTest(String testName, String testTyp, BordComputer testBc, String expectedResult) { if (testTyp.equals("count")) { int count = 0; try (FileReader reader = new FileReader("Geraete.config")) { @@ -27,6 +27,9 @@ class BordComputerTest { } assertThat(count).describedAs(testName).isEqualTo(testBc.deviceNames.length); } + if (testTyp.equals("item1")) { + assertThat(testBc.deviceNames[0]).describedAs(testName).isEqualTo(expectedResult); + } } static Stream readConfigOptions() { @@ -34,7 +37,8 @@ class BordComputerTest { bc1.readConfig(); return Stream.of( - Arguments.of("Check if file reader is getting every item in Geraete.config", "count", bc1) + Arguments.of("Check if file reader is getting every item in Geraete.config", "count", bc1, ""), + Arguments.of("Check if file reader is getting the first element", "item1", bc1, "device.cdPlayer.CdPlayer") ); } From b6a718f728bf18ae29019f809fe35852c7a1acc5 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 18:28:22 +0100 Subject: [PATCH 30/46] added third & fourth test for readConfig & productive code --- src/main/java/BordComputer.java | 2 ++ src/test/java/BordComputerTest.java | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index 5b44487..e0af6dc 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -1,4 +1,5 @@ import java.io.FileReader; +import java.util.Arrays; import java.util.Properties; public class BordComputer { @@ -11,6 +12,7 @@ public class BordComputer { Properties properties = new Properties(); properties.load(reader); String[] values = properties.values().toArray(new String[0]); + Arrays.sort(values); deviceNames = new String[values.length]; System.arraycopy(values, 0, deviceNames, 0, properties.size()); } catch (Exception e) { diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 034584d..3992b59 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -30,6 +30,12 @@ class BordComputerTest { if (testTyp.equals("item1")) { assertThat(testBc.deviceNames[0]).describedAs(testName).isEqualTo(expectedResult); } + if (testTyp.equals("item2")) { + assertThat(testBc.deviceNames[1]).describedAs(testName).isEqualTo(expectedResult); + } + if (testTyp.equals("item3")) { + assertThat(testBc.deviceNames[2]).describedAs(testName).isEqualTo(expectedResult); + } } static Stream readConfigOptions() { @@ -38,7 +44,9 @@ class BordComputerTest { return Stream.of( Arguments.of("Check if file reader is getting every item in Geraete.config", "count", bc1, ""), - Arguments.of("Check if file reader is getting the first element", "item1", bc1, "device.cdPlayer.CdPlayer") + Arguments.of("Check if file reader is getting the first element", "item1", bc1, "device.cdPlayer.CdPlayer"), + Arguments.of("Check if file reader is getting the second element", "item2", bc1, "device.radioPlayer.RadioPlayer"), + Arguments.of("Check if file reader is getting the third element", "item3", bc1, "device.usbPlayer.UsbPlayer") ); } From b3070125906cd0e55fb274c0abcd18678eb7aa79 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 18:57:02 +0100 Subject: [PATCH 31/46] Method changeToNextCD of CDPlayer tested checking the effect2 -> loadedCDShouldNotHaveTheSameIdAsPrev. --- src/main/java/device/cdPlayer/CD.java | 16 ++++++++++ src/main/java/device/cdPlayer/CDPlayer.java | 2 +- .../java/device/cdPlayer/CDPlayerTest.java | 29 +++++++++++++++---- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/main/java/device/cdPlayer/CD.java b/src/main/java/device/cdPlayer/CD.java index 4934ac2..ae8f7e8 100644 --- a/src/main/java/device/cdPlayer/CD.java +++ b/src/main/java/device/cdPlayer/CD.java @@ -4,6 +4,7 @@ public class CD { private String format; private String albumName; private String[] playList; + private String id; public CD() {} @@ -16,6 +17,13 @@ public class CD { this.playList = playList; } + public CD(String format, String albumName, String[] playList, String id) { + this.format = format; + this.albumName = albumName; + this.playList = playList; + this.id = id; + } + public String getFormat() { return format; } @@ -39,4 +47,12 @@ public class CD { public void setAlbumName(String albumName) { this.albumName = albumName; } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } } diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 724c2b4..ea05053 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -152,7 +152,7 @@ public class CDPlayer implements Device { throw new MaxCapacityExceededException(); } cdWechseler.loadOneCD(cd,index); - System.out.println(index); + this.loadedCD=cdWechseler.getCDList()[0]; } public void changeToNextCD(){ if(activeSource.equals("CDDrive")){ diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 20cbc8d..8bb6f90 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -441,21 +441,40 @@ class CDPlayerTest { CD nextCD=_cdPlayer.getCD(); assertThat(nextCD).describedAs(testName).isNotEqualTo(null); } + if(cases.equals("Case3")) { + CD actualCD=_cdPlayer.getCD(); + System.out.println("loadedCD_id:"+actualCD.getId()); + _cdPlayer.changeToNextCD(); + CD nextCD=_cdPlayer.getCD(); + System.out.println("nextCD_id:"+nextCD.getId()); + /*System.out.println("loadedCD_id:"+_cdPlayer.getCD().getId()); + System.out.println("actualCD_id:"+_cdPlayer.getCdWechseler().getCDList()[0].getId()); + System.out.println("nextCD_id:"+_cdPlayer.getCdWechseler().getCDList()[1].getId());*/ + //System.out.println("nextCD_id:"+nextCD.getId()); + assertThat(nextCD.getId()==actualCD.getId()).describedAs(testName).isNotEqualTo(true); + } } static Stream changeToNextCDData () { + String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; + CD audioCD1=new CD("Audio","PopMusic",audioPlayList,"XAc20044"); + CD audioCD2=new CD("Audio","RockMusic",audioPlayList,"BLXPP78"); + CDPlayer cdPlayer1 = new CDPlayer(); CDPlayer cdPlayer2 = new CDPlayer(); cdPlayer2.changePlaySource(); - - String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; - CD audioCD1=new CD("Audio",audioPlayList); cdPlayer2.loadCDWechseler(audioCD1,0); - cdPlayer2.loadCDWechseler(audioCD1,1); + cdPlayer2.loadCDWechseler(audioCD2,1); + + CDPlayer cdPlayer3 = new CDPlayer(); + cdPlayer3.changePlaySource(); + cdPlayer3.loadCDWechseler(audioCD1,0); + cdPlayer3.loadCDWechseler(audioCD2,1); return Stream.of( Arguments.of("[changeToNextCD() by CDWechselerNotSelected ] => shouldThrowAnException", "Case1", cdPlayer1,new ChangeCDOnlyOnCDWechselerException()), - Arguments.of("[changeToNextCD() checking the effect ] => loadedCDShouldNotReturnNull", "Case2", cdPlayer2,null) + Arguments.of("[changeToNextCD() checking the effect ] => loadedCDShouldNotReturnNull", "Case2", cdPlayer2,null), + Arguments.of("[changeToNextCD() checking the effect 2 ] => loadedCDShouldNotHaveTheSameIdAsPrev", "Case3", cdPlayer3,null) ); } From 9913b1755461ee46d2d19b83468d184f51d3c0a8 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 19:32:22 +0100 Subject: [PATCH 32/46] added fifth test case for readConfig() & productive code and added first test case for setDevices() & productive code --- Geraete.config | 2 +- src/main/java/BordComputer.java | 13 ++++++++ src/test/java/BordComputerTest.java | 46 ++++++++++++++++++++++------- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/Geraete.config b/Geraete.config index a98abfd..170bbd6 100644 --- a/Geraete.config +++ b/Geraete.config @@ -1,4 +1,4 @@ -CD=device.cdPlayer.CdPlayer +CD=device.cdPlayer.CDPlayer Radio=device.radioPlayer.RadioPlayer USB=device.usbPlayer.UsbPlayer diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index e0af6dc..dbf777c 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -1,10 +1,15 @@ +import device.Device; + import java.io.FileReader; +import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.Properties; public class BordComputer { String[] deviceNames; + Device[] installedDevices; + Device activeDevice = null; public void readConfig() { @@ -15,8 +20,16 @@ public class BordComputer { Arrays.sort(values); deviceNames = new String[values.length]; System.arraycopy(values, 0, deviceNames, 0, properties.size()); + installedDevices=new Device[values.length]; } catch (Exception e) { e.printStackTrace(); } + activeDevice =installedDevices[0]; + } + + public void setDevices() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ClassNotFoundException { + Class c; + c= Class.forName(deviceNames[0]); + installedDevices[0] = (Device) c.getConstructor().newInstance(); } } diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 3992b59..834a958 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -1,3 +1,4 @@ +import device.Device; import device.radioPlayer.RadioPlayer; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -5,6 +6,7 @@ import org.junit.jupiter.params.provider.MethodSource; import java.io.FileReader; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.util.Properties; import java.util.stream.Stream; @@ -17,15 +19,10 @@ class BordComputerTest { @MethodSource("readConfigOptions") void readConfigTest(String testName, String testTyp, BordComputer testBc, String expectedResult) { if (testTyp.equals("count")) { - int count = 0; - try (FileReader reader = new FileReader("Geraete.config")) { - Properties properties = new Properties(); - properties.load(reader); - count = properties.size(); - } catch (IOException e) { - e.printStackTrace(); - } - assertThat(count).describedAs(testName).isEqualTo(testBc.deviceNames.length); + assertThat(fileReaderCount()).describedAs(testName).isEqualTo(testBc.deviceNames.length); + } + if (testTyp.equals("count1")) { + assertThat(fileReaderCount()).describedAs(testName).isEqualTo(testBc.installedDevices.length); } if (testTyp.equals("item1")) { assertThat(testBc.deviceNames[0]).describedAs(testName).isEqualTo(expectedResult); @@ -44,10 +41,37 @@ class BordComputerTest { return Stream.of( Arguments.of("Check if file reader is getting every item in Geraete.config", "count", bc1, ""), - Arguments.of("Check if file reader is getting the first element", "item1", bc1, "device.cdPlayer.CdPlayer"), + Arguments.of("Check if file reader is getting the first element", "item1", bc1, "device.cdPlayer.CDPlayer"), Arguments.of("Check if file reader is getting the second element", "item2", bc1, "device.radioPlayer.RadioPlayer"), - Arguments.of("Check if file reader is getting the third element", "item3", bc1, "device.usbPlayer.UsbPlayer") + Arguments.of("Check if file reader is getting the third element", "item3", bc1, "device.usbPlayer.UsbPlayer"), + Arguments.of("Test if installed devices has the length", "count1", bc1, "") ); } + @ParameterizedTest + @MethodSource("setDevicesOptions") + void setDevicesTest(String testName, BordComputer testBc) { + Device dev = testBc.installedDevices[0]; + assertThat(dev).describedAs(testName).isNotEqualTo(null); + } + + static Stream setDevicesOptions() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + BordComputer bc = new BordComputer(); + bc.readConfig(); + bc.setDevices(); + return Stream.of( + Arguments.of("Test if installedDevices[0] is not null", bc) + + ); + } + public int fileReaderCount() { + int count = 0; + try (FileReader reader = new FileReader("Geraete.config")) { + Properties properties = new Properties(); + properties.load(reader); + count = properties.size(); + } catch (IOException e) { + e.printStackTrace(); + } return count; + } } \ No newline at end of file From 4bd3d5acd261a64d00699d9f8f0038cfe624a412 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 19:40:52 +0100 Subject: [PATCH 33/46] added second and third test case for setDevices() & productive code --- src/main/java/BordComputer.java | 6 ++++-- src/test/java/BordComputerTest.java | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index dbf777c..5f92057 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -29,7 +29,9 @@ public class BordComputer { public void setDevices() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ClassNotFoundException { Class c; - c= Class.forName(deviceNames[0]); - installedDevices[0] = (Device) c.getConstructor().newInstance(); + for(int i = 0;i < deviceNames.length; i++) { + c = Class.forName(deviceNames[i]); + installedDevices[i] = (Device) c.getConstructor().newInstance(); + } } } diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 834a958..8a38b9b 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -50,8 +50,11 @@ class BordComputerTest { @ParameterizedTest @MethodSource("setDevicesOptions") - void setDevicesTest(String testName, BordComputer testBc) { - Device dev = testBc.installedDevices[0]; + void setDevicesTest(String testName, BordComputer testBc, String testTyp) { + Device dev = null; + if(testTyp.equals("0")) dev = testBc.installedDevices[0]; + if(testTyp.equals("1")) dev = testBc.installedDevices[1]; + if(testTyp.equals("2")) dev = testBc.installedDevices[2]; assertThat(dev).describedAs(testName).isNotEqualTo(null); } @@ -60,8 +63,9 @@ class BordComputerTest { bc.readConfig(); bc.setDevices(); return Stream.of( - Arguments.of("Test if installedDevices[0] is not null", bc) - + Arguments.of("Test if installedDevices[0] is not null", bc, "0"), + Arguments.of("Test if installedDevices[1] is not null", bc, "1"), + Arguments.of("Test if installedDevices[2] is not null", bc, "2") ); } public int fileReaderCount() { From 2e2be94402cadfa3ff2ff9b2a80e2ac4825c823c Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 20:06:25 +0100 Subject: [PATCH 34/46] Method changeToNextCD of CDPlayer tested changing_from_last_to_first CD -> FirstCDShouldBeTaken. --- src/main/java/device/cdPlayer/CDPlayer.java | 8 +++-- .../java/device/cdPlayer/CDWechseler.java | 8 ++--- .../java/device/cdPlayer/CDPlayerTest.java | 29 ++++++++++++++----- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index ea05053..8d4a53b 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -152,13 +152,17 @@ public class CDPlayer implements Device { throw new MaxCapacityExceededException(); } cdWechseler.loadOneCD(cd,index); - this.loadedCD=cdWechseler.getCDList()[0]; + this.loadedCD=cdWechseler.getCDList().get(0); } public void changeToNextCD(){ if(activeSource.equals("CDDrive")){ throw new ChangeCDOnlyOnCDWechselerException(); } - this.loadedCD=cdWechseler.getCDList()[1]; + + List CDList = cdWechseler.getCDList(); + int indexOfLoadedCD=CDList.indexOf(loadedCD); + int nextIndex=(indexOfLoadedCD+1)%CDList.size(); + this.loadedCD=CDList.get(nextIndex); } //Getters, Setters und SupportMethods diff --git a/src/main/java/device/cdPlayer/CDWechseler.java b/src/main/java/device/cdPlayer/CDWechseler.java index 0ae54e5..fca17d6 100644 --- a/src/main/java/device/cdPlayer/CDWechseler.java +++ b/src/main/java/device/cdPlayer/CDWechseler.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; public class CDWechseler { - private CD[]CDList=new CD[10]; + private List CDList=new ArrayList<>(); private boolean running=false; @@ -16,11 +16,11 @@ public class CDWechseler { this.running = true; } - public CD[] getCDList() { + public List getCDList() { return CDList; } - public void loadOneCD(CD cd,int index){ - CDList[index]=cd; + public void loadOneCD(CD cd, int index){ + CDList.add(cd); } } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 8bb6f90..a3e3ebf 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -404,7 +404,7 @@ class CDPlayerTest { if(cases.equals("Case3")) { _cdPlayer.changePlaySource(); _cdPlayer.loadCDWechseler(cd,0); - CD firstCD=_cdPlayer.getCdWechseler().getCDList()[0]; + CD firstCD=_cdPlayer.getCdWechseler().getCDList().get(0); assertThat(firstCD).describedAs(testName).isNotEqualTo(null); } if(cases.equals("Case4")) { @@ -443,21 +443,24 @@ class CDPlayerTest { } if(cases.equals("Case3")) { CD actualCD=_cdPlayer.getCD(); - System.out.println("loadedCD_id:"+actualCD.getId()); _cdPlayer.changeToNextCD(); CD nextCD=_cdPlayer.getCD(); - System.out.println("nextCD_id:"+nextCD.getId()); - /*System.out.println("loadedCD_id:"+_cdPlayer.getCD().getId()); - System.out.println("actualCD_id:"+_cdPlayer.getCdWechseler().getCDList()[0].getId()); - System.out.println("nextCD_id:"+_cdPlayer.getCdWechseler().getCDList()[1].getId());*/ - //System.out.println("nextCD_id:"+nextCD.getId()); assertThat(nextCD.getId()==actualCD.getId()).describedAs(testName).isNotEqualTo(true); } + if(cases.equals("Case4")) { + CD actualCdBefore=_cdPlayer.getCD(); + for (int i = 0; i <3 ; i++) { + _cdPlayer.changeToNextCD(); + } + CD actualCdAfter=_cdPlayer.getCD(); + assertThat(actualCdBefore.getId()==actualCdAfter.getId()).describedAs(testName).isEqualTo(true); + } } static Stream changeToNextCDData () { String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; CD audioCD1=new CD("Audio","PopMusic",audioPlayList,"XAc20044"); CD audioCD2=new CD("Audio","RockMusic",audioPlayList,"BLXPP78"); + CD audioCD3=new CD("Audio","SalsaMusic",audioPlayList,"KKRP118"); CDPlayer cdPlayer1 = new CDPlayer(); @@ -465,16 +468,26 @@ class CDPlayerTest { cdPlayer2.changePlaySource(); cdPlayer2.loadCDWechseler(audioCD1,0); cdPlayer2.loadCDWechseler(audioCD2,1); + cdPlayer2.loadCDWechseler(audioCD3,2); + CDPlayer cdPlayer3 = new CDPlayer(); cdPlayer3.changePlaySource(); cdPlayer3.loadCDWechseler(audioCD1,0); cdPlayer3.loadCDWechseler(audioCD2,1); + cdPlayer3.loadCDWechseler(audioCD3,2); + + CDPlayer cdPlayer4 = new CDPlayer(); + cdPlayer4.changePlaySource(); + cdPlayer4.loadCDWechseler(audioCD1,0); + cdPlayer4.loadCDWechseler(audioCD2,1); + cdPlayer4.loadCDWechseler(audioCD3,2); return Stream.of( Arguments.of("[changeToNextCD() by CDWechselerNotSelected ] => shouldThrowAnException", "Case1", cdPlayer1,new ChangeCDOnlyOnCDWechselerException()), Arguments.of("[changeToNextCD() checking the effect ] => loadedCDShouldNotReturnNull", "Case2", cdPlayer2,null), - Arguments.of("[changeToNextCD() checking the effect 2 ] => loadedCDShouldNotHaveTheSameIdAsPrev", "Case3", cdPlayer3,null) + Arguments.of("[changeToNextCD() checking the effect 2 ] => loadedCDShouldNotHaveTheSameIdAsPrev", "Case3", cdPlayer3,null), + Arguments.of("[3x changeToNextCD() changing from last to first CD] => FirstCDShouldBeTaken", "Case4", cdPlayer4,null) ); } From ab054d5dfe53df9290ccd26a825841ff2f353e41 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 20:11:30 +0100 Subject: [PATCH 35/46] revised all test for setDevices now testing if every installed devices has the right instance & added productive code --- src/main/java/BordComputer.java | 9 +++++---- src/test/java/BordComputerTest.java | 27 +++++++++++++++------------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/java/BordComputer.java b/src/main/java/BordComputer.java index 5f92057..7563899 100644 --- a/src/main/java/BordComputer.java +++ b/src/main/java/BordComputer.java @@ -11,7 +11,7 @@ public class BordComputer { Device[] installedDevices; Device activeDevice = null; - public void readConfig() { + public void readConfig() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { try (FileReader reader = new FileReader("Geraete.config")) { Properties properties = new Properties(); @@ -20,16 +20,17 @@ public class BordComputer { Arrays.sort(values); deviceNames = new String[values.length]; System.arraycopy(values, 0, deviceNames, 0, properties.size()); - installedDevices=new Device[values.length]; + installedDevices = new Device[values.length]; } catch (Exception e) { e.printStackTrace(); } - activeDevice =installedDevices[0]; + setDevices(); + activeDevice = installedDevices[0]; } public void setDevices() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ClassNotFoundException { Class c; - for(int i = 0;i < deviceNames.length; i++) { + for (int i = 0; i < deviceNames.length; i++) { c = Class.forName(deviceNames[i]); installedDevices[i] = (Device) c.getConstructor().newInstance(); } diff --git a/src/test/java/BordComputerTest.java b/src/test/java/BordComputerTest.java index 8a38b9b..6772d99 100644 --- a/src/test/java/BordComputerTest.java +++ b/src/test/java/BordComputerTest.java @@ -1,5 +1,7 @@ import device.Device; +import device.cdPlayer.CDPlayer; import device.radioPlayer.RadioPlayer; +import device.usbPlayer.UsbPlayer; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -35,7 +37,7 @@ class BordComputerTest { } } - static Stream readConfigOptions() { + static Stream readConfigOptions() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { BordComputer bc1 = new BordComputer(); bc1.readConfig(); @@ -50,24 +52,24 @@ class BordComputerTest { @ParameterizedTest @MethodSource("setDevicesOptions") - void setDevicesTest(String testName, BordComputer testBc, String testTyp) { - Device dev = null; - if(testTyp.equals("0")) dev = testBc.installedDevices[0]; - if(testTyp.equals("1")) dev = testBc.installedDevices[1]; - if(testTyp.equals("2")) dev = testBc.installedDevices[2]; - assertThat(dev).describedAs(testName).isNotEqualTo(null); + void setDevicesTest(String testName, BordComputer testBc, String testTyp, Boolean bool) { + Boolean boolActual = null; + if (testTyp.equals("0")) boolActual = (testBc.installedDevices[0] instanceof CDPlayer); + if (testTyp.equals("1")) boolActual = (testBc.installedDevices[1] instanceof RadioPlayer); + if (testTyp.equals("2")) boolActual = (testBc.installedDevices[2] instanceof UsbPlayer); + assertThat(boolActual).describedAs(testName).isEqualTo(bool); } static Stream setDevicesOptions() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { BordComputer bc = new BordComputer(); bc.readConfig(); - bc.setDevices(); return Stream.of( - Arguments.of("Test if installedDevices[0] is not null", bc, "0"), - Arguments.of("Test if installedDevices[1] is not null", bc, "1"), - Arguments.of("Test if installedDevices[2] is not null", bc, "2") + Arguments.of("Test if installedDevices[0] is instance of CDPlayer", bc, "0", true), + Arguments.of("Test if installedDevices[1] is instance of RadioPlayer", bc, "1", true), + Arguments.of("Test if installedDevices[2] is instance of UsbPlayer", bc, "2", true) ); } + public int fileReaderCount() { int count = 0; try (FileReader reader = new FileReader("Geraete.config")) { @@ -76,6 +78,7 @@ class BordComputerTest { count = properties.size(); } catch (IOException e) { e.printStackTrace(); - } return count; + } + return count; } } \ No newline at end of file From 15385d3b4c6d0d5ce3c74027b5901d880af92a5d Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 21:00:21 +0100 Subject: [PATCH 36/46] Method addToFavoriteSongs of CDPlayer tested on addingOneSong -> favoriteSongsShouldReturnsThatAddedSong. --- src/main/java/device/cdPlayer/CDPlayer.java | 9 ++++++++ .../java/device/cdPlayer/CDPlayerTest.java | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 8d4a53b..7742fcb 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -23,6 +23,8 @@ public class CDPlayer implements Device { private CDWechseler cdWechseler=null; private String activeSource="CDDrive";//or CDWechseler + private ListfavoriteSongs=new ArrayList<>(); + @Override public void louder() { if(volume < 100) { @@ -164,6 +166,9 @@ public class CDPlayer implements Device { int nextIndex=(indexOfLoadedCD+1)%CDList.size(); this.loadedCD=CDList.get(nextIndex); } + public void addToFavoriteSongs(String song){ + favoriteSongs.add(song); + } //Getters, Setters und SupportMethods public void setCD(CD _loadedCD) { @@ -215,4 +220,8 @@ public class CDPlayer implements Device { public CDWechseler getCdWechseler() { return cdWechseler; } + + public List getFavoriteSongs() { + return favoriteSongs; + } } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index a3e3ebf..2468c0c 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -491,6 +491,27 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("addToFavoriteSongsData") + void addToFavoriteSongs(String testName,String cases, CDPlayer _cdPlayer,Exception exception) { + String myFavoriteSong=_cdPlayer.getCD().getPlayList()[0]; + _cdPlayer.addToFavoriteSongs(myFavoriteSong); + assertThat(_cdPlayer.getFavoriteSongs().get(0)).describedAs(testName).isEqualTo(myFavoriteSong); + + } + static Stream addToFavoriteSongsData () { + String[] audioPlayList = new String[]{"Audio 01", "Audio 02", "Audio 03", "Audio 04", "Audio 05"}; + CD audioCD1 = new CD("Audio", "PopMusic", audioPlayList, "XAc20044"); + CD audioCD2=new CD("Audio","RockMusic",audioPlayList,"BLXPP78"); + CDPlayer cdPlayer1 = new CDPlayer(); + cdPlayer1.changePlaySource(); + cdPlayer1.loadCDWechseler(audioCD1, 0); + cdPlayer1.loadCDWechseler(audioCD2, 1); + + return Stream.of( + Arguments.of("[addToFavoriteSongs() by addingOneSong] => favoriteSongsShouldReturnsThatAddedSong", "Case1", cdPlayer1, null) + ); + } } \ No newline at end of file From 9e5960da8785a44239d489fa1b86a4f739423d8f Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 21:14:48 +0100 Subject: [PATCH 37/46] Method addToFavoriteSongs of CDPlayer tested on addingDuplicatedSong -> SongShouldNotBeAdded. --- src/main/java/device/cdPlayer/CDPlayer.java | 4 +++- .../java/device/cdPlayer/CDPlayerTest.java | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 7742fcb..b6ccdab 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -167,7 +167,9 @@ public class CDPlayer implements Device { this.loadedCD=CDList.get(nextIndex); } public void addToFavoriteSongs(String song){ - favoriteSongs.add(song); + if(!(favoriteSongs.contains(song))) { + favoriteSongs.add(song); + } } //Getters, Setters und SupportMethods diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 2468c0c..9f53724 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -494,10 +494,18 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("addToFavoriteSongsData") void addToFavoriteSongs(String testName,String cases, CDPlayer _cdPlayer,Exception exception) { - String myFavoriteSong=_cdPlayer.getCD().getPlayList()[0]; - _cdPlayer.addToFavoriteSongs(myFavoriteSong); - assertThat(_cdPlayer.getFavoriteSongs().get(0)).describedAs(testName).isEqualTo(myFavoriteSong); - + if(cases.equals("Case1")) { + String myFavoriteSong = _cdPlayer.getCD().getPlayList()[0]; + _cdPlayer.addToFavoriteSongs(myFavoriteSong); + assertThat(_cdPlayer.getFavoriteSongs().get(0)).describedAs(testName).isEqualTo(myFavoriteSong); + } + if(cases.equals("Case2")) { + String myFavoriteSong1 = _cdPlayer.getCD().getPlayList()[0]; + String myFavoriteSong2 = _cdPlayer.getCD().getPlayList()[0]; + _cdPlayer.addToFavoriteSongs(myFavoriteSong1); + _cdPlayer.addToFavoriteSongs(myFavoriteSong2); + assertThat(_cdPlayer.getFavoriteSongs().size()>1).describedAs(testName).isNotEqualTo(true); + } } static Stream addToFavoriteSongsData () { String[] audioPlayList = new String[]{"Audio 01", "Audio 02", "Audio 03", "Audio 04", "Audio 05"}; @@ -510,7 +518,8 @@ class CDPlayerTest { cdPlayer1.loadCDWechseler(audioCD2, 1); return Stream.of( - Arguments.of("[addToFavoriteSongs() by addingOneSong] => favoriteSongsShouldReturnsThatAddedSong", "Case1", cdPlayer1, null) + Arguments.of("[addToFavoriteSongs() by addingOneSong] => favoriteSongsShouldReturnsThatAddedSong", "Case1", cdPlayer1, null), + Arguments.of("[addToFavoriteSongs() by addingDuplicatedSong] => SongShouldNotBeAdded", "Case2", cdPlayer1, null) ); } From 067a5c3d70fb8706e80667a50cd73ba67ae1289d Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 21:31:27 +0100 Subject: [PATCH 38/46] Method addToFavoriteSongs of CDPlayer tested on NotSelectingCDWechseler -> shouldThrowAnException. --- src/main/java/device/cdPlayer/CDPlayer.java | 3 +++ src/test/java/device/cdPlayer/CDPlayerTest.java | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index b6ccdab..304d03d 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -167,6 +167,9 @@ public class CDPlayer implements Device { this.loadedCD=CDList.get(nextIndex); } public void addToFavoriteSongs(String song){ + if(activeSource.equals("CDDrive")){ + throw new CDWechselerNotRunningException(); + } if(!(favoriteSongs.contains(song))) { favoriteSongs.add(song); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 9f53724..c3cda36 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -506,6 +506,11 @@ class CDPlayerTest { _cdPlayer.addToFavoriteSongs(myFavoriteSong2); assertThat(_cdPlayer.getFavoriteSongs().size()>1).describedAs(testName).isNotEqualTo(true); } + if(cases.equals("Case3")) { + String myFavoriteSong1 = _cdPlayer.getCD().getPlayList()[0]; + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.addToFavoriteSongs(myFavoriteSong1)); + assertEquals(CDWechselerNotRunningException.class, newException.getClass()); + } } static Stream addToFavoriteSongsData () { String[] audioPlayList = new String[]{"Audio 01", "Audio 02", "Audio 03", "Audio 04", "Audio 05"}; @@ -517,9 +522,12 @@ class CDPlayerTest { cdPlayer1.loadCDWechseler(audioCD1, 0); cdPlayer1.loadCDWechseler(audioCD2, 1); + CDPlayer cdPlayer2 = new CDPlayer(); + cdPlayer2.setCD(audioCD2); return Stream.of( Arguments.of("[addToFavoriteSongs() by addingOneSong] => favoriteSongsShouldReturnsThatAddedSong", "Case1", cdPlayer1, null), - Arguments.of("[addToFavoriteSongs() by addingDuplicatedSong] => SongShouldNotBeAdded", "Case2", cdPlayer1, null) + Arguments.of("[addToFavoriteSongs() by addingDuplicatedSong] => SongShouldNotBeAdded", "Case2", cdPlayer1, null), + Arguments.of("[addToFavoriteSongs() by NotSelectingCDWechseler] => shouldThrowAnException", "Case3", cdPlayer2, new CDWechselerNotRunningException()) ); } From 3f1d220ac84f5b77a9d29983fce2aa97d9770b3d Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 21:45:43 +0100 Subject: [PATCH 39/46] Method mute of CDPlayer tested on checkingTheReturnValue -> ShouldReturnAString. --- src/main/java/device/cdPlayer/CDPlayer.java | 2 +- src/test/java/device/cdPlayer/CDPlayerTest.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 304d03d..e1da09f 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -109,7 +109,7 @@ public class CDPlayer implements Device { @Override public String mute() { - return null; + return ("Volume muted."); } @Override diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index c3cda36..354719a 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -493,7 +493,7 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("addToFavoriteSongsData") - void addToFavoriteSongs(String testName,String cases, CDPlayer _cdPlayer,Exception exception) { + void addToFavoriteSongsTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception) { if(cases.equals("Case1")) { String myFavoriteSong = _cdPlayer.getCD().getPlayList()[0]; _cdPlayer.addToFavoriteSongs(myFavoriteSong); @@ -531,4 +531,19 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("muteTestData") + void muteTest(String testName,String cases, CDPlayer _cdPlayer,String expectedResult) { + assertThat(_cdPlayer.mute()).describedAs(testName).isEqualTo(expectedResult); + } + static Stream muteTestData () { + CDPlayer cdPlayer1 = new CDPlayer(); + return Stream.of( + Arguments.of("[mute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume muted.") + ); + } + + + + } \ No newline at end of file From c0ed52776b4fcfdeb9a8f1b97c16d2a2d697678b Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 21:59:30 +0100 Subject: [PATCH 40/46] Method mute of CDPlayer tested on checkingTheEffectAfterRun -> VariableMutedShouldBeTrue. --- src/main/java/device/cdPlayer/CDPlayer.java | 7 +++++++ src/test/java/device/cdPlayer/CDPlayerTest.java | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index e1da09f..23714be 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -25,6 +25,8 @@ public class CDPlayer implements Device { private ListfavoriteSongs=new ArrayList<>(); + private boolean muted=false; + @Override public void louder() { if(volume < 100) { @@ -109,6 +111,7 @@ public class CDPlayer implements Device { @Override public String mute() { + muted=true; return ("Volume muted."); } @@ -229,4 +232,8 @@ public class CDPlayer implements Device { public List getFavoriteSongs() { return favoriteSongs; } + + public boolean isMuted() { + return muted; + } } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 354719a..1786fc8 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -534,12 +534,19 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("muteTestData") void muteTest(String testName,String cases, CDPlayer _cdPlayer,String expectedResult) { - assertThat(_cdPlayer.mute()).describedAs(testName).isEqualTo(expectedResult); + if(cases.equals("Case1")) { + assertThat(_cdPlayer.mute()).describedAs(testName).isEqualTo(expectedResult); + } + if(cases.equals("Case2")) { + _cdPlayer.mute(); + assertThat(_cdPlayer.isMuted()).describedAs(testName).isEqualTo(true); + } } static Stream muteTestData () { CDPlayer cdPlayer1 = new CDPlayer(); return Stream.of( - Arguments.of("[mute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume muted.") + Arguments.of("[mute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume muted."), + Arguments.of("[mute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeTrue", "Case2", cdPlayer1, "Volume muted.") ); } From aaee24a3c5e83849ba78366a01738a24334c0690 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:07:24 +0100 Subject: [PATCH 41/46] Method mute of CDPlayer tested after 2x louder() by checkingTheVolume -> VolumeShouldBeSetTo0. --- src/main/java/device/cdPlayer/CDPlayer.java | 1 + src/test/java/device/cdPlayer/CDPlayerTest.java | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 23714be..618bc1d 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -112,6 +112,7 @@ public class CDPlayer implements Device { @Override public String mute() { muted=true; + volume=0; return ("Volume muted."); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 1786fc8..2f4a4dc 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -541,12 +541,19 @@ class CDPlayerTest { _cdPlayer.mute(); assertThat(_cdPlayer.isMuted()).describedAs(testName).isEqualTo(true); } + if(cases.equals("Case3")) { + _cdPlayer.louder(); + _cdPlayer.louder(); + _cdPlayer.mute(); + assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(0); + } } static Stream muteTestData () { CDPlayer cdPlayer1 = new CDPlayer(); return Stream.of( Arguments.of("[mute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume muted."), - Arguments.of("[mute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeTrue", "Case2", cdPlayer1, "Volume muted.") + Arguments.of("[mute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeTrue", "Case2", cdPlayer1, "Volume muted."), + Arguments.of("[mute() after 2x louder() by checkingTheVolume] => VolumeShouldBeSetTo0", "Case3", cdPlayer1, "Volume muted.") ); } From 9d7abe2b431c29945b56c24daf5cfba0810917a8 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:14:40 +0100 Subject: [PATCH 42/46] Method mute of CDPlayer tested after 5x louder() by checkingTheSavedOldVolume -> getOldVolumeShouldReturns_5. --- src/main/java/device/cdPlayer/CDPlayer.java | 7 +++++++ src/test/java/device/cdPlayer/CDPlayerTest.java | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 618bc1d..09e52fa 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -26,6 +26,7 @@ public class CDPlayer implements Device { private ListfavoriteSongs=new ArrayList<>(); private boolean muted=false; + private int oldVolume=0; @Override public void louder() { @@ -112,6 +113,7 @@ public class CDPlayer implements Device { @Override public String mute() { muted=true; + oldVolume=volume; volume=0; return ("Volume muted."); } @@ -237,4 +239,9 @@ public class CDPlayer implements Device { public boolean isMuted() { return muted; } + + public int getOldVolume() { + return oldVolume; + } + } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 2f4a4dc..5975e17 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -547,13 +547,21 @@ class CDPlayerTest { _cdPlayer.mute(); assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(0); } + if(cases.equals("Case4")) { + for (int i = 0; i < 5; i++) { + _cdPlayer.louder(); + } + _cdPlayer.mute(); + assertThat(_cdPlayer.getOldVolume()).describedAs(testName).isEqualTo(5); + } } static Stream muteTestData () { CDPlayer cdPlayer1 = new CDPlayer(); return Stream.of( Arguments.of("[mute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume muted."), Arguments.of("[mute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeTrue", "Case2", cdPlayer1, "Volume muted."), - Arguments.of("[mute() after 2x louder() by checkingTheVolume] => VolumeShouldBeSetTo0", "Case3", cdPlayer1, "Volume muted.") + Arguments.of("[mute() after 2x louder() by checkingTheVolume] => VolumeShouldBeSetTo0", "Case3", cdPlayer1, "Volume muted."), + Arguments.of("[mute() after 5x louder() by checkingTheSavedOldVolume] => getOldVolumeShouldReturns_5", "Case4", cdPlayer1, "Volume muted.") ); } From 5b1c8e910161737a42e9707d8972c896eecba71c Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:23:18 +0100 Subject: [PATCH 43/46] Method mute of CDPlayer tested on checkingTheReturnValue -> ShouldReturnAString. --- src/main/java/device/cdPlayer/CDPlayer.java | 2 +- src/test/java/device/cdPlayer/CDPlayerTest.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 09e52fa..7ee9b81 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -120,7 +120,7 @@ public class CDPlayer implements Device { @Override public String unmute() { - return null; + return ("Volume unmute."); } @Override diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 5975e17..31353b1 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -565,7 +565,17 @@ class CDPlayerTest { ); } - + @ParameterizedTest + @MethodSource("unmuteTestData") + void unmuteTest(String testName,String cases, CDPlayer _cdPlayer,String expectedResult) { + assertThat(_cdPlayer.unmute()).describedAs(testName).isEqualTo(expectedResult); + } + static Stream unmuteTestData () { + CDPlayer cdPlayer1 = new CDPlayer(); + return Stream.of( + Arguments.of("[unmute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume unmute.") + ); + } } \ No newline at end of file From d26513380d5c8def25d11cca201739a601feda08 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:34:43 +0100 Subject: [PATCH 44/46] Method mute of CDPlayer tested on checkingTheEffectAfterRun -> VariableMutedShouldBeFalse. --- src/main/java/device/cdPlayer/CDPlayer.java | 1 + src/test/java/device/cdPlayer/CDPlayerTest.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 7ee9b81..c33f53f 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -120,6 +120,7 @@ public class CDPlayer implements Device { @Override public String unmute() { + muted=false; return ("Volume unmute."); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 31353b1..67fbafc 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -568,12 +568,20 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("unmuteTestData") void unmuteTest(String testName,String cases, CDPlayer _cdPlayer,String expectedResult) { - assertThat(_cdPlayer.unmute()).describedAs(testName).isEqualTo(expectedResult); + if(cases.equals("Case1")) { + assertThat(_cdPlayer.unmute()).describedAs(testName).isEqualTo(expectedResult); + } + if(cases.equals("Case2")) { + _cdPlayer.unmute(); + assertThat(_cdPlayer.isMuted()).describedAs(testName).isEqualTo(false); + } } static Stream unmuteTestData () { CDPlayer cdPlayer1 = new CDPlayer(); + cdPlayer1.mute(); return Stream.of( - Arguments.of("[unmute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume unmute.") + Arguments.of("[unmute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume unmute."), + Arguments.of("[unmute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeFalse", "Case2", cdPlayer1, "Volume unmute.") ); } From 9836e3a26c2d8bd2eccfe936c8e3c3c07024f2fb Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:44:06 +0100 Subject: [PATCH 45/46] Method mute of CDPlayer tested on 5x louder()-> mute() -> getVolumeShouldReturn_5. --- src/main/java/device/cdPlayer/CDPlayer.java | 1 + src/test/java/device/cdPlayer/CDPlayerTest.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index c33f53f..b08c602 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -121,6 +121,7 @@ public class CDPlayer implements Device { @Override public String unmute() { muted=false; + volume=oldVolume; return ("Volume unmute."); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 67fbafc..988a878 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -575,13 +575,22 @@ class CDPlayerTest { _cdPlayer.unmute(); assertThat(_cdPlayer.isMuted()).describedAs(testName).isEqualTo(false); } + if(cases.equals("Case3")) { + for (int i = 0; i < 5; i++) { + _cdPlayer.louder(); + } + _cdPlayer.mute(); + _cdPlayer.unmute(); + assertThat(_cdPlayer.isMuted()).describedAs(testName).isEqualTo(false); + assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(5); + } } static Stream unmuteTestData () { CDPlayer cdPlayer1 = new CDPlayer(); - cdPlayer1.mute(); return Stream.of( Arguments.of("[unmute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume unmute."), - Arguments.of("[unmute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeFalse", "Case2", cdPlayer1, "Volume unmute.") + Arguments.of("[unmute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeFalse", "Case2", cdPlayer1, "Volume unmute."), + Arguments.of("[unmute() by 5x louder()-> mute()] => getVolumeShouldReturn_5", "Case3", cdPlayer1, "Volume unmute.") ); } From 9c4084e47940870dd0b38e6ad15b0be0b2820bd3 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:49:18 +0100 Subject: [PATCH 46/46] Method mute of CDPlayer tested on 6x louder()-> mute() -> getOldVolumeShouldReturn_0. --- src/main/java/device/cdPlayer/CDPlayer.java | 1 + src/test/java/device/cdPlayer/CDPlayerTest.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index b08c602..ca99dfb 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -122,6 +122,7 @@ public class CDPlayer implements Device { public String unmute() { muted=false; volume=oldVolume; + oldVolume=0; return ("Volume unmute."); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 988a878..06cdff8 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -584,13 +584,23 @@ class CDPlayerTest { assertThat(_cdPlayer.isMuted()).describedAs(testName).isEqualTo(false); assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(5); } + if(cases.equals("Case4")) { + for (int i = 0; i < 6; i++) { + _cdPlayer.louder(); + } + _cdPlayer.mute(); + _cdPlayer.unmute(); + assertThat(_cdPlayer.isMuted()).describedAs(testName).isEqualTo(false); + assertThat(_cdPlayer.getOldVolume()).describedAs(testName).isEqualTo(0); + } } static Stream unmuteTestData () { CDPlayer cdPlayer1 = new CDPlayer(); return Stream.of( Arguments.of("[unmute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume unmute."), Arguments.of("[unmute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeFalse", "Case2", cdPlayer1, "Volume unmute."), - Arguments.of("[unmute() by 5x louder()-> mute()] => getVolumeShouldReturn_5", "Case3", cdPlayer1, "Volume unmute.") + Arguments.of("[unmute() by 5x louder()-> mute()] => getVolumeShouldReturn_5", "Case3", cdPlayer1, "Volume unmute."), + Arguments.of("[unmute() by 6x louder()-> mute()] => getOldVolumeShouldReturn_0", "Case4", cdPlayer1, "Volume unmute.") ); }