Compare commits

...

9 Commits

  1. 32
      src/main/java/BordComputer.java
  2. 23
      src/main/java/device/usbPlayer/UsbPlayer.java
  3. 100
      src/test/java/BordComputerTest.java
  4. 339
      src/test/java/device/usbPlayer/UsbPlayerTest.java

32
src/main/java/BordComputer.java

@ -1,4 +1,6 @@
import device.Device; import device.Device;
import device.cdPlayer.CD;
import device.cdPlayer.CDPlayer;
import java.io.FileReader; import java.io.FileReader;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -35,4 +37,34 @@ public class BordComputer {
installedDevices[i] = (Device) c.getConstructor().newInstance(); installedDevices[i] = (Device) c.getConstructor().newInstance();
} }
} }
public String changeDevice() {
Device[] tempDevices=new Device[installedDevices.length];
tempDevices[0]=installedDevices[1];
tempDevices[1]=installedDevices[2];
tempDevices[2]=installedDevices[0];
//replaces the lists
installedDevices=tempDevices;
//setting activeDevice
activeDevice =installedDevices[0];
String infoText="";
if(activeDevice instanceof CDPlayer){
CDPlayer cdPlayer=(CDPlayer) activeDevice;
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"};
//some CDs
CD audioCD1=new CD("Audio",audioPlayList);
audioCD1.setAlbumName("Love Songs");
cdPlayer.tapOnCdFlap();
cdPlayer.setCD(audioCD1);
cdPlayer.tapOnCdFlap();
cdPlayer.setInfoText();
infoText = cdPlayer.getInfoText();
}else{
infoText=activeDevice.getInfoText()+" ist activate";
}
return infoText;
}
} }

23
src/main/java/device/usbPlayer/UsbPlayer.java

@ -230,27 +230,8 @@ public class UsbPlayer implements Device {
@Override @Override
public String play() { public String play() {
String result = "USB : ";
if (isConnected == true) {
result += "connected,";
if (isDefect == false) {
result += "working";
if (this.Playlist.size() != 0) {
result += ",have a list";
if (this.isAllAudio()) {
result += ",Audio";
if (!playTrack.equals(""))
result += ",point to a track.";
else
result += ",doesn't point to a track.";
} else {
result += ",not Audio.";
}
} else result += ",have no list.";
} else {
result += "not working.";
}
} else result = "not connected.";
String result = "USB Device plays";
return result; return result;
} }

100
src/test/java/BordComputerTest.java

@ -1,6 +1,8 @@
import device.Device; import device.Device;
import device.cdPlayer.CD;
import device.cdPlayer.CDPlayer; import device.cdPlayer.CDPlayer;
import device.radioPlayer.RadioPlayer; import device.radioPlayer.RadioPlayer;
import device.usbPlayer.USB_Stick;
import device.usbPlayer.UsbPlayer; import device.usbPlayer.UsbPlayer;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
@ -80,5 +82,103 @@ class BordComputerTest {
e.printStackTrace(); e.printStackTrace();
} }
return count; return count;
}//changeDevice()
@ParameterizedTest
@MethodSource("changeDeviceOptions")
void changeDeviceTest(String testName, BordComputer inputBC, Device[] oldDevices,Device prvDevice,String message ,int caseNr) {
Device[] newDevicesList = inputBC.installedDevices.clone();
if (caseNr == 1 ) {
assertThat(newDevicesList).describedAs(testName).isNotEqualTo(oldDevices);
}else if (caseNr == 2) {
Device currentDevice = inputBC.activeDevice;
assertThat(currentDevice).describedAs(testName).isNotEqualTo(prvDevice);
}else if (caseNr == 3) {
assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull();
}else if (caseNr == 4) {
assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull();
}else if (caseNr == 5) {
assertThat(inputBC.changeDevice()).describedAs(testName).isNotNull();
}else if (caseNr == 6) {
assertThat(inputBC.changeDevice()).describedAs(testName).contains("USB Player");
}else if (caseNr == 7) {//playlist
assertThat(inputBC.changeDevice()).describedAs(testName).contains("CDPlayer");
}else if (caseNr == 8) {//
assertThat(inputBC.changeDevice()).describedAs(testName).contains("playlist");
}
} }
static Stream<Arguments> changeDeviceOptions() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
//first case
BordComputer bc = new BordComputer();
bc.readConfig();
bc.setDevices();
Device[] currentDevices = new Device[bc.installedDevices.length];
currentDevices = bc.installedDevices.clone();
String m = bc.changeDevice();
//second case
BordComputer bc1 = new BordComputer();
bc1.readConfig();
bc1.setDevices();
Device prvDevice = bc1.activeDevice;
m =bc1.changeDevice();
//third case
BordComputer bc2 = new BordComputer();
bc2.readConfig();
bc2.setDevices();
m =bc2.changeDevice();
//forth case
BordComputer bc3 = new BordComputer();
bc3.readConfig();
bc3.setDevices();
m =bc3.changeDevice();
m =bc3.changeDevice(); //CDPlayer
//fifth case
BordComputer bc4 = new BordComputer();
bc4.readConfig();
bc4.setDevices();
m =bc4.changeDevice();
m =bc4.changeDevice(); //CDPlayer
m =bc4.changeDevice();
//sixth case
BordComputer bc5 = new BordComputer();
bc5.readConfig();
bc5.setDevices();
m =bc5.changeDevice();
//seventh case
BordComputer bc6 = new BordComputer();
bc6.readConfig();
bc6.setDevices();
m =bc6.changeDevice();
m =bc6.changeDevice();
//eight case
BordComputer bc7 = new BordComputer();
bc7.readConfig();
bc7.setDevices();
m =bc7.changeDevice();
m =bc7.changeDevice();
m =bc7.changeDevice();
return Stream.of(
Arguments.of("The order of the installedDevices should be changed ", bc,currentDevices,null,"",1),
Arguments.of("The active Device should be changed ", bc1,null,prvDevice,"",2),
Arguments.of("The new Device returns a String ", bc2,null,prvDevice,bc2.activeDevice.toString(),3),
Arguments.of("The new Device returns a String ", bc3,null,prvDevice,null,4),
Arguments.of("The new Device returns a String ", bc4,null,prvDevice,null,5),
Arguments.of("The new Device returns Info ", bc5,null,prvDevice,null,6),
Arguments.of("The new Device returns Info ", bc6,null,prvDevice,null,7),
Arguments.of("The new Device returns Info ", bc6,null,prvDevice,null,8)
);
}
} }

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

