26 Commits

Author SHA1 Message Date
Jenkins 5da6de9413 Merge commit 'fd36f2089f2f69bbc514d60eeb1562be3e5bc4a3' into HEAD 3 years ago
sahar fd36f2089f change in the Structure 3 years ago
sahar 7e7a6d4b35 Merge branch 'master' into feature-pr-USB-otherTests 3 years ago
sahar ca035a17cb changes saved 3 years ago
sahar 917cadd420 UsbPlayerTest.getItemList Second Case 3 years ago
sahar 32693bf8fa UsbPlayerTest.getItemList First Case 3 years ago
sahar 3a3df49836 UsbPlayerTest.chooseItemTest third Case 3 years ago
sahar 83f5e50640 UsbPlayerTest.chooseItemTest second Case with changes 3 years ago
sahar d6a7637c06 UsbPlayerTest.chooseItemTest second Case 3 years ago
sahar 2b0475f00c UsbPlayerTest.chooseItemTest First Case 3 years ago
sahar 62c89d35e0 UsbPlayerTest.quieter_10_Test Fifth Case 3 years ago
sahar f683c378d1 UsbPlayerTest.quieter_10_Test Forth Case 3 years ago
sahar 0751a3348d UsbPlayerTest.louder_10_Test Fifth Case 3 years ago
sahar 28bee40852 UsbPlayerTest.louder_10_Test Forth Case 3 years ago
sahar 1958c4d193 UsbPlayerTest.quieterTest Forth Case 3 years ago
sahar 54706c4612 UsbPlayerTest.louderTest Forth Case 3 years ago
sahar aac9081276 UsbPlayerTest.louderTest third Case 3 years ago
sahar 21b630ae04 UsbPlayerTest.quieterTest third Case 3 years ago
sahar bf95ae8e71 UsbPlayerTest.unmuteTest third Case correction of the Production Code 3 years ago
sahar 83d3c8e4c0 UsbPlayerTest.unmuteTest third Case 3 years ago
sahar a7c3ea8610 UsbPlayerTest.unmuteTest second Case 3 years ago
sahar 947a842f6d UsbPlayerTest.unmuteTest first Case 3 years ago
sahar 20727f6e60 UsbPlayerTest.muteTest third Case 3 years ago
sahar 802a780a4e UsbPlayerTest.muteTest Second Case 3 years ago
sahar 717120b972 UsbPlayerTest.getInfoTextTest Second Case 3 years ago
sahar 69cbbf90fa UsbPlayerTest.getInfoTextTest First Case 3 years ago
  1. 9
      src/main/java/device/usbPlayer/USB_Stick.java
  2. 95
      src/main/java/device/usbPlayer/UsbPlayer.java
  3. 3
      src/test/java/device/usbPlayer/USB_StickTest.java
  4. 327
      src/test/java/device/usbPlayer/UsbPlayerTest.java

9
src/main/java/device/usbPlayer/USB_Stick.java

@ -39,14 +39,19 @@ public class USB_Stick {
USB_Stick(String a){
}
USB_Stick(ArrayList<String> a1) {
Folders.add(a1);
currentAlbum = 0;
}
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);
}
}

