diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 31a5394..aec782d 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -387,7 +387,7 @@ class UsbPlayerTest { @MethodSource("GoToFirstOptions") void GoToFirstTest(String testName, UsbPlayer inputUSB, String expectedResult) { String firstSong = inputUSB.getPlayTrack(); - assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult); + assertThat(firstSong).describedAs(testName).isEqualTo(expectedResult); } static Stream GoToFirstOptions() { @@ -404,9 +404,9 @@ class UsbPlayerTest { up3.GoToFirst(); return Stream.of( - Arguments.of("It should go to the first Song ", up1,up1.getPlaylist().get(0)), - Arguments.of("Call the function twice and it stills go to the first Song ", up2,up2.getPlaylist().get(0)), - Arguments.of("go to the next Song then back to first Song ", up3,up3.getPlaylist().get(0)) + Arguments.of("It should go to the first Song ", up1, up1.getPlaylist().get(0)), + Arguments.of("Call the function twice and it stills go to the first Song ", up2, up2.getPlaylist().get(0)), + Arguments.of("go to the next Song then back to first Song ", up3, up3.getPlaylist().get(0)) ); } @@ -414,7 +414,7 @@ class UsbPlayerTest { @MethodSource("GoToLastOptions") void GoToLastTest(String testName, UsbPlayer inputUSB, String expectedResult) { String firstSong = inputUSB.getPlayTrack(); - assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult); + assertThat(firstSong).describedAs(testName).isEqualTo(expectedResult); } static Stream GoToLastOptions() { @@ -433,9 +433,9 @@ class UsbPlayerTest { return Stream.of( - Arguments.of("It should go to the Last Song ", up1,up1.getPlaylist().get(up1.getPlaylist().size()-1)), - Arguments.of("It should go to the Last Song even after calling the function twice ", up2,up2.getPlaylist().get(up2.getPlaylist().size()-1)), - Arguments.of("It should go to the Last Song even changing the current song ", up3,up3.getPlaylist().get(up3.getPlaylist().size()-1)) + Arguments.of("It should go to the Last Song ", up1, up1.getPlaylist().get(up1.getPlaylist().size() - 1)), + Arguments.of("It should go to the Last Song even after calling the function twice ", up2, up2.getPlaylist().get(up2.getPlaylist().size() - 1)), + Arguments.of("It should go to the Last Song even changing the current song ", up3, up3.getPlaylist().get(up3.getPlaylist().size() - 1)) ); } @@ -443,7 +443,7 @@ class UsbPlayerTest { @MethodSource("setPlayTrackOptions") void setPlayTrackTest(String testName, UsbPlayer inputUSB, String expectedResult) { String firstSong = inputUSB.getPlayTrack(); - assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult); + assertThat(firstSong).describedAs(testName).isEqualTo(expectedResult); } static Stream setPlayTrackOptions() { @@ -461,9 +461,9 @@ class UsbPlayerTest { up3.setPlayTrack("Musik 04.mp3"); return Stream.of( - Arguments.of("It should change the current Song ", up1,"Musik 02.mp3"), - Arguments.of("It should change the current Song if it is in the Albume", up2,"Musik 02.mp3"), - Arguments.of("Tried to change the Song,but the Song name does not exist in the Album(No change)", up3,"Musik 01.mp3") + Arguments.of("It should change the current Song ", up1, "Musik 02.mp3"), + Arguments.of("It should change the current Song if it is in the Albume", up2, "Musik 02.mp3"), + Arguments.of("Tried to change the Song,but the Song name does not exist in the Album(No change)", up3, "Musik 01.mp3") ); }//// @@ -471,7 +471,7 @@ class UsbPlayerTest { @MethodSource("getInfoTextOptions") void getInfoTextTest(String testName, UsbPlayer inputUSB, String expectedResult) { String infotxt = inputUSB.getInfoText(); - assertThat(infotxt ).describedAs(testName).isEqualTo(expectedResult); + assertThat(infotxt).describedAs(testName).isEqualTo(expectedResult); } static Stream getInfoTextOptions() { @@ -489,14 +489,14 @@ class UsbPlayerTest { UsbPlayer up2 = new UsbPlayer(USBwithTXT); return Stream.of( - Arguments.of("USB Player with Albums ", up1,"USB Player is on : "+up1.getPlayTrack()), - Arguments.of("USB Player with no Albums ", up2,"USB Player with no Albums") + Arguments.of("USB Player with Albums ", up1, "USB Player is on : " + up1.getPlayTrack()), + Arguments.of("USB Player with no Albums ", up2, "USB Player with no Albums") ); }//"muted" @ParameterizedTest @MethodSource("muteOptions") - void muteTest(String testName, UsbPlayer inputUSB, String expectedResult,String testName2,String testName3) { + void muteTest(String testName, UsbPlayer inputUSB, String expectedResult, String testName2, String testName3) { int prevSound = inputUSB.getLautstaerke(); String isMuted = inputUSB.mute(); assertThat(isMuted).describedAs(testName).isEqualTo(expectedResult); @@ -514,14 +514,14 @@ class UsbPlayerTest { up1.mute(); return Stream.of( - Arguments.of("The Sound is muted ", up1,"muted","Sound level is 0","previous sound level is saved ") + Arguments.of("The Sound is muted ", up1, "muted", "Sound level is 0", "previous sound level is saved ") ); } @ParameterizedTest @MethodSource("unmuteOptions") - void unmuteTest(String testName, UsbPlayer inputUSB, String expectedResult,String testName2,String testName3) { + void unmuteTest(String testName, UsbPlayer inputUSB, String expectedResult, String testName2, String testName3) { int prevSound = inputUSB.getLautstaerke(); String unMuted = inputUSB.unmute(); int currentStatusofSoundWas = inputUSB.soundWas; @@ -540,7 +540,7 @@ class UsbPlayerTest { up1.unmute(); return Stream.of( - Arguments.of("The Sound is unmuted ", up1,"unmuted","Sound level has changed","previous sound level is 0") + Arguments.of("The Sound is unmuted ", up1, "unmuted", "Sound level has changed", "previous sound level is 0") ); } @@ -567,17 +567,24 @@ class UsbPlayerTest { void getItemListTest(String testName, UsbPlayer inputPlayer, String[] expectedResult) { String[] Pl = inputPlayer.getItemList(); - assertThat(Pl).contains("Musik 01.mp3","Musik 02.mp3","Musik 03.mp3").describedAs(testName); + if (Pl.length > 0) + assertThat(Pl).contains("Musik 01.mp3", "Musik 02.mp3", "Musik 03.mp3").describedAs(testName); + else assertThat(Pl).describedAs("No Album").isEmpty(); } static Stream getItemList() { USB_Stick USBDrive = new USB_Stick(); UsbPlayer up1 = new UsbPlayer(USBDrive); - String[] Pl = {"Musik 01.mp3","Musik 02.mp3","Musik 03.mp3"}; + String[] Pl = {"Musik 01.mp3", "Musik 02.mp3", "Musik 03.mp3"}; - return Stream.of( - Arguments.of("An Album was returned ", up1, Pl,1) + UsbPlayer up2 = new UsbPlayer(USBDrive); + ArrayList Pl1 = new ArrayList(); + up2.setPlaylist(Pl1); + String[] l = new String[3]; + return Stream.of( + Arguments.of("An Album was returned ", up1, Pl, 1), + Arguments.of("There is no Album to be returned ", up2, l, 2) ); }