@ -9,10 +9,9 @@ import java.util.ArrayList;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
class UsbPlayerTest { class UsbPlayerTest {
//UsbPlayer up = new UsbPlayer();
UsbPlayer up = new UsbPlayer();
@ParameterizedTest @ParameterizedTest
@MethodSource("PlayOptions") @MethodSource("PlayOptions")
@ -22,32 +21,11 @@ class UsbPlayerTest {
} }
static Stream<Arguments> PlayOptions() { static Stream<Arguments> PlayOptions() {
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up8 = new UsbPlayer(USBDrive);
up8.setPlayTrack("");
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(USBDrive);
ArrayList<String> Pl = new ArrayList<String>();
up3.setPlaylist(Pl);
UsbPlayer up6 = new UsbPlayer(USBDrive);
up6.setDefect(true);
UsbPlayer up7 = new UsbPlayer(USBDrive);
up7.setConnected(false);
UsbPlayer up1 = new UsbPlayer();
return Stream.of( return Stream.of(
Arguments.of("All right : ", up1, "USB : connected,working,have a list,Audio,point to a track."),
Arguments.of("No first Track : ", up8, "USB : connected,working,have a list,Audio,doesn't point to a track."),
Arguments.of("No Audio Files : ", up2, "USB : connected,working,have a list,not Audio."),
Arguments.of("No list of tracks : ", up3, "USB : connected,working,have no list."),
Arguments.of("connected , not working : ", up6, "USB : connected,not working."),
Arguments.of("not connected : ", up7, "not connected."));
Arguments.of("All right : ", up1, "USB Device plays"));
} }
@ -59,31 +37,14 @@ class UsbPlayerTest {
} }
static Stream<Arguments> louderOptions() { static Stream<Arguments> louderOptions() {
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up11 = new UsbPlayer(USBDrive);
UsbPlayer up11 = new UsbPlayer();
up11.louder(); up11.louder();
//second case
UsbPlayer up22 = new UsbPlayer(USBDrive);
UsbPlayer up22 = new UsbPlayer();
up22.setLautstaerke(100); up22.setLautstaerke(100);
up22.louder(); 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( return Stream.of(
Arguments.of("Volume is : 1 ", up11, 1), 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 unmuted,a change has been made ", up4, 11)
Arguments.of("Volume is : 100 ", up22, 100)
); );
} }
@ -95,33 +56,14 @@ class UsbPlayerTest {
} }
static Stream<Arguments> quieterOptions() { static Stream<Arguments> quieterOptions() {
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up1 = new UsbPlayer();
up1.quieter(); up1.quieter();
//second case
UsbPlayer up2 = new UsbPlayer(USBDrive);
UsbPlayer up2 = new UsbPlayer();
up2.setLautstaerke(10); up2.setLautstaerke(10);
up2.quieter(); 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( return Stream.of(
Arguments.of("Volume must stay 0 ", up1, 0), 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 unmuted,a change has been made ", up4, 9)
Arguments.of("Volume must be 9 ", up2, 9)
); );
} }
@ -134,14 +76,13 @@ class UsbPlayerTest {
} }
static Stream<Arguments> NextOptions() { static Stream<Arguments> NextOptions() {
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up1 = new UsbPlayer();
up1.next(); up1.next();
UsbPlayer up2 = new UsbPlayer(USBDrive);
UsbPlayer up2 = new UsbPlayer();
for (int i = 1; i < up2.getPlaylist().size(); i++) { for (int i = 1; i < up2.getPlaylist().size(); i++) {
up2.next(); up2.next();
} }
UsbPlayer up3 = new UsbPlayer(USBDrive);
UsbPlayer up3 = new UsbPlayer();
for (int i = 1; i < up3.getPlaylist().size(); i++) { for (int i = 1; i < up3.getPlaylist().size(); i++) {
up3.next(); up3.next();
} }
@ -162,10 +103,9 @@ class UsbPlayerTest {
} }
static Stream<Arguments> PrevOptions() { static Stream<Arguments> PrevOptions() {
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up1 = new UsbPlayer();
up1.prev(); up1.prev();
UsbPlayer up2 = new UsbPlayer(USBDrive);
UsbPlayer up2 = new UsbPlayer();
for (int i = 1; i < up2.getPlaylist().size(); i++) {//3 for (int i = 1; i < up2.getPlaylist().size(); i++) {//3
up2.prev(); up2.prev();
} }
@ -185,37 +125,22 @@ class UsbPlayerTest {
} }
static Stream<Arguments> louder_10_Options() { static Stream<Arguments> louder_10_Options() {
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up1 = new UsbPlayer();
up1.Louder_10(); up1.Louder_10();
//Second case
UsbPlayer up2 = new UsbPlayer(USBDrive);
for (int i = 0; i < 3; i++) {
UsbPlayer up2 = new UsbPlayer();
for (int i = 0; i <= 3; i++) {
up2.Louder_10(); up2.Louder_10();
} }
//third case
UsbPlayer up3 = new UsbPlayer(USBDrive);
up2.quieter_10();
UsbPlayer up3 = new UsbPlayer();
up3.setLautstaerke(100); up3.setLautstaerke(100);
up3.Louder_10(); 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( return Stream.of(
Arguments.of("Volume was 0, should be 10 ", up1, 10), Arguments.of("Volume was 0, should be 10 ", up1, 10),
Arguments.of("Volume was 0, should be 30 ", up2, 30), 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 unmuted,a change has been made ", up5, 20)
Arguments.of("Volume was 100, should stay 100 ", up3, 100)
); );
} }
@ -227,38 +152,23 @@ class UsbPlayerTest {
} }
static Stream<Arguments> quieter_10_Options() { static Stream<Arguments> quieter_10_Options() {
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up1 = new UsbPlayer();
up1.setLautstaerke(10); up1.setLautstaerke(10);
up1.quieter_10(); up1.quieter_10();
//second case
UsbPlayer up2 = new UsbPlayer(USBDrive);
UsbPlayer up2 = new UsbPlayer();
up2.setLautstaerke(50); up2.setLautstaerke(50);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
up2.quieter_10(); up2.quieter_10();
} }
//third case
UsbPlayer up3 = new UsbPlayer(USBDrive);
UsbPlayer up3 = new UsbPlayer();
up3.quieter_10(); 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( return Stream.of(
Arguments.of("Volume was 10, should be 0 ", up1, 0), Arguments.of("Volume was 10, should be 0 ", up1, 0),
Arguments.of("Volume was 50, should be 20 ", up2, 20), 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 unmuted,a change has been made ", up5, 1)
Arguments.of("Volume was 0, should stay 0 ", up3, 0)
); );
} }
@ -275,8 +185,7 @@ class UsbPlayerTest {
} }
static Stream<Arguments> FindSongOptions() { static Stream<Arguments> FindSongOptions() {
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up1 = new UsbPlayer();
return Stream.of( return Stream.of(
Arguments.of("The song is not in the Album", up1.findSong("song 4"), -1), 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), Arguments.of("The song is in the Album", up1.findSong("Musik 02"), 1),
@ -293,17 +202,16 @@ class UsbPlayerTest {
} }
static Stream<Arguments> GoToOptions() { static Stream<Arguments> GoToOptions() {
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up1 = new UsbPlayer();
up1.GoTo("Musik 03.mp3"); up1.GoTo("Musik 03.mp3");
UsbPlayer up2 = new UsbPlayer(USBDrive);
UsbPlayer up2 = new UsbPlayer();
up2.GoTo("Musik 04.mp3"); up2.GoTo("Musik 04.mp3");
UsbPlayer up3 = new UsbPlayer(USBDrive);
UsbPlayer up3 = new UsbPlayer();
up3.GoTo("Musik 02"); up3.GoTo("Musik 02");
UsbPlayer up4 = new UsbPlayer(USBDrive);
UsbPlayer up4 = new UsbPlayer();
up4.next(); up4.next();
up4.GoTo("Musik"); up4.GoTo("Musik");
@ -324,46 +232,45 @@ class UsbPlayerTest {
} }
static Stream<Arguments> isAllAudioOptions() { static Stream<Arguments> isAllAudioOptions() {
USB_Stick USBDrive = new USB_Stick();
//mp3 //mp3
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up1 = new UsbPlayer();
//mp4 //mp4
UsbPlayer up2 = new UsbPlayer(USBDrive);
UsbPlayer up2 = new UsbPlayer();
ArrayList<String> Pl = new ArrayList<String>(); ArrayList<String> Pl = new ArrayList<String>();
Pl.add("Musik 01.mp4"); Pl.add("Musik 01.mp4");
Pl.add("Musik 02.mp4"); Pl.add("Musik 02.mp4");
Pl.add("Musik 03.mp4"); Pl.add("Musik 03.mp4");
up2.setPlaylist(Pl); up2.setPlaylist(Pl);
//m4a //m4a
UsbPlayer up3 = new UsbPlayer(USBDrive);
UsbPlayer up3 = new UsbPlayer();
ArrayList<String> Pl1 = new ArrayList<String>(); ArrayList<String> Pl1 = new ArrayList<String>();
Pl1.add("Musik 01.m4a"); Pl1.add("Musik 01.m4a");
Pl1.add("Musik 02.m4a"); Pl1.add("Musik 02.m4a");
Pl1.add("Musik 03.m4a"); Pl1.add("Musik 03.m4a");
up3.setPlaylist(Pl1); up3.setPlaylist(Pl1);
//wav //wav
UsbPlayer up4 = new UsbPlayer(USBDrive);
UsbPlayer up4 = new UsbPlayer();
ArrayList<String> Pl2 = new ArrayList<String>(); ArrayList<String> Pl2 = new ArrayList<String>();
Pl2.add("Musik 01.wav"); Pl2.add("Musik 01.wav");
Pl2.add("Musik 02.wav"); Pl2.add("Musik 02.wav");
Pl2.add("Musik 03.wav"); Pl2.add("Musik 03.wav");
up4.setPlaylist(Pl2); up4.setPlaylist(Pl2);
//wma //wma
UsbPlayer up5 = new UsbPlayer(USBDrive);
UsbPlayer up5 = new UsbPlayer();
ArrayList<String> Pl3 = new ArrayList<String>(); ArrayList<String> Pl3 = new ArrayList<String>();
Pl3.add("Musik 01.wma"); Pl3.add("Musik 01.wma");
Pl3.add("Musik 02.wma"); Pl3.add("Musik 02.wma");
Pl3.add("Musik 03.wma"); Pl3.add("Musik 03.wma");
up5.setPlaylist(Pl3); up5.setPlaylist(Pl3);
//aac //aac
UsbPlayer up6 = new UsbPlayer(USBDrive);
UsbPlayer up6 = new UsbPlayer();
ArrayList<String> Pl4 = new ArrayList<String>(); ArrayList<String> Pl4 = new ArrayList<String>();
Pl4.add("Musik 01.aac"); Pl4.add("Musik 01.aac");
Pl4.add("Musik 02.aac"); Pl4.add("Musik 02.aac");
Pl4.add("Musik 03.aac"); Pl4.add("Musik 03.aac");
up6.setPlaylist(Pl4); up6.setPlaylist(Pl4);
//mixed Audio and text Files in the Album //mixed Audio and text Files in the Album
UsbPlayer up7 = new UsbPlayer(USBDrive);
UsbPlayer up7 = new UsbPlayer();
ArrayList<String> Pl5 = new ArrayList<String>(); ArrayList<String> Pl5 = new ArrayList<String>();
Pl5.add("Musik 01.aac"); Pl5.add("Musik 01.aac");
Pl5.add("Musik 02.txt"); Pl5.add("Musik 02.txt");
@ -387,26 +294,25 @@ class UsbPlayerTest {
@MethodSource("GoToFirstOptions") @MethodSource("GoToFirstOptions")
void GoToFirstTest(String testName, UsbPlayer inputUSB, String expectedResult) { void GoToFirstTest(String testName, UsbPlayer inputUSB, String expectedResult) {
String firstSong = inputUSB.getPlayTrack(); String firstSong = inputUSB.getPlayTrack();
assertThat(firstSong).describedAs(testName).isEqualTo(expectedResult);
assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult);
} }
static Stream<Arguments> GoToFirstOptions() { static Stream<Arguments> GoToFirstOptions() {
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up1 = new UsbPlayer();
up1.GoToFirst(); up1.GoToFirst();
UsbPlayer up2 = new UsbPlayer(USBDrive);
UsbPlayer up2 = new UsbPlayer();
up2.GoToFirst(); up2.GoToFirst();
up2.GoToFirst(); up2.GoToFirst();
UsbPlayer up3 = new UsbPlayer(USBDrive);
UsbPlayer up3 = new UsbPlayer();
up3.next(); up3.next();
up3.GoToFirst(); up3.GoToFirst();
return Stream.of( 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,28 +320,27 @@ class UsbPlayerTest {
@MethodSource("GoToLastOptions") @MethodSource("GoToLastOptions")
void GoToLastTest(String testName, UsbPlayer inputUSB, String expectedResult) { void GoToLastTest(String testName, UsbPlayer inputUSB, String expectedResult) {
String firstSong = inputUSB.getPlayTrack(); String firstSong = inputUSB.getPlayTrack();
assertThat(firstSong).describedAs(testName).isEqualTo(expectedResult);
assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult);
} }
static Stream<Arguments> GoToLastOptions() { static Stream<Arguments> GoToLastOptions() {
USB_Stick USBDrive = new USB_Stick();
//first case //first case
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up1 = new UsbPlayer();
up1.GoToLast(); up1.GoToLast();
UsbPlayer up2 = new UsbPlayer(USBDrive);
UsbPlayer up2 = new UsbPlayer();
up2.GoToLast(); up2.GoToLast();
up2.GoToLast(); up2.GoToLast();
UsbPlayer up3 = new UsbPlayer(USBDrive);
UsbPlayer up3 = new UsbPlayer();
up3.next(); up3.next();
up3.GoToLast(); up3.GoToLast();
return Stream.of( 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,148 +348,26 @@ class UsbPlayerTest {
@MethodSource("setPlayTrackOptions") @MethodSource("setPlayTrackOptions")
void setPlayTrackTest(String testName, UsbPlayer inputUSB, String expectedResult) { void setPlayTrackTest(String testName, UsbPlayer inputUSB, String expectedResult) {
String firstSong = inputUSB.getPlayTrack(); String firstSong = inputUSB.getPlayTrack();
assertThat(firstSong).describedAs(testName).isEqualTo(expectedResult);
assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult);
} }
static Stream<Arguments> setPlayTrackOptions() { static Stream<Arguments> setPlayTrackOptions() {
USB_Stick USBDrive = new USB_Stick();
//first case //first case
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up1 = new UsbPlayer();
up1.setPlayTrack("Musik 02.mp3"); up1.setPlayTrack("Musik 02.mp3");
//Second Case //Second Case
UsbPlayer up2 = new UsbPlayer(USBDrive);
UsbPlayer up2 = new UsbPlayer();
up2.setPlayTrack("Musik 02.mp3"); up2.setPlayTrack("Musik 02.mp3");
//Third Case //Third Case
UsbPlayer up3 = new UsbPlayer(USBDrive);
UsbPlayer up3 = new UsbPlayer();
up3.setPlayTrack("Musik 04.mp3"); up3.setPlayTrack("Musik 04.mp3");
return Stream.of( 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")
);
}////
@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)
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")
); );
} }
Loading…
Cancel
Save