From e5b9f46ce7b8c864340b39d4a0127c5e8df4ebe9 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 16 Feb 2022 17:53:53 +0100 Subject: [PATCH] added first test case for chooseItem() & and added productive code for RadioPlayer --- .../java/device/radioPlayer/RadioPlayer.java | 3 ++- .../device/radioPlayer/RadioPlayerTest.java | 21 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/device/radioPlayer/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java index 858cf13..5a79bc8 100644 --- a/src/main/java/device/radioPlayer/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -158,7 +158,8 @@ public class RadioPlayer implements Device { @Override public String chooseItem(int itemNr) { - return null; + playedStation = savedPlaylist.get(itemNr - 1); + return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"); } @Override diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 109e1d1..6de8fc1 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -171,11 +171,24 @@ class RadioPlayerTest { @Test void getOptions() { } - - @Test - void chooseOption() { - } */ + + @ParameterizedTest + @MethodSource("chooseItemOptions") + void testChooseItem(String testName, RadioPlayer testRp, String expectedResult) { + String playedStation = testRp.playedStation; + assertThat(playedStation).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream chooseItemOptions() { + RadioPlayer rp = new RadioPlayer(); + rp.chooseItem(2); + + return Stream.of( + Arguments.of("Test select station to play with nr isn`t bigger than playlist size", rp, "Teddy") + ); + } + @ParameterizedTest @MethodSource("testPlayOptions") void testPlay(String testName, RadioPlayer testRp, String expectedResult) {