From 9ca661545f3a4f205a17dd9effaec37af2fae074 Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 9 Feb 2022 19:21:16 +0100 Subject: [PATCH 1/3] PrevTest in UsbPlayerTest.java --- .../java/device/usbPlayer/UsbPlayerTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 2d5e721..0fdc110 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -114,4 +114,21 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) { ); } + //////////////// + @ParameterizedTest + @MethodSource("PrevOptions") + void PrevTest(String testName, UsbPlayer inputPlay, String expectedResult) { + String current_Track = inputPlay.getPlayTrack(); + assertThat(current_Track).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream PrevOptions() { + UsbPlayer up1 = new UsbPlayer(); + up1.prev(); + + return Stream.of( + Arguments.of("From first-Song to last-Song : Musik 03.mp3 ", up1, "Musik 03.mp3") + ); + } + } \ No newline at end of file From ebd9395495a3b7cf4424c392a4573aab04b00f51 Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 9 Feb 2022 19:23:28 +0100 Subject: [PATCH 2/3] Production Code of UsbPlayer.prev() implemented --- src/main/java/device/usbPlayer/UsbPlayer.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 75f6a21..0a6e75d 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -118,7 +118,12 @@ public class UsbPlayer implements Device { @Override public void prev() { - + int currentIdex = Playlist.indexOf(playTrack); + int nextIndex = Playlist.size() - 1; + if (currentIdex != 0) { + nextIndex = (currentIdex - 1); + } + playTrack = Playlist.get(nextIndex); } @Override From 77768e5230a252ffb2657e59465d5df7cded6c61 Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 9 Feb 2022 20:00:05 +0100 Subject: [PATCH 3/3] UsbPlayerTest.PrevTest implemented --- src/test/java/device/usbPlayer/UsbPlayerTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 0fdc110..70c0f7a 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -125,9 +125,15 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) { static Stream PrevOptions() { UsbPlayer up1 = new UsbPlayer(); up1.prev(); + UsbPlayer up2 = new UsbPlayer(); + for (int i = 1; i < up2.getPlaylist().size(); i++) {//3 + up2.prev(); + } + return Stream.of( - Arguments.of("From first-Song to last-Song : Musik 03.mp3 ", up1, "Musik 03.mp3") + Arguments.of("From first-Song to last-Song : Musik 03.mp3 ", up1, "Musik 03.mp3"), + Arguments.of("From first-Song to second-Song(Backward) : Musik 02.mp3 ", up2, "Musik 02.mp3") ); }