Browse Source

UsbPlayerTest.findSongTest Second Case

feature-pr-USB-10Louder
sahar 2 years ago
parent
commit
40ff19f935
  1. 18
      src/main/java/device/usbPlayer/UsbPlayer.java
  2. 15
      src/test/java/device/usbPlayer/UsbPlayerTest.java

18
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;
}
}

15
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<Arguments> 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)
);
}

Loading…
Cancel
Save