From 9d20decf08819d7048f07e52cb418f03f36869a6 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 22:28:57 +0100 Subject: [PATCH] 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