From c868d5256778629cae6b227bd06a5d6db8bf3225 Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 9 Feb 2022 18:45:19 +0100 Subject: [PATCH 1/2] NextTest in USB Class --- .../java/device/usbPlayer/UsbPlayerTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index bd85948..81711dc 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -86,4 +86,32 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) { ); } + + @ParameterizedTest + @MethodSource("NextOptions") + void NextTest(String testName, UsbPlayer inputPlay, String expectedResult) { + String current_Track = inputPlay.getPlayTrack(); + assertThat(current_Track).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream NextOptions() { + UsbPlayer up1 = new UsbPlayer(); + up1.next(); + UsbPlayer up2 = new UsbPlayer(); + for (int i = 0; i < up2.getPlaylist().size(); i++) { + up2.next(); + } + UsbPlayer up3 = new UsbPlayer(); + for (int i = 0; i < up3.getPlaylist().size(); i++) { + up3.next(); + } + up3.next(); + return Stream.of( + Arguments.of("Second-Song : Musik 02.mp3 ", up1, "Musik 02.mp3"), + Arguments.of("Last-Song : Musik 03.mp3 ", up2, "Musik 03.mp3"), + Arguments.of("From last to first Song : Musik 01.mp3 ", up2, "Musik 01.mp3") + + ); + } + } \ No newline at end of file From 7d66b2e47ad5a005bc446384abc2cd5aaae5e21b Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 9 Feb 2022 19:01:10 +0100 Subject: [PATCH 2/2] Next Production Code in USB Class implemented --- src/main/java/device/usbPlayer/UsbPlayer.java | 4 +++- src/test/java/device/usbPlayer/UsbPlayerTest.java | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 65a2be0..75f6a21 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -111,7 +111,9 @@ public class UsbPlayer implements Device { @Override public void next() { - + int currentIdex = Playlist.indexOf(playTrack); + int nextIndex = (currentIdex + 1) % Playlist.size(); + playTrack = Playlist.get(nextIndex); } @Override diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 81711dc..2d5e721 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -98,18 +98,18 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) { UsbPlayer up1 = new UsbPlayer(); up1.next(); UsbPlayer up2 = new UsbPlayer(); - for (int i = 0; i < up2.getPlaylist().size(); i++) { + for (int i = 1; i < up2.getPlaylist().size(); i++) { up2.next(); } UsbPlayer up3 = new UsbPlayer(); - for (int i = 0; i < up3.getPlaylist().size(); i++) { + for (int i = 1; i < up3.getPlaylist().size(); i++) { up3.next(); } up3.next(); return Stream.of( Arguments.of("Second-Song : Musik 02.mp3 ", up1, "Musik 02.mp3"), Arguments.of("Last-Song : Musik 03.mp3 ", up2, "Musik 03.mp3"), - Arguments.of("From last to first Song : Musik 01.mp3 ", up2, "Musik 01.mp3") + Arguments.of("From last to first Song : Musik 01.mp3 ", up3, "Musik 01.mp3") ); }