From 69cbbf90fad19bcbb1e4f42d70d61f3ed1cad647 Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 20:07:26 +0100 Subject: [PATCH] UsbPlayerTest.getInfoTextTest First Case --- src/main/java/device/usbPlayer/USB_Stick.java | 16 ++- src/main/java/device/usbPlayer/UsbPlayer.java | 11 +- .../java/device/usbPlayer/USB_StickTest.java | 3 +- .../java/device/usbPlayer/UsbPlayerTest.java | 119 +++++++++++------- 4 files changed, 99 insertions(+), 50 deletions(-) diff --git a/src/main/java/device/usbPlayer/USB_Stick.java b/src/main/java/device/usbPlayer/USB_Stick.java index cb15e82..4dd0fc6 100644 --- a/src/main/java/device/usbPlayer/USB_Stick.java +++ b/src/main/java/device/usbPlayer/USB_Stick.java @@ -39,14 +39,26 @@ public class USB_Stick { USB_Stick(String a){ + } + + USB_Stick(ArrayList a1) { + + Folders.add(a1); + currentAlbum = 0; + for (int i = 0; i < Folders.size(); i++) { + for (int j = 0; j < Folders.get(0).size(); j++) { + System.out.println("the song is "+Folders.get(0).get(j)+"\n"); + + } + + } + } public ArrayList getAlbum() throws NoFolderFound{ if(Folders.size()==0) { - System.out.println("list ist leer"); throw new NoFolderFound("The USB Drive is empty"); } else { - System.out.println("nicht leer"); return Folders.get(currentAlbum); } } diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index cb2523f..ded0469 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -61,7 +61,7 @@ public class UsbPlayer implements Device { } //*********constructure******** - public UsbPlayer() { + public UsbPlayer(USB_Stick stick) { super(); isDefect = false; isConnected = true; @@ -70,11 +70,13 @@ public class UsbPlayer implements Device { Playlist.add("Musik 03.mp3"); playTrack = Playlist.get(0);*/ try { - Playlist = USBDrive.getAlbum(); + Playlist = stick.getAlbum(); } catch (NoFolderFound e) { e.printStackTrace(); } - playTrack = Playlist.get(0); + if (isAllAudio()) { + playTrack = Playlist.get(0); + } } @@ -154,7 +156,8 @@ public class UsbPlayer implements Device { @Override public String getInfoText() { - return null; + + return "USB Player is on : "+this.getPlayTrack(); } @Override diff --git a/src/test/java/device/usbPlayer/USB_StickTest.java b/src/test/java/device/usbPlayer/USB_StickTest.java index 8d21050..5982ced 100644 --- a/src/test/java/device/usbPlayer/USB_StickTest.java +++ b/src/test/java/device/usbPlayer/USB_StickTest.java @@ -47,7 +47,6 @@ class USB_StickTest { ); } - //ChangeAlbum @ParameterizedTest @MethodSource("ChangeAlbumOptions") void ChangeAlbumTest(String testName, USB_Stick s) throws NoFolderFound { @@ -68,4 +67,6 @@ class USB_StickTest { ); } + + } \ No newline at end of file diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 6aea624..c44f026 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -11,7 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat; class UsbPlayerTest { - UsbPlayer up = new UsbPlayer(); + //UsbPlayer up = new UsbPlayer(); @ParameterizedTest @MethodSource("PlayOptions") @@ -21,21 +21,22 @@ class UsbPlayerTest { } static Stream PlayOptions() { - UsbPlayer up1 = new UsbPlayer(); - UsbPlayer up8 = new UsbPlayer(); + USB_Stick USBDrive = new USB_Stick(); + UsbPlayer up1 = new UsbPlayer(USBDrive); + UsbPlayer up8 = new UsbPlayer(USBDrive); up8.setPlayTrack(""); - UsbPlayer up2 = new UsbPlayer(); + UsbPlayer up2 = new UsbPlayer(USBDrive); ArrayList l = new ArrayList(); l.add("a.mp3"); l.add("b.mp3"); l.add("c.gif"); up2.setPlaylist(l); - UsbPlayer up3 = new UsbPlayer(); + UsbPlayer up3 = new UsbPlayer(USBDrive); ArrayList Pl = new ArrayList(); up3.setPlaylist(Pl); - UsbPlayer up6 = new UsbPlayer(); + UsbPlayer up6 = new UsbPlayer(USBDrive); up6.setDefect(true); - UsbPlayer up7 = new UsbPlayer(); + UsbPlayer up7 = new UsbPlayer(USBDrive); up7.setConnected(false); @@ -57,9 +58,10 @@ class UsbPlayerTest { } static Stream louderOptions() { - UsbPlayer up11 = new UsbPlayer(); + USB_Stick USBDrive = new USB_Stick(); + UsbPlayer up11 = new UsbPlayer(USBDrive); up11.louder(); - UsbPlayer up22 = new UsbPlayer(); + UsbPlayer up22 = new UsbPlayer(USBDrive); up22.setLautstaerke(100); up22.louder(); return Stream.of( @@ -76,9 +78,10 @@ class UsbPlayerTest { } static Stream quieterOptions() { - UsbPlayer up1 = new UsbPlayer(); + USB_Stick USBDrive = new USB_Stick(); + UsbPlayer up1 = new UsbPlayer(USBDrive); up1.quieter(); - UsbPlayer up2 = new UsbPlayer(); + UsbPlayer up2 = new UsbPlayer(USBDrive); up2.setLautstaerke(10); up2.quieter(); return Stream.of( @@ -96,13 +99,14 @@ class UsbPlayerTest { } static Stream NextOptions() { - UsbPlayer up1 = new UsbPlayer(); + USB_Stick USBDrive = new USB_Stick(); + UsbPlayer up1 = new UsbPlayer(USBDrive); up1.next(); - UsbPlayer up2 = new UsbPlayer(); + UsbPlayer up2 = new UsbPlayer(USBDrive); for (int i = 1; i < up2.getPlaylist().size(); i++) { up2.next(); } - UsbPlayer up3 = new UsbPlayer(); + UsbPlayer up3 = new UsbPlayer(USBDrive); for (int i = 1; i < up3.getPlaylist().size(); i++) { up3.next(); } @@ -123,9 +127,10 @@ class UsbPlayerTest { } static Stream PrevOptions() { - UsbPlayer up1 = new UsbPlayer(); + USB_Stick USBDrive = new USB_Stick(); + UsbPlayer up1 = new UsbPlayer(USBDrive); up1.prev(); - UsbPlayer up2 = new UsbPlayer(); + UsbPlayer up2 = new UsbPlayer(USBDrive); for (int i = 1; i < up2.getPlaylist().size(); i++) {//3 up2.prev(); } @@ -145,16 +150,17 @@ class UsbPlayerTest { } static Stream louder_10_Options() { - UsbPlayer up1 = new UsbPlayer(); + USB_Stick USBDrive = new USB_Stick(); + UsbPlayer up1 = new UsbPlayer(USBDrive); up1.Louder_10(); - UsbPlayer up2 = new UsbPlayer(); + UsbPlayer up2 = new UsbPlayer(USBDrive); for (int i = 0; i <= 3; i++) { up2.Louder_10(); } up2.quieter_10(); - UsbPlayer up3 = new UsbPlayer(); + UsbPlayer up3 = new UsbPlayer(USBDrive); up3.setLautstaerke(100); up3.Louder_10(); return Stream.of( @@ -172,17 +178,18 @@ class UsbPlayerTest { } static Stream quieter_10_Options() { - UsbPlayer up1 = new UsbPlayer(); + USB_Stick USBDrive = new USB_Stick(); + UsbPlayer up1 = new UsbPlayer(USBDrive); up1.setLautstaerke(10); up1.quieter_10(); - UsbPlayer up2 = new UsbPlayer(); + UsbPlayer up2 = new UsbPlayer(USBDrive); up2.setLautstaerke(50); for (int i = 0; i < 3; i++) { up2.quieter_10(); } - UsbPlayer up3 = new UsbPlayer(); + UsbPlayer up3 = new UsbPlayer(USBDrive); up3.quieter_10(); return Stream.of( @@ -205,7 +212,8 @@ class UsbPlayerTest { } static Stream FindSongOptions() { - UsbPlayer up1 = new UsbPlayer(); + USB_Stick USBDrive = new USB_Stick(); + UsbPlayer up1 = new UsbPlayer(USBDrive); return Stream.of( 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), @@ -222,16 +230,17 @@ class UsbPlayerTest { } static Stream GoToOptions() { - UsbPlayer up1 = new UsbPlayer(); + USB_Stick USBDrive = new USB_Stick(); + UsbPlayer up1 = new UsbPlayer(USBDrive); up1.GoTo("Musik 03.mp3"); - UsbPlayer up2 = new UsbPlayer(); + UsbPlayer up2 = new UsbPlayer(USBDrive); up2.GoTo("Musik 04.mp3"); - UsbPlayer up3 = new UsbPlayer(); + UsbPlayer up3 = new UsbPlayer(USBDrive); up3.GoTo("Musik 02"); - UsbPlayer up4 = new UsbPlayer(); + UsbPlayer up4 = new UsbPlayer(USBDrive); up4.next(); up4.GoTo("Musik"); @@ -252,45 +261,46 @@ class UsbPlayerTest { } static Stream isAllAudioOptions() { + USB_Stick USBDrive = new USB_Stick(); //mp3 - UsbPlayer up1 = new UsbPlayer(); + UsbPlayer up1 = new UsbPlayer(USBDrive); //mp4 - UsbPlayer up2 = new UsbPlayer(); + UsbPlayer up2 = new UsbPlayer(USBDrive); ArrayList Pl = new ArrayList(); Pl.add("Musik 01.mp4"); Pl.add("Musik 02.mp4"); Pl.add("Musik 03.mp4"); up2.setPlaylist(Pl); //m4a - UsbPlayer up3 = new UsbPlayer(); + UsbPlayer up3 = new UsbPlayer(USBDrive); ArrayList Pl1 = new ArrayList(); Pl1.add("Musik 01.m4a"); Pl1.add("Musik 02.m4a"); Pl1.add("Musik 03.m4a"); up3.setPlaylist(Pl1); //wav - UsbPlayer up4 = new UsbPlayer(); + UsbPlayer up4 = new UsbPlayer(USBDrive); ArrayList Pl2 = new ArrayList(); Pl2.add("Musik 01.wav"); Pl2.add("Musik 02.wav"); Pl2.add("Musik 03.wav"); up4.setPlaylist(Pl2); //wma - UsbPlayer up5 = new UsbPlayer(); + UsbPlayer up5 = new UsbPlayer(USBDrive); ArrayList Pl3 = new ArrayList(); Pl3.add("Musik 01.wma"); Pl3.add("Musik 02.wma"); Pl3.add("Musik 03.wma"); up5.setPlaylist(Pl3); //aac - UsbPlayer up6 = new UsbPlayer(); + UsbPlayer up6 = new UsbPlayer(USBDrive); ArrayList Pl4 = new ArrayList(); Pl4.add("Musik 01.aac"); Pl4.add("Musik 02.aac"); Pl4.add("Musik 03.aac"); up6.setPlaylist(Pl4); //mixed Audio and text Files in the Album - UsbPlayer up7 = new UsbPlayer(); + UsbPlayer up7 = new UsbPlayer(USBDrive); ArrayList Pl5 = new ArrayList(); Pl5.add("Musik 01.aac"); Pl5.add("Musik 02.txt"); @@ -318,14 +328,15 @@ class UsbPlayerTest { } static Stream GoToFirstOptions() { - UsbPlayer up1 = new UsbPlayer(); + USB_Stick USBDrive = new USB_Stick(); + UsbPlayer up1 = new UsbPlayer(USBDrive); up1.GoToFirst(); - UsbPlayer up2 = new UsbPlayer(); + UsbPlayer up2 = new UsbPlayer(USBDrive); up2.GoToFirst(); up2.GoToFirst(); - UsbPlayer up3 = new UsbPlayer(); + UsbPlayer up3 = new UsbPlayer(USBDrive); up3.next(); up3.GoToFirst(); @@ -344,15 +355,16 @@ class UsbPlayerTest { } static Stream GoToLastOptions() { + USB_Stick USBDrive = new USB_Stick(); //first case - UsbPlayer up1 = new UsbPlayer(); + UsbPlayer up1 = new UsbPlayer(USBDrive); up1.GoToLast(); - UsbPlayer up2 = new UsbPlayer(); + UsbPlayer up2 = new UsbPlayer(USBDrive); up2.GoToLast(); up2.GoToLast(); - UsbPlayer up3 = new UsbPlayer(); + UsbPlayer up3 = new UsbPlayer(USBDrive); up3.next(); up3.GoToLast(); @@ -372,16 +384,17 @@ class UsbPlayerTest { } static Stream setPlayTrackOptions() { + USB_Stick USBDrive = new USB_Stick(); //first case - UsbPlayer up1 = new UsbPlayer(); + UsbPlayer up1 = new UsbPlayer(USBDrive); up1.setPlayTrack("Musik 02.mp3"); //Second Case - UsbPlayer up2 = new UsbPlayer(); + UsbPlayer up2 = new UsbPlayer(USBDrive); up2.setPlayTrack("Musik 02.mp3"); //Third Case - UsbPlayer up3 = new UsbPlayer(); + UsbPlayer up3 = new UsbPlayer(USBDrive); up3.setPlayTrack("Musik 04.mp3"); return Stream.of( @@ -389,6 +402,26 @@ class UsbPlayerTest { 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") ); + }//// + + @ParameterizedTest + @MethodSource("getInfoTextOptions") + void getInfoTextTest(String testName, UsbPlayer inputUSB, String expectedResult) { + String infotxt = inputUSB.getInfoText(); + assertThat(infotxt ).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream getInfoTextOptions() { + USB_Stick USBDrive = new USB_Stick(); + //USB_Stick emptyUSB = new USB_Stick(""); + //first case + UsbPlayer up1 = new UsbPlayer(USBDrive); + + + + return Stream.of( + Arguments.of("USB Player with Albums ", up1,"USB Player is on : "+up1.getPlayTrack()) + ); } } \ No newline at end of file