From 9bf794bbea8749163410d6992190606f04c4bad1 Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 16 Feb 2022 00:03:45 +0100 Subject: [PATCH 1/9] UsbPlayerTest.GoToLastTest fiSecond Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 1 + src/test/java/device/usbPlayer/UsbPlayerTest.java | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index bf403d6..d0dd39d 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -222,6 +222,7 @@ public class UsbPlayer implements Device { } public void GoToLast() { + //go to the last Song setPlayTrack("Musik 03.mp3"); } } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 042a4a9..b649a16 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -348,9 +348,15 @@ class UsbPlayerTest { UsbPlayer up1 = new UsbPlayer(); up1.GoToLast(); + UsbPlayer up2 = new UsbPlayer(); + up2.GoToLast(); + up2.GoToLast(); + + return Stream.of( - Arguments.of("It should go to the first Song ", up1,"Musik 03.mp3") + Arguments.of("It should go to the Last Song ", up1,"Musik 03.mp3"), + Arguments.of("It should go to the Last Song even after calling the function twice ", up2,"Musik 03.mp3") ); } From 945bb15abff248273a696718be6125f47b076517 Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 16 Feb 2022 00:08:25 +0100 Subject: [PATCH 2/9] UsbPlayerTest.GoToLastTest third Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 2 +- src/test/java/device/usbPlayer/UsbPlayerTest.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index d0dd39d..40d03fe 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -223,6 +223,6 @@ public class UsbPlayer implements Device { public void GoToLast() { //go to the last Song - setPlayTrack("Musik 03.mp3"); + setPlayTrack(this.getPlaylist().get(this.getPlaylist().size()-1)); } } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index b649a16..1986521 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -352,11 +352,15 @@ class UsbPlayerTest { up2.GoToLast(); up2.GoToLast(); + UsbPlayer up3 = new UsbPlayer(); + up3.next(); + up3.GoToLast(); return Stream.of( - Arguments.of("It should go to the Last Song ", up1,"Musik 03.mp3"), - Arguments.of("It should go to the Last Song even after calling the function twice ", up2,"Musik 03.mp3") + Arguments.of("It should go to the Last Song ", up1,up3.getPlaylist().get(up3.getPlaylist().size()-1)), + Arguments.of("It should go to the Last Song even after calling the function twice ", up2,up3.getPlaylist().get(up3.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)) ); } From 95977c9ae7e675d8ba6a4433a8d8ace842c9f06e Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 16 Feb 2022 00:17:49 +0100 Subject: [PATCH 3/9] UsbPlayerTest.setPlayTrackTest first Case --- .../java/device/usbPlayer/UsbPlayerTest.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 1986521..b44afb5 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -358,10 +358,27 @@ class UsbPlayerTest { return Stream.of( - Arguments.of("It should go to the Last Song ", up1,up3.getPlaylist().get(up3.getPlaylist().size()-1)), - Arguments.of("It should go to the Last Song even after calling the function twice ", up2,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)) ); } + @ParameterizedTest + @MethodSource("setPlayTrackOptions") + void setPlayTrackTest(String testName, UsbPlayer inputUSB, String expectedResult) { + String firstSong = inputUSB.getPlayTrack(); + assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream setPlayTrackOptions() { + //first case + UsbPlayer up1 = new UsbPlayer(); + up1.setPlayTrack("Musik 02.mp3"); + + return Stream.of( + Arguments.of("It should change the current Song ", up1,"Musik 02.mp3") + ); + } + } \ No newline at end of file From 648baabab07b10a93edf862e43efb65b44b52054 Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 16 Feb 2022 00:21:47 +0100 Subject: [PATCH 4/9] UsbPlayerTest.setPlayTrackTest Second Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 1 + src/test/java/device/usbPlayer/UsbPlayerTest.java | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 40d03fe..dc82c32 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -43,6 +43,7 @@ public class UsbPlayer implements Device { } public void setPlayTrack(String playTrack) { + if(this.findSong(playTrack) != -1) this.playTrack = playTrack; } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index b44afb5..c23080b 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -376,8 +376,13 @@ class UsbPlayerTest { UsbPlayer up1 = new UsbPlayer(); up1.setPlayTrack("Musik 02.mp3"); + //Second Case + UsbPlayer up2 = new UsbPlayer(); + up2.setPlayTrack("Musik 02.mp3"); + return Stream.of( - Arguments.of("It should change the current Song ", up1,"Musik 02.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") ); } From 308057ae4b4f1079f8d28efef51a49851190d3a0 Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 16 Feb 2022 00:26:38 +0100 Subject: [PATCH 5/9] UsbPlayerTest.setPlayTrackTest Third Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 5 +++-- src/test/java/device/usbPlayer/UsbPlayerTest.java | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index dc82c32..2e5a2bf 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -43,8 +43,9 @@ public class UsbPlayer implements Device { } public void setPlayTrack(String playTrack) { - if(this.findSong(playTrack) != -1) - this.playTrack = playTrack; + if(this.findSong(playTrack) != -1){ + this.playTrack = playTrack;} + else System.out.println("The Song does not exist in the Albume"); } diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index c23080b..6aea624 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -380,9 +380,14 @@ class UsbPlayerTest { UsbPlayer up2 = new UsbPlayer(); up2.setPlayTrack("Musik 02.mp3"); + //Third Case + UsbPlayer up3 = new UsbPlayer(); + 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("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") ); } From 85e3d47217dc28527fb2d3dddf200b826a26858a Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 16 Feb 2022 19:12:57 +0100 Subject: [PATCH 6/9] Changes in the Structure if device.usbPlayer , USB_Stick.java was added and changes in the UsbPlayer.java --- src/main/java/device/usbPlayer/USB_Stick.java | 41 ++++++++++++++++ src/main/java/device/usbPlayer/UsbPlayer.java | 47 ++++++++++--------- 2 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 src/main/java/device/usbPlayer/USB_Stick.java diff --git a/src/main/java/device/usbPlayer/USB_Stick.java b/src/main/java/device/usbPlayer/USB_Stick.java new file mode 100644 index 0000000..4b0d4fa --- /dev/null +++ b/src/main/java/device/usbPlayer/USB_Stick.java @@ -0,0 +1,41 @@ +package device.usbPlayer; + +import java.util.ArrayList; + +public class USB_Stick { + + public ArrayList> albums = new ArrayList<>(); + + USB_Stick() { + ArrayList a1 = new ArrayList(); + a1.add("Musik 01.mp3"); + a1.add("Musik 02.mp3"); + a1.add("Musik 03.mp3"); + albums.add(0,a1); + + ArrayList a2 = new ArrayList(); + a2.add("File 01.txt"); + a2.add("File 01.txt"); + a2.add("File 01.txt"); + albums.add(1,a2); + + ArrayList a3 = new ArrayList(); + a3.add("Photo 01.gif"); + a3.add("Photo 02.gif"); + a3.add("Photo 03.gif"); + albums.add(2,a3); + + ArrayList a4 = new ArrayList(); + a4.add("Music 01.mp3"); + a4.add("Music 02.mp3"); + a4.add("Music 03.mp3"); + albums.add(3,a4); + + } + public ArrayList getAlbum(){ + return albums.get(0); + } + +} + + diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 2e5a2bf..7da474a 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -6,13 +6,14 @@ import java.util.ArrayList; public class UsbPlayer implements Device { + private ArrayList Playlist = new ArrayList(); private String playTrack = ""; private Boolean isConnected; private Boolean isDefect; int Lautstaerke = 0; + public USB_Stick USBDrive = new USB_Stick(); - //*********setters und getters******** public ArrayList getPlaylist() { return Playlist; } @@ -43,9 +44,9 @@ public class UsbPlayer implements Device { } public void setPlayTrack(String playTrack) { - if(this.findSong(playTrack) != -1){ - this.playTrack = playTrack;} - else System.out.println("The Song does not exist in the Albume"); + if (this.findSong(playTrack) != -1) { + this.playTrack = playTrack; + } else System.out.println("The Song does not exist in the Albume"); } @@ -64,12 +65,15 @@ public class UsbPlayer implements Device { super(); isDefect = false; isConnected = true; - Playlist.add("Musik 01.mp3"); + /*Playlist.add("Musik 01.mp3"); Playlist.add("Musik 02.mp3"); Playlist.add("Musik 03.mp3"); + playTrack = Playlist.get(0);*/ + Playlist = USBDrive.getAlbum(); playTrack = Playlist.get(0); } + //**********search method************* public boolean isAllAudio() { @@ -78,7 +82,7 @@ public class UsbPlayer implements Device { for (int i = 0; i < Playlist.size(); i++) { song = Playlist.get(i).substring(Playlist.get(i).length() - 4); - if (song.equals(".mp3") | song.equals(".mp4")| song.equals(".m4a")| song.equals(".wav")| song.equals(".wma")| song.equals(".aac") ) { + if (song.equals(".mp3") | song.equals(".mp4") | song.equals(".m4a") | song.equals(".wav") | song.equals(".wma") | song.equals(".aac")) { flag = true; } else { flag = false; @@ -87,10 +91,12 @@ public class UsbPlayer implements Device { } return flag; } + + //**********search method************* @Override public void quieter() { - if(Lautstaerke > 0) { + if (Lautstaerke > 0) { Lautstaerke -= 1; } else { Lautstaerke = 0; @@ -99,21 +105,21 @@ public class UsbPlayer implements Device { @Override public void louder() { - if(Lautstaerke < 100) { + if (Lautstaerke < 100) { Lautstaerke += 1; } else { Lautstaerke = 100; } } - public void Louder_10(){ + public void Louder_10() { Lautstaerke += 10; if (Lautstaerke > 100) { Lautstaerke = 100; } } - public void quieter_10(){ + public void quieter_10() { Lautstaerke -= 10; if (Lautstaerke < 0) { Lautstaerke = 0; @@ -190,32 +196,31 @@ public class UsbPlayer implements Device { } - public int findSong(String songName){ + public int findSong(String songName) { - int songIndex =-1, index=-1; + int songIndex = -1, index = -1; String song; for (int j = 0; j < getPlaylist().size(); j++) { song = getPlaylist().get(j); - songIndex=song.toLowerCase().indexOf(songName.toLowerCase()); + songIndex = song.toLowerCase().indexOf(songName.toLowerCase()); if (songIndex != -1) { - index = j; + index = j; break; } } return index; } - public boolean GoTo(String songName){ - if(findSong(songName) != -1){ + public boolean GoTo(String songName) { + if (findSong(songName) != -1) { playTrack = getPlaylist().get(findSong(songName));//songName; return true; - } - else - //playTrack = songName; - return false; + } else + //playTrack = songName; + return false; } public void GoToFirst() { @@ -225,6 +230,6 @@ public class UsbPlayer implements Device { public void GoToLast() { //go to the last Song - setPlayTrack(this.getPlaylist().get(this.getPlaylist().size()-1)); + setPlayTrack(this.getPlaylist().get(this.getPlaylist().size() - 1)); } } From d1b481b3d06d984cdef8cc254cecfe97bea062a2 Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 16 Feb 2022 19:56:37 +0100 Subject: [PATCH 7/9] USB_StickTest.getAlbumTest First Case --- .../java/device/usbPlayer/USB_StickTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/test/java/device/usbPlayer/USB_StickTest.java diff --git a/src/test/java/device/usbPlayer/USB_StickTest.java b/src/test/java/device/usbPlayer/USB_StickTest.java new file mode 100644 index 0000000..a713b10 --- /dev/null +++ b/src/test/java/device/usbPlayer/USB_StickTest.java @@ -0,0 +1,33 @@ +package device.usbPlayer; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; +import java.util.ArrayList; + +import static org.assertj.core.api.Assertions.assertThat; + +class USB_StickTest { + + @ParameterizedTest + @MethodSource("getAlbumOptions") + void getAlbumTest(String testName, ArrayList album,int TestNr) {//, int expectedResult + //int volumeNum = inputPlay.getLautstaerke(); + if(TestNr == 1) + assertThat(album).describedAs(testName).isNotEmpty(); + } + + static Stream getAlbumOptions() { + USB_Stick stick = new USB_Stick(); + ArrayList AlbumsItems = new ArrayList<>(); + AlbumsItems= stick.getAlbum(); + + + return Stream.of( + Arguments.of("First Album is loaded", stick.getAlbum(),1)//,something + ); + } + +} \ No newline at end of file From 88078ff752fe2267306b4bfe5994e742dc4adadc Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 16 Feb 2022 20:52:14 +0100 Subject: [PATCH 8/9] USB_StickTest.ChangeAlbumTest First Case --- src/main/java/device/usbPlayer/USB_Stick.java | 25 +++++++++++++------ .../java/device/usbPlayer/USB_StickTest.java | 21 ++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/main/java/device/usbPlayer/USB_Stick.java b/src/main/java/device/usbPlayer/USB_Stick.java index 4b0d4fa..c3d3557 100644 --- a/src/main/java/device/usbPlayer/USB_Stick.java +++ b/src/main/java/device/usbPlayer/USB_Stick.java @@ -4,36 +4,45 @@ import java.util.ArrayList; public class USB_Stick { - public ArrayList> albums = new ArrayList<>(); + public ArrayList> Folders = new ArrayList<>(); + int currentAlbum ; USB_Stick() { ArrayList a1 = new ArrayList(); a1.add("Musik 01.mp3"); a1.add("Musik 02.mp3"); a1.add("Musik 03.mp3"); - albums.add(0,a1); + Folders.add(0,a1); ArrayList a2 = new ArrayList(); a2.add("File 01.txt"); - a2.add("File 01.txt"); - a2.add("File 01.txt"); - albums.add(1,a2); + a2.add("File 02.txt"); + a2.add("File 03.txt"); + Folders.add(1,a2); ArrayList a3 = new ArrayList(); a3.add("Photo 01.gif"); a3.add("Photo 02.gif"); a3.add("Photo 03.gif"); - albums.add(2,a3); + Folders.add(2,a3); ArrayList a4 = new ArrayList(); a4.add("Music 01.mp3"); a4.add("Music 02.mp3"); a4.add("Music 03.mp3"); - albums.add(3,a4); + Folders.add(3,a4); + + currentAlbum = 0; + + } public ArrayList getAlbum(){ - return albums.get(0); + return Folders.get(currentAlbum); + } + + public void ChangeAlbum(){ + ++currentAlbum; } } diff --git a/src/test/java/device/usbPlayer/USB_StickTest.java b/src/test/java/device/usbPlayer/USB_StickTest.java index a713b10..4c6f671 100644 --- a/src/test/java/device/usbPlayer/USB_StickTest.java +++ b/src/test/java/device/usbPlayer/USB_StickTest.java @@ -30,4 +30,25 @@ class USB_StickTest { ); } + //ChangeAlbum + @ParameterizedTest + @MethodSource("ChangeAlbumOptions") + void ChangeAlbumTest(String testName, USB_Stick s) {//, int expectedResult + ArrayList a = new ArrayList(); + a = s.getAlbum(); + + assertThat(a).describedAs(testName).contains("File 01.txt","File 02.txt","File 03.txt"); + } + + static Stream ChangeAlbumOptions() { + USB_Stick stick = new USB_Stick(); + ArrayList AlbumsItems = new ArrayList<>(); + stick.ChangeAlbum(); + + + return Stream.of( + Arguments.of("First Album is loaded", stick)//,something + ); + } + } \ No newline at end of file From 002db4c71f38e21d9528a63b57b96c2cf3ad45ed Mon Sep 17 00:00:00 2001 From: sahar Date: Wed, 16 Feb 2022 22:52:06 +0100 Subject: [PATCH 9/9] USB_StickTest.getAlbumTest Second Case --- .../java/device/usbPlayer/NoFolderFound.java | 8 ++++ src/main/java/device/usbPlayer/USB_Stick.java | 14 ++++++- src/main/java/device/usbPlayer/UsbPlayer.java | 6 ++- .../java/device/usbPlayer/USB_StickTest.java | 41 +++++++++++++------ 4 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 src/main/java/device/usbPlayer/NoFolderFound.java diff --git a/src/main/java/device/usbPlayer/NoFolderFound.java b/src/main/java/device/usbPlayer/NoFolderFound.java new file mode 100644 index 0000000..5d22d07 --- /dev/null +++ b/src/main/java/device/usbPlayer/NoFolderFound.java @@ -0,0 +1,8 @@ +package device.usbPlayer; + +public class NoFolderFound extends Exception{ + public NoFolderFound(String message) + { + super(message); + } +} diff --git a/src/main/java/device/usbPlayer/USB_Stick.java b/src/main/java/device/usbPlayer/USB_Stick.java index c3d3557..cb15e82 100644 --- a/src/main/java/device/usbPlayer/USB_Stick.java +++ b/src/main/java/device/usbPlayer/USB_Stick.java @@ -1,6 +1,7 @@ package device.usbPlayer; import java.util.ArrayList; +import device.usbPlayer.NoFolderFound; public class USB_Stick { @@ -34,11 +35,20 @@ public class USB_Stick { currentAlbum = 0; + } + USB_Stick(String a){ } - public ArrayList getAlbum(){ - return Folders.get(currentAlbum); + 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); + } } public void ChangeAlbum(){ diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 7da474a..a21bca5 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -69,7 +69,11 @@ public class UsbPlayer implements Device { Playlist.add("Musik 02.mp3"); Playlist.add("Musik 03.mp3"); playTrack = Playlist.get(0);*/ - Playlist = USBDrive.getAlbum(); + try { + Playlist = USBDrive.getAlbum(); + } catch (NoFolderFound e) { + e.printStackTrace(); + } playTrack = Playlist.get(0); } diff --git a/src/test/java/device/usbPlayer/USB_StickTest.java b/src/test/java/device/usbPlayer/USB_StickTest.java index 4c6f671..8d21050 100644 --- a/src/test/java/device/usbPlayer/USB_StickTest.java +++ b/src/test/java/device/usbPlayer/USB_StickTest.java @@ -2,42 +2,59 @@ package device.usbPlayer; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.MethodSource;//hasMessageMatching import java.util.stream.Stream; import java.util.ArrayList; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; +import static org.assertj.core.api.AssertionsForClassTypes.catchThrowable; +import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class USB_StickTest { @ParameterizedTest @MethodSource("getAlbumOptions") - void getAlbumTest(String testName, ArrayList album,int TestNr) {//, int expectedResult - //int volumeNum = inputPlay.getLautstaerke(); - if(TestNr == 1) - assertThat(album).describedAs(testName).isNotEmpty(); + void getAlbumTest(String testName, USB_Stick s, int TestNr) throws NoFolderFound { + ArrayList album =new ArrayList(); + + if (TestNr == 1){ + album = s.getAlbum(); + assertThat(album).describedAs(testName).isNotEmpty();} + else { + // when + Throwable thrown = catchThrowable(() -> s.getAlbum()); + + // then + assertThat(thrown) + .isInstanceOf(NoFolderFound.class) + .hasMessageContaining("The USB Drive is empty"); + + } + } - static Stream getAlbumOptions() { + static Stream getAlbumOptions() throws NoFolderFound { USB_Stick stick = new USB_Stick(); - ArrayList AlbumsItems = new ArrayList<>(); - AlbumsItems= stick.getAlbum(); - + USB_Stick emptyStick = new USB_Stick(""); return Stream.of( - Arguments.of("First Album is loaded", stick.getAlbum(),1)//,something + Arguments.of("First Album is loaded", stick, 1), + Arguments.of("No Album is loaded", emptyStick, 2) ); } //ChangeAlbum @ParameterizedTest @MethodSource("ChangeAlbumOptions") - void ChangeAlbumTest(String testName, USB_Stick s) {//, int expectedResult + void ChangeAlbumTest(String testName, USB_Stick s) throws NoFolderFound { ArrayList a = new ArrayList(); a = s.getAlbum(); - assertThat(a).describedAs(testName).contains("File 01.txt","File 02.txt","File 03.txt"); + assertThat(a).describedAs(testName).contains("File 01.txt", "File 02.txt", "File 03.txt"); } static Stream ChangeAlbumOptions() {