From 40ff19f9351f2f079849add0994ee801cc4992f5 Mon Sep 17 00:00:00 2001 From: sahar Date: Sat, 12 Feb 2022 23:12:06 +0100 Subject: [PATCH] UsbPlayerTest.findSongTest Second Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 18 ++++++++++++++++-- .../java/device/usbPlayer/UsbPlayerTest.java | 15 ++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 4be2046..501c451 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -183,8 +183,22 @@ public class UsbPlayer implements Device { } - public int findSong(String song){ - return -1; + public int findSong(String songName){ + + int songIndex =-1, index=-1; + String song; + + for (int j = 0; j < getPlaylist().size(); j++) { + + song = getPlaylist().get(j); + songIndex=song.indexOf(songName); + + if (songIndex != -1) { + index = j; + break; + } + } + return index; } } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index c285d79..5d979d8 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -192,16 +192,21 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) { @ParameterizedTest @MethodSource("FindSongOptions") - void findSongTest(String testName, UsbPlayer inputPlay, int expectedResult) { - int songLocation = inputPlay.findSong("song 4"); - assertThat(songLocation).describedAs(testName).isEqualTo(expectedResult); + void findSongTest(String testName, int inputPlay, int expectedResult) { + //first case: the song is not in the Album + // int songLoc1 = inputPlay.findSong("song 4"); + assertThat(inputPlay).describedAs(testName).isEqualTo(expectedResult);//songLoc1 + //Second Case: the song is in the album + // int songLoc2 = inputPlay.findSong("Musik 02"); + assertThat(inputPlay).describedAs(testName).isEqualTo(expectedResult); + } static Stream FindSongOptions() { UsbPlayer up1 = new UsbPlayer(); - return Stream.of( - Arguments.of("The song is not in the Album", up1, -1) + Arguments.of("The song is not in the Album", up1.findSong("song 4"), -1), + Arguments.of("The song is in the Album", up1.findSong("Musik 02"), 1) ); }