From 69cbbf90fad19bcbb1e4f42d70d61f3ed1cad647 Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 20:07:26 +0100 Subject: [PATCH 01/24] 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 From 717120b9721469747be429ed8e5adbf81ca7d6e5 Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 20:31:48 +0100 Subject: [PATCH 02/24] UsbPlayerTest.getInfoTextTest Second Case --- src/main/java/device/usbPlayer/USB_Stick.java | 7 ------- src/main/java/device/usbPlayer/UsbPlayer.java | 9 +++++++-- src/test/java/device/usbPlayer/UsbPlayerTest.java | 11 +++++++++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/device/usbPlayer/USB_Stick.java b/src/main/java/device/usbPlayer/USB_Stick.java index 4dd0fc6..39817e9 100644 --- a/src/main/java/device/usbPlayer/USB_Stick.java +++ b/src/main/java/device/usbPlayer/USB_Stick.java @@ -45,13 +45,6 @@ public class USB_Stick { 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{ diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index ded0469..7e862b5 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -156,8 +156,13 @@ public class UsbPlayer implements Device { @Override public String getInfoText() { - - return "USB Player is on : "+this.getPlayTrack(); + String InfoText=""; + if (isAllAudio()) { + InfoText="USB Player is on : "+this.getPlayTrack(); + } + else + InfoText="USB Player with no Albums"; + return InfoText; } @Override diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index c44f026..92688cd 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -413,14 +413,21 @@ class UsbPlayerTest { static Stream getInfoTextOptions() { USB_Stick USBDrive = new USB_Stick(); + ArrayList Fileslist = new ArrayList(); + Fileslist.add("file 01.txt"); + Fileslist.add("file 02.txt"); + Fileslist.add("file 03.txt"); + USB_Stick USBwithTXT = new USB_Stick(Fileslist); //USB_Stick emptyUSB = new USB_Stick(""); //first case UsbPlayer up1 = new UsbPlayer(USBDrive); - + //Second case + 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 Albums ", up1,"USB Player is on : "+up1.getPlayTrack()), + Arguments.of("USB Player with no Albums ", up2,"USB Player with no Albums") ); } From 802a780a4eaaf01459b8656862b8c43ccc453302 Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 21:20:49 +0100 Subject: [PATCH 03/24] UsbPlayerTest.muteTest Second Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 8 ++++-- .../java/device/usbPlayer/UsbPlayerTest.java | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 7e862b5..0b7a255 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -12,6 +12,8 @@ public class UsbPlayer implements Device { private Boolean isConnected; private Boolean isDefect; int Lautstaerke = 0; + int soundWas ; + public USB_Stick USBDrive = new USB_Stick(); public ArrayList getPlaylist() { @@ -134,7 +136,7 @@ public class UsbPlayer implements Device { @Override public int getVolume() { - return 0; + return Lautstaerke; } @Override @@ -182,7 +184,9 @@ public class UsbPlayer implements Device { @Override public String mute() { - return null; + + setLautstaerke(0); + return "muted"; } @Override diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 92688cd..3663731 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -429,6 +429,31 @@ class UsbPlayerTest { 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 isMuted = inputUSB.mute(); + assertThat(isMuted).describedAs(testName).isEqualTo(expectedResult); + //Second case + assertThat(inputUSB.getLautstaerke()).describedAs(testName2).isEqualTo(0); + + } + + static Stream muteOptions() { + USB_Stick USBDrive = new USB_Stick(); + + //first case + UsbPlayer up1 = new UsbPlayer(USBDrive); + up1.mute(); + + + return Stream.of( + Arguments.of("The Sound is muted ", up1,"muted","Sound level is 0") + + ); } } \ No newline at end of file From 20727f6e6055f22ca8a45b3ecf61c8f52a292585 Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 21:28:10 +0100 Subject: [PATCH 04/24] UsbPlayerTest.muteTest third Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 2 +- src/test/java/device/usbPlayer/UsbPlayerTest.java | 8 +++++--- 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 0b7a255..1ad1b54 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -184,7 +184,7 @@ public class UsbPlayer implements Device { @Override public String mute() { - + this.soundWas = getLautstaerke(); setLautstaerke(0); return "muted"; } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 3663731..0bf968e 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -433,12 +433,14 @@ class UsbPlayerTest { @ParameterizedTest @MethodSource("muteOptions") - void muteTest(String testName, UsbPlayer inputUSB, String expectedResult,String testName2) { - + 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); //Second case assertThat(inputUSB.getLautstaerke()).describedAs(testName2).isEqualTo(0); + //third case + assertThat(inputUSB.soundWas).describedAs(testName3).isEqualTo(prevSound); } @@ -451,7 +453,7 @@ class UsbPlayerTest { return Stream.of( - Arguments.of("The Sound is muted ", up1,"muted","Sound level is 0") + Arguments.of("The Sound is muted ", up1,"muted","Sound level is 0","previous sound level is saved ") ); } From 947a842f6decd04794269d8a7c19dd2a7df0eddc Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 21:36:52 +0100 Subject: [PATCH 05/24] UsbPlayerTest.unmuteTest first Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 3 ++- .../java/device/usbPlayer/UsbPlayerTest.java | 24 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 1ad1b54..d0a7278 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -191,7 +191,8 @@ public class UsbPlayer implements Device { @Override public String unmute() { - return null; + + return "unmuted"; } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 0bf968e..acba644 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -447,15 +447,35 @@ class UsbPlayerTest { static Stream muteOptions() { USB_Stick USBDrive = new USB_Stick(); - //first case UsbPlayer up1 = new UsbPlayer(USBDrive); up1.mute(); - return Stream.of( 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 unMuted = inputUSB.unmute(); + //first case + assertThat(unMuted).describedAs(testName).isEqualTo(expectedResult); + + } + + static Stream unmuteOptions() { + USB_Stick USBDrive = new USB_Stick(); + + UsbPlayer up1 = new UsbPlayer(USBDrive); + up1.unmute(); + + return Stream.of( + Arguments.of("The Sound is unmuted ", up1,"unmuted") + + ); + } + } \ No newline at end of file From a7c3ea8610529afc0f5548b0670346341180257a Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 21:43:26 +0100 Subject: [PATCH 06/24] UsbPlayerTest.unmuteTest second Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 1 + src/test/java/device/usbPlayer/UsbPlayerTest.java | 9 +++++---- 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 d0a7278..1ad4b8d 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -192,6 +192,7 @@ public class UsbPlayer implements Device { @Override public String unmute() { + setLautstaerke(soundWas); return "unmuted"; } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index acba644..7041eb1 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -458,22 +458,23 @@ class UsbPlayerTest { @ParameterizedTest @MethodSource("unmuteOptions") - void unmuteTest(String testName, UsbPlayer inputUSB, String expectedResult) { - + void unmuteTest(String testName, UsbPlayer inputUSB, String expectedResult,String testName2) { + int prevSound = inputUSB.getLautstaerke(); String unMuted = inputUSB.unmute(); //first case assertThat(unMuted).describedAs(testName).isEqualTo(expectedResult); + //Second case + assertThat(inputUSB.getLautstaerke()).describedAs(testName2).isEqualTo(prevSound); } static Stream unmuteOptions() { USB_Stick USBDrive = new USB_Stick(); - UsbPlayer up1 = new UsbPlayer(USBDrive); up1.unmute(); return Stream.of( - Arguments.of("The Sound is unmuted ", up1,"unmuted") + Arguments.of("The Sound is unmuted ", up1,"unmuted","Sound level has changed") ); } From 83d3c8e4c05c06e93b4c0d63a1016090645f5b7d Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 21:47:00 +0100 Subject: [PATCH 07/24] UsbPlayerTest.unmuteTest third Case --- src/test/java/device/usbPlayer/UsbPlayerTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 7041eb1..f15d636 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -458,13 +458,16 @@ class UsbPlayerTest { @ParameterizedTest @MethodSource("unmuteOptions") - void unmuteTest(String testName, UsbPlayer inputUSB, String expectedResult,String testName2) { + void unmuteTest(String testName, UsbPlayer inputUSB, String expectedResult,String testName2,String testName3) { int prevSound = inputUSB.getLautstaerke(); String unMuted = inputUSB.unmute(); + int currentStatusofSoundWas = inputUSB.soundWas; //first case assertThat(unMuted).describedAs(testName).isEqualTo(expectedResult); //Second case assertThat(inputUSB.getLautstaerke()).describedAs(testName2).isEqualTo(prevSound); + //third case + assertThat(inputUSB.soundWas).describedAs(testName3).isEqualTo(currentStatusofSoundWas); } @@ -474,7 +477,7 @@ class UsbPlayerTest { up1.unmute(); return Stream.of( - Arguments.of("The Sound is unmuted ", up1,"unmuted","Sound level has changed") + Arguments.of("The Sound is unmuted ", up1,"unmuted","Sound level has changed","previous sound level is 0") ); } From bf95ae8e7144009378829ae0c7f44bfa5c738661 Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 21:48:30 +0100 Subject: [PATCH 08/24] UsbPlayerTest.unmuteTest third Case correction of the Production Code --- src/main/java/device/usbPlayer/UsbPlayer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 1ad4b8d..6d8f2a0 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -193,6 +193,7 @@ public class UsbPlayer implements Device { public String unmute() { setLautstaerke(soundWas); + this.soundWas = 0; return "unmuted"; } From 21b630ae04685af97322f9f864bd415472d5c47e Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 23:38:15 +0100 Subject: [PATCH 09/24] UsbPlayerTest.quieterTest third Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 15 +++++++++------ src/test/java/device/usbPlayer/UsbPlayerTest.java | 13 ++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 6d8f2a0..c9e15c2 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -12,7 +12,7 @@ public class UsbPlayer implements Device { private Boolean isConnected; private Boolean isDefect; int Lautstaerke = 0; - int soundWas ; + int soundWas =-1; public USB_Stick USBDrive = new USB_Stick(); @@ -104,11 +104,14 @@ public class UsbPlayer implements Device { //**********search method************* @Override public void quieter() { - if (Lautstaerke > 0) { - Lautstaerke -= 1; - } else { - Lautstaerke = 0; + if(this.soundWas == -1){ + if (Lautstaerke > 0 ) { + Lautstaerke -= 1; + } else { + Lautstaerke = 0; + } } + } @Override @@ -193,7 +196,7 @@ public class UsbPlayer implements Device { public String unmute() { setLautstaerke(soundWas); - this.soundWas = 0; + this.soundWas = -1; return "unmuted"; } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index f15d636..202aef3 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -79,14 +79,25 @@ class UsbPlayerTest { static Stream quieterOptions() { USB_Stick USBDrive = new USB_Stick(); + //first case UsbPlayer up1 = new UsbPlayer(USBDrive); up1.quieter(); + //second case UsbPlayer up2 = new UsbPlayer(USBDrive); up2.setLautstaerke(10); up2.quieter(); + + //third case + UsbPlayer up3 = new UsbPlayer(USBDrive); + up3.setLautstaerke(10); + up3.mute(); + up3.quieter(); + return Stream.of( Arguments.of("Volume must stay 0 ", up1, 0), - Arguments.of("Volume must be 9 ", up2, 9) + Arguments.of("Volume must be 9 ", up2, 9), + Arguments.of("Volume is muted,no change can be made ", up3, 0) + ); } From aac9081276a160387e0e2679db6091058976e5db Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 23:41:27 +0100 Subject: [PATCH 10/24] UsbPlayerTest.louderTest third Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 10 ++++++---- src/test/java/device/usbPlayer/UsbPlayerTest.java | 13 ++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index c9e15c2..5796406 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -116,10 +116,12 @@ public class UsbPlayer implements Device { @Override public void louder() { - if (Lautstaerke < 100) { - Lautstaerke += 1; - } else { - Lautstaerke = 100; + if(this.soundWas == -1) { + if (Lautstaerke < 100) { + Lautstaerke += 1; + } else { + Lautstaerke = 100; + } } } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 202aef3..1bc8d55 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -59,14 +59,25 @@ class UsbPlayerTest { static Stream louderOptions() { USB_Stick USBDrive = new USB_Stick(); + //first case UsbPlayer up11 = new UsbPlayer(USBDrive); up11.louder(); + //second case UsbPlayer up22 = new UsbPlayer(USBDrive); up22.setLautstaerke(100); up22.louder(); + //third case + UsbPlayer up3 = new UsbPlayer(USBDrive); + up3.setLautstaerke(100); + up3.mute(); + up3.louder(); + + + return Stream.of( Arguments.of("Volume is : 1 ", up11, 1), - Arguments.of("Volume is : 100 ", up22, 100) + Arguments.of("Volume is : 100 ", up22, 100), + Arguments.of("Volume is muted,no change can be made ", up3, 0) ); } From 54706c4612a7c55aab7309627808ebb987b79166 Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 23:44:34 +0100 Subject: [PATCH 11/24] UsbPlayerTest.louderTest Forth Case --- src/test/java/device/usbPlayer/UsbPlayerTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 1bc8d55..d3805a2 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -68,16 +68,21 @@ class UsbPlayerTest { up22.louder(); //third case UsbPlayer up3 = new UsbPlayer(USBDrive); - up3.setLautstaerke(100); + up3.setLautstaerke(10); up3.mute(); up3.louder(); - - + //forth case + UsbPlayer up4 = new UsbPlayer(USBDrive); + up4.setLautstaerke(10); + up4.mute(); + up4.unmute(); + up4.louder(); return Stream.of( Arguments.of("Volume is : 1 ", up11, 1), Arguments.of("Volume is : 100 ", up22, 100), - Arguments.of("Volume is muted,no change can be made ", up3, 0) + Arguments.of("Volume is muted,no change can be made ", up3, 0), + Arguments.of("Volume is muted,a change has been made ", up4, 11) ); } From 1958c4d1936b7b23d1321565c290b45eeba4133a Mon Sep 17 00:00:00 2001 From: sahar Date: Thu, 17 Feb 2022 23:46:56 +0100 Subject: [PATCH 12/24] UsbPlayerTest.quieterTest Forth Case --- src/test/java/device/usbPlayer/UsbPlayerTest.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index d3805a2..d94b380 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -82,7 +82,7 @@ class UsbPlayerTest { Arguments.of("Volume is : 1 ", up11, 1), Arguments.of("Volume is : 100 ", up22, 100), Arguments.of("Volume is muted,no change can be made ", up3, 0), - Arguments.of("Volume is muted,a change has been made ", up4, 11) + Arguments.of("Volume is unmuted,a change has been made ", up4, 11) ); } @@ -109,11 +109,18 @@ class UsbPlayerTest { up3.mute(); up3.quieter(); + //forth case + UsbPlayer up4 = new UsbPlayer(USBDrive); + up4.setLautstaerke(10); + up4.mute(); + up4.unmute(); + up4.quieter(); + return Stream.of( Arguments.of("Volume must stay 0 ", up1, 0), Arguments.of("Volume must be 9 ", up2, 9), - Arguments.of("Volume is muted,no change can be made ", up3, 0) - + Arguments.of("Volume is muted,no change can be made ", up3, 0), + Arguments.of("Volume is unmuted,a change has been made ", up4, 9) ); } From 28bee40852549f9a279ec0c1f793e344efab2c8a Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 00:06:00 +0100 Subject: [PATCH 13/24] UsbPlayerTest.louder_10_Test Forth Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 9 ++++++--- .../java/device/usbPlayer/UsbPlayerTest.java | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 5796406..ea93e00 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -126,10 +126,13 @@ public class UsbPlayer implements Device { } public void Louder_10() { - Lautstaerke += 10; - if (Lautstaerke > 100) { - Lautstaerke = 100; + if(this.soundWas == -1) { + Lautstaerke += 10; + if (Lautstaerke > 100) { + Lautstaerke = 100; + } } + } public void quieter_10() { diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index d94b380..4da5857 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -185,22 +185,29 @@ class UsbPlayerTest { static Stream louder_10_Options() { USB_Stick USBDrive = new USB_Stick(); + //first case UsbPlayer up1 = new UsbPlayer(USBDrive); up1.Louder_10(); - + //Second case UsbPlayer up2 = new UsbPlayer(USBDrive); - for (int i = 0; i <= 3; i++) { + for (int i = 0; i < 3; i++) { up2.Louder_10(); } - up2.quieter_10(); - + //third case UsbPlayer up3 = new UsbPlayer(USBDrive); up3.setLautstaerke(100); up3.Louder_10(); + //forth case + UsbPlayer up4 = new UsbPlayer(USBDrive); + up4.setLautstaerke(10); + up4.mute(); + up4.Louder_10(); + return Stream.of( Arguments.of("Volume was 0, should be 10 ", up1, 10), Arguments.of("Volume was 0, should be 30 ", up2, 30), - Arguments.of("Volume was 100, should stay 100 ", up3, 100) + Arguments.of("Volume was 100, should stay 100 ", up3, 100), + Arguments.of("Volume is muted,no change can be made ", up4, 0) ); } From 0751a3348daec19a01caf542357dedf1a77fdf3f Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 00:07:44 +0100 Subject: [PATCH 14/24] UsbPlayerTest.louder_10_Test Fifth Case --- src/test/java/device/usbPlayer/UsbPlayerTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 4da5857..48ffd9c 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -202,12 +202,19 @@ class UsbPlayerTest { up4.setLautstaerke(10); up4.mute(); up4.Louder_10(); + //fifth case + UsbPlayer up5 = new UsbPlayer(USBDrive); + up5.setLautstaerke(10); + up5.mute(); + up5.unmute(); + up5.Louder_10(); return Stream.of( Arguments.of("Volume was 0, should be 10 ", up1, 10), Arguments.of("Volume was 0, should be 30 ", up2, 30), Arguments.of("Volume was 100, should stay 100 ", up3, 100), - Arguments.of("Volume is muted,no change can be made ", up4, 0) + Arguments.of("Volume is muted,no change can be made ", up4, 0), + Arguments.of("Volume is unmuted,a change has been made ", up5, 20) ); } From f683c378d17c68089266971078a75beb935052c8 Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 00:10:35 +0100 Subject: [PATCH 15/24] UsbPlayerTest.quieter_10_Test Forth Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 8 +++++--- src/test/java/device/usbPlayer/UsbPlayerTest.java | 9 ++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index ea93e00..034c19d 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -136,9 +136,11 @@ public class UsbPlayer implements Device { } public void quieter_10() { - Lautstaerke -= 10; - if (Lautstaerke < 0) { - Lautstaerke = 0; + if(this.soundWas == -1) { + Lautstaerke -= 10; + if (Lautstaerke < 0) { + Lautstaerke = 0; + } } } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 48ffd9c..f222f15 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -240,10 +240,17 @@ class UsbPlayerTest { UsbPlayer up3 = new UsbPlayer(USBDrive); up3.quieter_10(); + //forth case + UsbPlayer up4 = new UsbPlayer(USBDrive); + up4.setLautstaerke(11); + up4.mute(); + up4.quieter_10(); + return Stream.of( Arguments.of("Volume was 10, should be 0 ", up1, 0), Arguments.of("Volume was 50, should be 20 ", up2, 20), - Arguments.of("Volume was 0, should stay 0 ", up3, 0) + Arguments.of("Volume was 0, should stay 0 ", up3, 0), + Arguments.of("Volume is muted,no change can be made ", up4, 0) ); } From 62c89d35e013365466450b7c814f830749edd576 Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 00:14:14 +0100 Subject: [PATCH 16/24] UsbPlayerTest.quieter_10_Test Fifth Case --- src/test/java/device/usbPlayer/UsbPlayerTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index f222f15..c22f806 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -227,30 +227,37 @@ class UsbPlayerTest { static Stream quieter_10_Options() { USB_Stick USBDrive = new USB_Stick(); + //first case UsbPlayer up1 = new UsbPlayer(USBDrive); up1.setLautstaerke(10); up1.quieter_10(); - + //second case UsbPlayer up2 = new UsbPlayer(USBDrive); up2.setLautstaerke(50); for (int i = 0; i < 3; i++) { up2.quieter_10(); } - + //third case UsbPlayer up3 = new UsbPlayer(USBDrive); up3.quieter_10(); - //forth case UsbPlayer up4 = new UsbPlayer(USBDrive); up4.setLautstaerke(11); up4.mute(); up4.quieter_10(); + //fifth case + UsbPlayer up5 = new UsbPlayer(USBDrive); + up5.setLautstaerke(11); + up5.mute(); + up5.unmute(); + up5.quieter_10(); return Stream.of( Arguments.of("Volume was 10, should be 0 ", up1, 0), Arguments.of("Volume was 50, should be 20 ", up2, 20), Arguments.of("Volume was 0, should stay 0 ", up3, 0), - Arguments.of("Volume is muted,no change can be made ", up4, 0) + Arguments.of("Volume is muted,no change can be made ", up4, 0), + Arguments.of("Volume is unmuted,a change has been made ", up5, 1) ); } From 2b0475f00c827b0ee6d0e3495c0a49f8a1bd1e4e Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 00:30:46 +0100 Subject: [PATCH 17/24] UsbPlayerTest.chooseItemTest First Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 29 +++++++++++-------- .../java/device/usbPlayer/UsbPlayerTest.java | 17 +++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 034c19d..9bdf190 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -12,7 +12,7 @@ public class UsbPlayer implements Device { private Boolean isConnected; private Boolean isDefect; int Lautstaerke = 0; - int soundWas =-1; + int soundWas = -1; public USB_Stick USBDrive = new USB_Stick(); @@ -104,8 +104,8 @@ public class UsbPlayer implements Device { //**********search method************* @Override public void quieter() { - if(this.soundWas == -1){ - if (Lautstaerke > 0 ) { + if (this.soundWas == -1) { + if (Lautstaerke > 0) { Lautstaerke -= 1; } else { Lautstaerke = 0; @@ -116,7 +116,7 @@ public class UsbPlayer implements Device { @Override public void louder() { - if(this.soundWas == -1) { + if (this.soundWas == -1) { if (Lautstaerke < 100) { Lautstaerke += 1; } else { @@ -126,7 +126,7 @@ public class UsbPlayer implements Device { } public void Louder_10() { - if(this.soundWas == -1) { + if (this.soundWas == -1) { Lautstaerke += 10; if (Lautstaerke > 100) { Lautstaerke = 100; @@ -136,7 +136,7 @@ public class UsbPlayer implements Device { } public void quieter_10() { - if(this.soundWas == -1) { + if (this.soundWas == -1) { Lautstaerke -= 10; if (Lautstaerke < 0) { Lautstaerke = 0; @@ -168,12 +168,11 @@ public class UsbPlayer implements Device { @Override public String getInfoText() { - String InfoText=""; + String InfoText = ""; if (isAllAudio()) { - InfoText="USB Player is on : "+this.getPlayTrack(); - } - else - InfoText="USB Player with no Albums"; + InfoText = "USB Player is on : " + this.getPlayTrack(); + } else + InfoText = "USB Player with no Albums"; return InfoText; } @@ -184,9 +183,15 @@ public class UsbPlayer implements Device { @Override public String chooseItem(int itemNr) { - return null; + String songName=""; + if (itemNr < this.getPlaylist().size()) { + songName= this.getPlaylist().get(itemNr ).toString(); + } + return songName; } + + @Override public String[] getItemList() { return null; diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index c22f806..e641c90 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -542,6 +542,23 @@ class UsbPlayerTest { Arguments.of("The Sound is unmuted ", up1,"unmuted","Sound level has changed","previous sound level is 0") ); + }//chooseItem + + @ParameterizedTest + @MethodSource("chooseItem") + void chooseItemTest(String testName, String inputSong, String expectedResult) { + //int volumeNum = inputPlay.getLautstaerke(); + assertThat(inputSong).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream chooseItem() { + USB_Stick USBDrive = new USB_Stick(); + //first case + UsbPlayer up1 = new UsbPlayer(USBDrive); + + return Stream.of( + Arguments.of("An Item from the Album was chosen ", up1.chooseItem(0), "Musik 01.mp3") + ); } } \ No newline at end of file From d6a7637c06c3bf825bb1fa5ddbac2a81763c39ff Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 00:35:02 +0100 Subject: [PATCH 18/24] UsbPlayerTest.chooseItemTest second Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 2 +- src/test/java/device/usbPlayer/UsbPlayerTest.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 9bdf190..1575e64 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -184,7 +184,7 @@ public class UsbPlayer implements Device { @Override public String chooseItem(int itemNr) { String songName=""; - if (itemNr < this.getPlaylist().size()) { + if (itemNr < this.getPlaylist().size() && itemNr >= 0) { songName= this.getPlaylist().get(itemNr ).toString(); } return songName; diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index e641c90..93ac0c8 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -557,7 +557,8 @@ class UsbPlayerTest { UsbPlayer up1 = new UsbPlayer(USBDrive); return Stream.of( - Arguments.of("An Item from the Album was chosen ", up1.chooseItem(0), "Musik 01.mp3") + Arguments.of("An Item from the Album was chosen ", up1.chooseItem(0), "Musik 01.mp3"), + Arguments.of("Incorrect Nr of Item was given ", up1.chooseItem(-1), "") ); } From 83f5e5064022d3523f509db9ecf22de21cc68c78 Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 00:42:29 +0100 Subject: [PATCH 19/24] UsbPlayerTest.chooseItemTest second Case with changes --- src/main/java/device/usbPlayer/UsbPlayer.java | 8 +++++--- src/test/java/device/usbPlayer/UsbPlayerTest.java | 2 +- 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 1575e64..a6ea9fa 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -183,11 +183,13 @@ public class UsbPlayer implements Device { @Override public String chooseItem(int itemNr) { - String songName=""; + String Message=""; if (itemNr < this.getPlaylist().size() && itemNr >= 0) { - songName= this.getPlaylist().get(itemNr ).toString(); + Message= this.getPlaylist().get(itemNr ).toString(); + }else if(itemNr < 0){ + Message="The Nr is smaller than 0"; } - return songName; + return Message; } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 93ac0c8..7be24cf 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -558,7 +558,7 @@ class UsbPlayerTest { return Stream.of( Arguments.of("An Item from the Album was chosen ", up1.chooseItem(0), "Musik 01.mp3"), - Arguments.of("Incorrect Nr of Item was given ", up1.chooseItem(-1), "") + Arguments.of("Incorrect Nr of Item was given ", up1.chooseItem(-1), "The Nr is smaller than 0") ); } From 3a3df498360d81db2719191025123a9bb57be332 Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 00:44:40 +0100 Subject: [PATCH 20/24] UsbPlayerTest.chooseItemTest third Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 2 +- src/test/java/device/usbPlayer/UsbPlayerTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index a6ea9fa..a5ca30e 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -188,7 +188,7 @@ public class UsbPlayer implements Device { Message= this.getPlaylist().get(itemNr ).toString(); }else if(itemNr < 0){ Message="The Nr is smaller than 0"; - } + }else Message="The Nr is bigger than 0"; return Message; } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 7be24cf..cb4e039 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -553,12 +553,12 @@ class UsbPlayerTest { static Stream chooseItem() { USB_Stick USBDrive = new USB_Stick(); - //first case UsbPlayer up1 = new UsbPlayer(USBDrive); return Stream.of( Arguments.of("An Item from the Album was chosen ", up1.chooseItem(0), "Musik 01.mp3"), - Arguments.of("Incorrect Nr of Item was given ", up1.chooseItem(-1), "The Nr is smaller than 0") + Arguments.of("Incorrect Nr of Item was given < 0", up1.chooseItem(-1), "The Nr is smaller than 0"), + Arguments.of("Incorrect Nr of Item was given > 0", up1.chooseItem(5), "The Nr is bigger than 0") ); } From 32693bf8fa226e281eb1cf3b49c9d72ecabb78d1 Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 01:37:50 +0100 Subject: [PATCH 21/24] UsbPlayerTest.getItemList First Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 6 ++++- .../java/device/usbPlayer/UsbPlayerTest.java | 23 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index a5ca30e..e3394a7 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -196,7 +196,11 @@ public class UsbPlayer implements Device { @Override public String[] getItemList() { - return null; + String array[] = new String[getPlaylist().size()]; + for(int j =0;j 0", up1.chooseItem(5), "The Nr is bigger than 0") ); + }//getItemList + + @ParameterizedTest + @MethodSource("getItemList") + 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); + } + + 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"}; + + return Stream.of( + Arguments.of("An Album was returned ", up1, Pl,1) + + ); } } \ No newline at end of file From 917cadd4208971093dad186f91a37e7083e6da02 Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 02:24:27 +0100 Subject: [PATCH 22/24] UsbPlayerTest.getItemList Second Case --- .../java/device/usbPlayer/UsbPlayerTest.java | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) 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) ); } From ca035a17cb3164604a39c543a1146b7f18e1b4af Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 12:39:25 +0100 Subject: [PATCH 23/24] changes saved --- src/main/java/device/usbPlayer/UsbPlayer.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index e3394a7..fbb8aa4 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -2,6 +2,7 @@ package device.usbPlayer; import device.Device; +import java.lang.reflect.Method; import java.util.ArrayList; public class UsbPlayer implements Device { @@ -178,7 +179,13 @@ public class UsbPlayer implements Device { @Override public String[] getOptions() { - return new String[0]; + + Method[] methods=this.getClass().getDeclaredMethods(); + String[] methodsList =new String[methods.length]; + for (int i = 0; i Date: Fri, 18 Feb 2022 12:59:47 +0100 Subject: [PATCH 24/24] change in the Structure --- src/main/java/device/usbPlayer/UsbPlayer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index fbb8aa4..acf923b 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -63,6 +63,8 @@ public class UsbPlayer implements Device { return Lautstaerke; } + public UsbPlayer() {} + //*********constructure******** public UsbPlayer(USB_Stick stick) { super();