From 0ff584dc0ae67ee01d0cb3c91fd07dfe6b2bd9bf Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Thu, 17 Feb 2022 00:05:33 +0100 Subject: [PATCH] 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