95
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 {
@ -12,6 +13,8 @@ public class UsbPlayer implements Device {
private Boolean isConnected;
private Boolean isDefect;
int Lautstaerke = 0;
int soundWas = -1;
public USB_Stick USBDrive = new USB_Stick();
public ArrayList<String> getPlaylist() {
@ -60,8 +63,10 @@ public class UsbPlayer implements Device {
return Lautstaerke;
}
public UsbPlayer() {}
//*********constructure********
public UsbPlayer() {
public UsbPlayer(USB_Stick stick) {
super();
isDefect = false;
isConnected = true;
@ -70,11 +75,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);
}
}
@ -100,39 +107,49 @@ 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
public void louder() {
if (Lautstaerke < 100) {
Lautstaerke += 1;
} else {
Lautstaerke = 100;
if (this.soundWas == -1) {
if (Lautstaerke < 100) {
Lautstaerke += 1;
} else {
Lautstaerke = 100;
}
}
}
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() {
Lautstaerke -= 10;
if (Lautstaerke < 0) {
Lautstaerke = 0;
if (this.soundWas == -1) {
Lautstaerke -= 10;
if (Lautstaerke < 0) {
Lautstaerke = 0;
}
}
}
@Override
public int getVolume() {
return 0;
return Lautstaerke;
}
@Override
@ -154,32 +171,60 @@ public class UsbPlayer implements Device {
@Override
public String getInfoText() {
return null;
String InfoText = "";
if (isAllAudio()) {
InfoText = "USB Player is on : " + this.getPlayTrack();
} else
InfoText = "USB Player with no Albums";
return InfoText;
}
@Override
public String[] getOptions() {
return new String[0];
Method[] methods=this.getClass().getDeclaredMethods();
String[] methodsList =new String[methods.length];
for (int i = 0; i <methods.length ; i++) {
methodsList[i]=methods[i].getName();
}
return methodsList;
}
@Override
public String chooseItem(int itemNr) {
return null;
String Message="";
if (itemNr < this.getPlaylist().size() && itemNr >= 0) {
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;
}
@Override
public String[] getItemList() {
return null;
String array[] = new String[getPlaylist().size()];
for(int j =0;j<getPlaylist().size();j++){
array[j] = getPlaylist().get(j);
}
return array;
}
@Override
public String mute() {
return null;
this.soundWas = getLautstaerke();
setLautstaerke(0);
return "muted";
}
@Override
public String unmute() {
return null;
setLautstaerke(soundWas);
this.soundWas = -1;
return "unmuted";
}
@ -246,4 +291,6 @@ public class UsbPlayer implements Device {
//go to the last Song
setPlayTrack(this.getPlaylist().get(this.getPlaylist().size() - 1));
}
}

3
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 {
);
}
}

327
src/test/java/device/usbPlayer/UsbPlayerTest.java

@ -9,9 +9,10 @@ import java.util.ArrayList;
import static org.assertj.core.api.Assertions.assertThat;
class UsbPlayerTest {
UsbPlayer up = new UsbPlayer();
//UsbPlayer up = new UsbPlayer();
@ParameterizedTest
@MethodSource("PlayOptions")
@ -21,21 +22,22 @@ class UsbPlayerTest {
}
static Stream<Arguments> 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<String> l = new ArrayList<String>();
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<String> Pl = new ArrayList<String>();
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,14 +59,31 @@ class UsbPlayerTest {
}
static Stream<Arguments> louderOptions() {
UsbPlayer up11 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up11 = new UsbPlayer(USBDrive);
up11.louder();
UsbPlayer up22 = new UsbPlayer();
//second case
UsbPlayer up22 = new UsbPlayer(USBDrive);
up22.setLautstaerke(100);
up22.louder();
//third case
UsbPlayer up3 = new UsbPlayer(USBDrive);
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 : 100 ", up22, 100),
Arguments.of("Volume is muted,no change can be made ", up3, 0),
Arguments.of("Volume is unmuted,a change has been made ", up4, 11)
);
}
@ -76,14 +95,33 @@ class UsbPlayerTest {
}
static Stream<Arguments> quieterOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.quieter();
UsbPlayer up2 = new UsbPlayer();
//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();
//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 must be 9 ", up2, 9),
Arguments.of("Volume is muted,no change can be made ", up3, 0),
Arguments.of("Volume is unmuted,a change has been made ", up4, 9)
);
}
@ -96,13 +134,14 @@ class UsbPlayerTest {
}
static Stream<Arguments> 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 +162,10 @@ class UsbPlayerTest {
}
static Stream<Arguments> 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,22 +185,37 @@ class UsbPlayerTest {
}
static Stream<Arguments> louder_10_Options() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.Louder_10();
UsbPlayer up2 = new UsbPlayer();
for (int i = 0; i <= 3; i++) {
//Second case
UsbPlayer up2 = new UsbPlayer(USBDrive);
for (int i = 0; i < 3; i++) {
up2.Louder_10();
}
up2.quieter_10();
UsbPlayer up3 = new UsbPlayer();
//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();
//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 was 100, should stay 100 ", up3, 100),
Arguments.of("Volume is muted,no change can be made ", up4, 0),
Arguments.of("Volume is unmuted,a change has been made ", up5, 20)
);
}
@ -172,23 +227,38 @@ class UsbPlayerTest {
}
static Stream<Arguments> quieter_10_Options() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.setLautstaerke(10);
up1.quieter_10();
UsbPlayer up2 = new UsbPlayer();
//second case
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.setLautstaerke(50);
for (int i = 0; i < 3; i++) {
up2.quieter_10();
}
UsbPlayer up3 = new UsbPlayer();
//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 was 0, should stay 0 ", up3, 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)
);
}
@ -205,7 +275,8 @@ class UsbPlayerTest {
}
static Stream<Arguments> 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 +293,17 @@ class UsbPlayerTest {
}
static Stream<Arguments> 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 +324,46 @@ class UsbPlayerTest {
}
static Stream<Arguments> 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<String> Pl = new ArrayList<String>();
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<String> Pl1 = new ArrayList<String>();
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<String> Pl2 = new ArrayList<String>();
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<String> Pl3 = new ArrayList<String>();
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<String> Pl4 = new ArrayList<String>();
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<String> Pl5 = new ArrayList<String>();
Pl5.add("Musik 01.aac");
Pl5.add("Musik 02.txt");
@ -314,25 +387,26 @@ 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<Arguments> 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();
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))
);
}
@ -340,27 +414,28 @@ 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<Arguments> 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();
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))
);
}
@ -368,26 +443,148 @@ 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<Arguments> 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(
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")
);
}////
@ParameterizedTest
@MethodSource("getInfoTextOptions")
void getInfoTextTest(String testName, UsbPlayer inputUSB, String expectedResult) {
String infotxt = inputUSB.getInfoText();
assertThat(infotxt).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> getInfoTextOptions() {
USB_Stick USBDrive = new USB_Stick();
ArrayList<String> Fileslist = new ArrayList<String>();
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 no Albums ", up2, "USB Player with no Albums")
);
}//"muted"
@ParameterizedTest
@MethodSource("muteOptions")
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);
}
static Stream<Arguments> muteOptions() {
USB_Stick USBDrive = new USB_Stick();
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 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);
}
static Stream<Arguments> 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", "Sound level has changed", "previous sound level is 0")
);
}
@ParameterizedTest
@MethodSource("chooseItem")
void chooseItemTest(String testName, String inputSong, String expectedResult) {
assertThat(inputSong).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> chooseItem() {
USB_Stick USBDrive = new USB_Stick();
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 < 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")
);
}//getItemList
@ParameterizedTest
@MethodSource("getItemList")
void getItemListTest(String testName, UsbPlayer inputPlayer, String[] expectedResult) {
String[] Pl = inputPlayer.getItemList();
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<Arguments> getItemList() {
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
String[] Pl = {"Musik 01.mp3", "Musik 02.mp3", "Musik 03.mp3"};
UsbPlayer up2 = new UsbPlayer(USBDrive);
ArrayList<String> Pl1 = new ArrayList<String>();
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)
);
}
Loading…
Cancel
Save