Browse Source

USB_StickTest.getAlbumTest Second Case

feature-pr-USB-otherTests
sahar 3 years ago
parent
commit
002db4c71f
  1. 8
      src/main/java/device/usbPlayer/NoFolderFound.java
  2. 14
      src/main/java/device/usbPlayer/USB_Stick.java
  3. 6
      src/main/java/device/usbPlayer/UsbPlayer.java
  4. 41
      src/test/java/device/usbPlayer/USB_StickTest.java

8
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);
}
}

14
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<String> getAlbum(){
return Folders.get(currentAlbum);
public ArrayList<String> 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(){

6
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);
}

41
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<String> 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<String> album =new ArrayList<String>();
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<Arguments> getAlbumOptions() {
static Stream<Arguments> getAlbumOptions() throws NoFolderFound {
USB_Stick stick = new USB_Stick();
ArrayList<String> 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<String> a = new ArrayList<String>();
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<Arguments> ChangeAlbumOptions() {

Loading…
Cancel
Save