68 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
Jenkins f3035b6b2f Merge commit '9c4084e47940870dd0b38e6ad15b0be0b2820bd3' into HEAD 3 years ago
JPANZO 9c4084e479 Method mute of CDPlayer tested on 6x louder()-> mute() -> getOldVolumeShouldReturn_0. 3 years ago
JPANZO 9836e3a26c Method mute of CDPlayer tested on 5x louder()-> mute() -> getVolumeShouldReturn_5. 3 years ago
JPANZO d26513380d Method mute of CDPlayer tested on checkingTheEffectAfterRun -> VariableMutedShouldBeFalse. 3 years ago
JPANZO 5b1c8e9101 Method mute of CDPlayer tested on checkingTheReturnValue -> ShouldReturnAString. 3 years ago
JPANZO 9d7abe2b43 Method mute of CDPlayer tested after 5x louder() by checkingTheSavedOldVolume -> getOldVolumeShouldReturns_5. 3 years ago
JPANZO aaee24a3c5 Method mute of CDPlayer tested after 2x louder() by checkingTheVolume -> VolumeShouldBeSetTo0. 3 years ago
JPANZO c0ed52776b Method mute of CDPlayer tested on checkingTheEffectAfterRun -> VariableMutedShouldBeTrue. 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
JPANZO 3f1d220ac8 Method mute of CDPlayer tested on checkingTheReturnValue -> ShouldReturnAString. 3 years ago
sahar a7c3ea8610 UsbPlayerTest.unmuteTest second Case 3 years ago
sahar 947a842f6d UsbPlayerTest.unmuteTest first Case 3 years ago
Jenkins fa0526cffb Merge commit '067a5c3d70fb8706e80667a50cd73ba67ae1289d' into HEAD 3 years ago
JPANZO 067a5c3d70 Method addToFavoriteSongs of CDPlayer tested on NotSelectingCDWechseler -> shouldThrowAnException. 3 years ago
sahar 20727f6e60 UsbPlayerTest.muteTest third Case 3 years ago
sahar 802a780a4e UsbPlayerTest.muteTest Second Case 3 years ago
JPANZO 9e5960da87 Method addToFavoriteSongs of CDPlayer tested on addingDuplicatedSong -> SongShouldNotBeAdded. 3 years ago
JPANZO 15385d3b4c Method addToFavoriteSongs of CDPlayer tested on addingOneSong -> favoriteSongsShouldReturnsThatAddedSong. 3 years ago
sahar 717120b972 UsbPlayerTest.getInfoTextTest Second Case 3 years ago
Jenkins 7ba3489caa Merge commit '2e2be94402cadfa3ff2ff9b2a80e2ac4825c823c' into HEAD 3 years ago
Jenkins c7748f03db Merge commit 'ab054d5dfe53df9290ccd26a825841ff2f353e41' into HEAD 3 years ago
Jan Ortner ab054d5dfe revised all test for setDevices now testing if every installed devices has the right instance & added productive code 3 years ago
sahar 69cbbf90fa UsbPlayerTest.getInfoTextTest First Case 3 years ago
JPANZO 2e2be94402 Method changeToNextCD of CDPlayer tested changing_from_last_to_first CD -> FirstCDShouldBeTaken. 3 years ago
Jan Ortner 4bd3d5acd2 added second and third test case for setDevices() & productive code 3 years ago
Jan Ortner 9913b17554 added fifth test case for readConfig() & productive code 3 years ago
JPANZO b307012590 Method changeToNextCD of CDPlayer tested checking the effect2 -> loadedCDShouldNotHaveTheSameIdAsPrev. 3 years ago
Jenkins 7a36cad435 Merge commit 'b6a718f728bf18ae29019f809fe35852c7a1acc5' into HEAD 3 years ago
Jan Ortner b6a718f728 added third & fourth test for readConfig & productive code 3 years ago
Jan Ortner 0fd42ce65a added second test for readConfig & productive code 3 years ago
Jan Ortner 5c1b1bd8a2 added BordComputer & BordComputerTest 3 years ago
JPANZO f77ed10d41 Method changeToNextCD of CDPlayer tested checking the effect -> loadedCDShouldNotReturnNull. 3 years ago
JPANZO 3d0f3997f2 Method changeToNextCD of CDPlayer tested on CDWechselerNotSelected -> shouldThrowAnException. 3 years ago
Jenkins ec60931dab Merge commit '7c7ae70a2b179b0cce12df32f2f06dd9664d16e4' into HEAD 3 years ago
JPANZO 7c7ae70a2b Method loadCDWechseler of CDPlayer tested on MaxCapacityExceeded:Max=10 -> shouldThrowAnException. 3 years ago
JPANZO e6741fd092 Method loadCDWechseler of CDPlayer tested on leadingFirstCD -> CDListOfCDWechselerShouldHaveLength1. 3 years ago
JPANZO 77ce33d615 Method loadCDWechseler of CDPlayer tested on WrongCDFormat -> shouldThrowAnException. 3 years ago
JPANZO 29aa121c19 Method loadCDWechseler of CDPlayer tested on notRunning=CDWechseler -> shouldThrowAnException. 3 years ago
JPANZO 7faf0d78e2 Method changePlaySource of CDPlayer tested on activeSource=CDWechseler -> shouldReturnCDDrive. 3 years ago
JPANZO 43f556fa6f Method changePlaySource of CDPlayer tested on activeSource=CDDrive -> shouldReturnCDWechseler. 3 years ago
JPANZO 34b14f3e87 Method chooseItem of CDPlayer tested on validInput->shouldReturnMsgWithinTheItemNr. 3 years ago
JPANZO 1fb89934b1 Method chooseItem of CDPlayer tested on invalidInput->negativeNumber. 3 years ago
JPANZO aac81d6b22 Method chooseItem of CDPlayer tested on invalidInput->greater than PlayListSize. 3 years ago
JPANZO 87a0723a68 Method chooseItem of CDPlayer tested on notSetCD. 3 years ago
Jenkins 2148801828 Merge commit '5885370fe321bede908b3baf3990fc0e9282dca3' into HEAD 3 years ago
Jan Ortner 5885370fe3 revised test for RadioPlayer getAntenneBYInfoByTime() 3 years ago
Jan Ortner 089fa0144f revised test for RadioPlayer getBR3InfoByTime() 3 years ago
Jan Ortner fc98df250d revised test for RadioPlayer getYouFMInfoByTime() 3 years ago
Jenkins c78b7dd6f4 Merge commit '32b80ec46d26c94ee1fc05658214d1b2b1874de4' into HEAD 3 years ago
  1. 2
      Geraete.config
  2. 38
      src/main/java/BordComputer.java
  3. 16
      src/main/java/device/cdPlayer/CD.java
  4. 92
      src/main/java/device/cdPlayer/CDPlayer.java
  5. 26
      src/main/java/device/cdPlayer/CDWechseler.java
  6. 8
      src/main/java/device/cdPlayer/exceptions/CDWechselerNotRunningException.java
  7. 7
      src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java
  8. 7
      src/main/java/device/cdPlayer/exceptions/ItemNumberNotFoundException.java
  9. 7
      src/main/java/device/cdPlayer/exceptions/MaxCapacityExceededException.java
  10. 7
      src/main/java/device/cdPlayer/exceptions/NegativeInputException.java
  11. 9
      src/main/java/device/usbPlayer/USB_Stick.java
  12. 65
      src/main/java/device/usbPlayer/UsbPlayer.java
  13. 84
      src/test/java/BordComputerTest.java
  14. 278
      src/test/java/device/cdPlayer/CDPlayerTest.java
  15. 60
      src/test/java/device/radioPlayer/RadioPlayerTest.java
  16. 3
      src/test/java/device/usbPlayer/USB_StickTest.java
  17. 303
      src/test/java/device/usbPlayer/UsbPlayerTest.java

2
Geraete.config

@ -1,4 +1,4 @@
CD=device.cdPlayer.CdPlayer
CD=device.cdPlayer.CDPlayer
Radio=device.radioPlayer.RadioPlayer Radio=device.radioPlayer.RadioPlayer
USB=device.usbPlayer.UsbPlayer USB=device.usbPlayer.UsbPlayer

38
src/main/java/BordComputer.java

@ -0,0 +1,38 @@
import device.Device;
import java.io.FileReader;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Properties;
public class BordComputer {
String[] deviceNames;
Device[] installedDevices;
Device activeDevice = null;
public void readConfig() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
try (FileReader reader = new FileReader("Geraete.config")) {
Properties properties = new Properties();
properties.load(reader);
String[] values = properties.values().toArray(new String[0]);
Arrays.sort(values);
deviceNames = new String[values.length];
System.arraycopy(values, 0, deviceNames, 0, properties.size());
installedDevices = new Device[values.length];
} catch (Exception e) {
e.printStackTrace();
}
setDevices();
activeDevice = installedDevices[0];
}
public void setDevices() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ClassNotFoundException {
Class<?> c;
for (int i = 0; i < deviceNames.length; i++) {
c = Class.forName(deviceNames[i]);
installedDevices[i] = (Device) c.getConstructor().newInstance();
}
}
}

16
src/main/java/device/cdPlayer/CD.java

@ -4,6 +4,7 @@ public class CD {
private String format; private String format;
private String albumName; private String albumName;
private String[] playList; private String[] playList;
private String id;
public CD() {} public CD() {}
@ -16,6 +17,13 @@ public class CD {
this.playList = playList; this.playList = playList;
} }
public CD(String format, String albumName, String[] playList, String id) {
this.format = format;
this.albumName = albumName;
this.playList = playList;
this.id = id;
}
public String getFormat() { public String getFormat() {
return format; return format;
} }
@ -39,4 +47,12 @@ public class CD {
public void setAlbumName(String albumName) { public void setAlbumName(String albumName) {
this.albumName = albumName; this.albumName = albumName;
} }
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
} }

92
src/main/java/device/cdPlayer/CDPlayer.java

@ -18,7 +18,15 @@ public class CDPlayer implements Device {
private List<String> supportedFormats = new ArrayList<String>(Arrays.asList(new String[] {"Audio","MP3","WMA","AAC"})); private List<String> supportedFormats = new ArrayList<String>(Arrays.asList(new String[] {"Audio","MP3","WMA","AAC"}));
private String actualPlayTrack=""; private String actualPlayTrack="";
private CD loadedCD;
private CD loadedCD=null;
private CDWechseler cdWechseler=null;
private String activeSource="CDDrive";//or CDWechseler
private List<String>favoriteSongs=new ArrayList<>();
private boolean muted=false;
private int oldVolume=0;
@Override @Override
public void louder() { public void louder() {
@ -48,9 +56,7 @@ public class CDPlayer implements Device {
List<String> playList = Arrays.asList(loadedCD.getPlayList()); List<String> playList = Arrays.asList(loadedCD.getPlayList());
int indexOfActualPlayTrack=playList.indexOf(actualPlayTrack); int indexOfActualPlayTrack=playList.indexOf(actualPlayTrack);
int indexOfNextPlayTrack=(indexOfActualPlayTrack+1)%loadedCD.getPlayList().length; int indexOfNextPlayTrack=(indexOfActualPlayTrack+1)%loadedCD.getPlayList().length;
//System.out.println("actualIndex= "+indexOfActualPlayTrack);
this.actualPlayTrack=playList.get(indexOfNextPlayTrack ); this.actualPlayTrack=playList.get(indexOfNextPlayTrack );
//System.out.println("nextSong= "+actualPlayTrack);
} }
@Override @Override
@ -86,7 +92,17 @@ public class CDPlayer implements Device {
@Override @Override
public String chooseItem(int itemNr) { public String chooseItem(int itemNr) {
return null;
if(this.loadedCD==null){
throw new ReturnValueNullException();
}
if(itemNr<0){
throw new NegativeInputException();
}
if(!(itemNr>=0 && itemNr<loadedCD.getPlayList().length)){
throw new ItemNumberNotFoundException();
}
return loadedCD.getPlayList()[itemNr];
} }
@Override @Override
@ -96,12 +112,18 @@ public class CDPlayer implements Device {
@Override @Override
public String mute() { public String mute() {
return null;
muted=true;
oldVolume=volume;
volume=0;
return ("Volume muted.");
} }
@Override @Override
public String unmute() { public String unmute() {
return null;
muted=false;
volume=oldVolume;
oldVolume=0;
return ("Volume unmute.");
} }
@Override @Override
@ -121,6 +143,46 @@ public class CDPlayer implements Device {
} }
return null; return null;
} }
public String changePlaySource(){
if(activeSource.equals("CDDrive")) {
this.activeSource = "CDWechseler";
this.cdWechseler=new CDWechseler();
this.cdWechseler.activate();
}else this.activeSource="CDDrive";
return activeSource;
}
public void loadCDWechseler(CD cd,int index){
if(cdWechseler==null||!cdWechseler.isRunning()){
throw new CDWechselerNotRunningException();
}
if(!(this.supportedFormats.contains(cd.getFormat()))){
throw new FormatNotSupportedException();
}
if(index>10){
throw new MaxCapacityExceededException();
}
cdWechseler.loadOneCD(cd,index);
this.loadedCD=cdWechseler.getCDList().get(0);
}
public void changeToNextCD(){
if(activeSource.equals("CDDrive")){
throw new ChangeCDOnlyOnCDWechselerException();
}
List<CD> CDList = cdWechseler.getCDList();
int indexOfLoadedCD=CDList.indexOf(loadedCD);
int nextIndex=(indexOfLoadedCD+1)%CDList.size();
this.loadedCD=CDList.get(nextIndex);
}
public void addToFavoriteSongs(String song){
if(activeSource.equals("CDDrive")){
throw new CDWechselerNotRunningException();
}
if(!(favoriteSongs.contains(song))) {
favoriteSongs.add(song);
}
}
//Getters, Setters und SupportMethods //Getters, Setters und SupportMethods
public void setCD(CD _loadedCD) { public void setCD(CD _loadedCD) {
@ -165,8 +227,24 @@ public class CDPlayer implements Device {
this.infoText=this.getClass().getSimpleName()+": Item->"+actualPlayTrack+" from Album->"+this.loadedCD.getAlbumName()+" running."; this.infoText=this.getClass().getSimpleName()+": Item->"+actualPlayTrack+" from Album->"+this.loadedCD.getAlbumName()+" running.";
} }
public CD getCD() { public CD getCD() {
return this.loadedCD; return this.loadedCD;
} }
public CDWechseler getCdWechseler() {
return cdWechseler;
}
public List<String> getFavoriteSongs() {
return favoriteSongs;
}
public boolean isMuted() {
return muted;
}
public int getOldVolume() {
return oldVolume;
}
} }

26
src/main/java/device/cdPlayer/CDWechseler.java

@ -0,0 +1,26 @@
package device.cdPlayer;
import java.util.ArrayList;
import java.util.List;
public class CDWechseler {
private List<CD> CDList=new ArrayList<>();
private boolean running=false;
public boolean isRunning() {
return running;
}
public void activate() {
this.running = true;
}
public List<CD> getCDList() {
return CDList;
}
public void loadOneCD(CD cd, int index){
CDList.add(cd);
}
}

8
src/main/java/device/cdPlayer/exceptions/CDWechselerNotRunningException.java

@ -0,0 +1,8 @@
package device.cdPlayer.exceptions;
public class CDWechselerNotRunningException extends RuntimeException {
public CDWechselerNotRunningException() {
super("CDWechseler must be active for using.");
}
}

7
src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java

@ -0,0 +1,7 @@
package device.cdPlayer.exceptions;
public class ChangeCDOnlyOnCDWechselerException extends RuntimeException{
public ChangeCDOnlyOnCDWechselerException(){
super("Change to next CD olny when CDWechseler is selected");
}
}

7
src/main/java/device/cdPlayer/exceptions/ItemNumberNotFoundException.java

@ -0,0 +1,7 @@
package device.cdPlayer.exceptions;
public class ItemNumberNotFoundException extends RuntimeException {
public ItemNumberNotFoundException() {
super("Given ItemNumber ist not in the Album.");
}
}

7
src/main/java/device/cdPlayer/exceptions/MaxCapacityExceededException.java

@ -0,0 +1,7 @@
package device.cdPlayer.exceptions;
public class MaxCapacityExceededException extends RuntimeException{
public MaxCapacityExceededException(){
super("Max capacity of 10-CDs is already exceeded.");
}
}

7
src/main/java/device/cdPlayer/exceptions/NegativeInputException.java

@ -0,0 +1,7 @@
package device.cdPlayer.exceptions;
public class NegativeInputException extends RuntimeException{
public NegativeInputException() {
super("InputNumber must be positive.");
}
}

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

@ -39,14 +39,19 @@ public class USB_Stick {
USB_Stick(String a){ USB_Stick(String a){
}
USB_Stick(ArrayList<String> a1) {
Folders.add(a1);
currentAlbum = 0;
} }
public ArrayList<String> getAlbum() throws NoFolderFound{ public ArrayList<String> getAlbum() throws NoFolderFound{
if(Folders.size()==0) { if(Folders.size()==0) {
System.out.println("list ist leer");
throw new NoFolderFound("The USB Drive is empty"); throw new NoFolderFound("The USB Drive is empty");
} }
else { else {
System.out.println("nicht leer");
return Folders.get(currentAlbum); return Folders.get(currentAlbum);
} }
} }

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

@ -2,6 +2,7 @@ package device.usbPlayer;
import device.Device; import device.Device;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
public class UsbPlayer implements Device { public class UsbPlayer implements Device {
@ -12,6 +13,8 @@ public class UsbPlayer implements Device {
private Boolean isConnected; private Boolean isConnected;
private Boolean isDefect; private Boolean isDefect;
int Lautstaerke = 0; int Lautstaerke = 0;
int soundWas = -1;
public USB_Stick USBDrive = new USB_Stick(); public USB_Stick USBDrive = new USB_Stick();
public ArrayList<String> getPlaylist() { public ArrayList<String> getPlaylist() {
@ -60,8 +63,10 @@ public class UsbPlayer implements Device {
return Lautstaerke; return Lautstaerke;
} }
public UsbPlayer() {}
//*********constructure******** //*********constructure********
public UsbPlayer() {
public UsbPlayer(USB_Stick stick) {
super(); super();
isDefect = false; isDefect = false;
isConnected = true; isConnected = true;
@ -70,11 +75,13 @@ public class UsbPlayer implements Device {
Playlist.add("Musik 03.mp3"); Playlist.add("Musik 03.mp3");
playTrack = Playlist.get(0);*/ playTrack = Playlist.get(0);*/
try { try {
Playlist = USBDrive.getAlbum();
Playlist = stick.getAlbum();
} catch (NoFolderFound e) { } catch (NoFolderFound e) {
e.printStackTrace(); e.printStackTrace();
} }
if (isAllAudio()) {
playTrack = Playlist.get(0); playTrack = Playlist.get(0);
}
} }
@ -100,6 +107,7 @@ public class UsbPlayer implements Device {
//**********search method************* //**********search method*************
@Override @Override
public void quieter() { public void quieter() {
if (this.soundWas == -1) {
if (Lautstaerke > 0) { if (Lautstaerke > 0) {
Lautstaerke -= 1; Lautstaerke -= 1;
} else { } else {
@ -107,32 +115,41 @@ public class UsbPlayer implements Device {
} }
} }
}
@Override @Override
public void louder() { public void louder() {
if (this.soundWas == -1) {
if (Lautstaerke < 100) { if (Lautstaerke < 100) {
Lautstaerke += 1; Lautstaerke += 1;
} else { } else {
Lautstaerke = 100; Lautstaerke = 100;
} }
} }
}
public void Louder_10() { public void Louder_10() {
if (this.soundWas == -1) {
Lautstaerke += 10; Lautstaerke += 10;
if (Lautstaerke > 100) { if (Lautstaerke > 100) {
Lautstaerke = 100; Lautstaerke = 100;
} }
} }
}
public void quieter_10() { public void quieter_10() {
if (this.soundWas == -1) {
Lautstaerke -= 10; Lautstaerke -= 10;
if (Lautstaerke < 0) { if (Lautstaerke < 0) {
Lautstaerke = 0; Lautstaerke = 0;
} }
} }
}
@Override @Override
public int getVolume() { public int getVolume() {
return 0;
return Lautstaerke;
} }
@Override @Override
@ -154,32 +171,60 @@ public class UsbPlayer implements Device {
@Override @Override
public String getInfoText() { 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 @Override
public String[] getOptions() { 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 @Override
public String chooseItem(int itemNr) { 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 @Override
public String[] getItemList() { 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 @Override
public String mute() { public String mute() {
return null;
this.soundWas = getLautstaerke();
setLautstaerke(0);
return "muted";
} }
@Override @Override
public String unmute() { 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 //go to the last Song
setPlayTrack(this.getPlaylist().get(this.getPlaylist().size() - 1)); setPlayTrack(this.getPlaylist().get(this.getPlaylist().size() - 1));
} }
} }

84
src/test/java/BordComputerTest.java

@ -0,0 +1,84 @@
import device.Device;
import device.cdPlayer.CDPlayer;
import device.radioPlayer.RadioPlayer;
import device.usbPlayer.UsbPlayer;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;
import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
class BordComputerTest {
@ParameterizedTest
@MethodSource("readConfigOptions")
void readConfigTest(String testName, String testTyp, BordComputer testBc, String expectedResult) {
if (testTyp.equals("count")) {
assertThat(fileReaderCount()).describedAs(testName).isEqualTo(testBc.deviceNames.length);
}
if (testTyp.equals("count1")) {
assertThat(fileReaderCount()).describedAs(testName).isEqualTo(testBc.installedDevices.length);
}
if (testTyp.equals("item1")) {
assertThat(testBc.deviceNames[0]).describedAs(testName).isEqualTo(expectedResult);
}
if (testTyp.equals("item2")) {
assertThat(testBc.deviceNames[1]).describedAs(testName).isEqualTo(expectedResult);
}
if (testTyp.equals("item3")) {
assertThat(testBc.deviceNames[2]).describedAs(testName).isEqualTo(expectedResult);
}
}
static Stream<Arguments> readConfigOptions() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
BordComputer bc1 = new BordComputer();
bc1.readConfig();
return Stream.of(
Arguments.of("Check if file reader is getting every item in Geraete.config", "count", bc1, ""),
Arguments.of("Check if file reader is getting the first element", "item1", bc1, "device.cdPlayer.CDPlayer"),
Arguments.of("Check if file reader is getting the second element", "item2", bc1, "device.radioPlayer.RadioPlayer"),
Arguments.of("Check if file reader is getting the third element", "item3", bc1, "device.usbPlayer.UsbPlayer"),
Arguments.of("Test if installed devices has the length", "count1", bc1, "")
);
}
@ParameterizedTest
@MethodSource("setDevicesOptions")
void setDevicesTest(String testName, BordComputer testBc, String testTyp, Boolean bool) {
Boolean boolActual = null;
if (testTyp.equals("0")) boolActual = (testBc.installedDevices[0] instanceof CDPlayer);
if (testTyp.equals("1")) boolActual = (testBc.installedDevices[1] instanceof RadioPlayer);
if (testTyp.equals("2")) boolActual = (testBc.installedDevices[2] instanceof UsbPlayer);
assertThat(boolActual).describedAs(testName).isEqualTo(bool);
}
static Stream<Arguments> setDevicesOptions() throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
BordComputer bc = new BordComputer();
bc.readConfig();
return Stream.of(
Arguments.of("Test if installedDevices[0] is instance of CDPlayer", bc, "0", true),
Arguments.of("Test if installedDevices[1] is instance of RadioPlayer", bc, "1", true),
Arguments.of("Test if installedDevices[2] is instance of UsbPlayer", bc, "2", true)
);
}
public int fileReaderCount() {
int count = 0;
try (FileReader reader = new FileReader("Geraete.config")) {
Properties properties = new Properties();
properties.load(reader);
count = properties.size();
} catch (IOException e) {
e.printStackTrace();
}
return count;
}
}

278
src/test/java/device/cdPlayer/CDPlayerTest.java

@ -327,4 +327,282 @@ class CDPlayerTest {
); );
} }
@ParameterizedTest
@MethodSource("chooseItemTestData")
void chooseItemTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception ) {
if(cases.equals("Case1")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(1));
assertEquals(ReturnValueNullException.class, newException.getClass());
}
if(cases.equals("Case2")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(200));
assertEquals(ItemNumberNotFoundException.class, newException.getClass());
}
if(cases.equals("Case3")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(-1));
assertEquals(NegativeInputException.class, newException.getClass());
}
if(cases.equals("Case4")) {
assertThat(_cdPlayer.chooseItem(1).contains("2")).describedAs(testName).isEqualTo(true);
}
}
static Stream<Arguments> chooseItemTestData () {
CDPlayer cdPlayer1 = new CDPlayer();
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"};
CD audioCD1=new CD("Audio",audioPlayList);
CDPlayer cdPlayer2 = new CDPlayer();
cdPlayer2.tapOnCdFlap();
cdPlayer2.setCD(audioCD1);
cdPlayer2.tapOnCdFlap();
return Stream.of(
Arguments.of("[chooseItem() by notSetCD ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException()),
Arguments.of("[chooseItem() by invalidInput ] => shouldThrowItemNumberNotFoundException","Case2", cdPlayer2,new ItemNumberNotFoundException()),
Arguments.of("[chooseItem() by invalidInput:negativeNumber] => shouldThrowItemNumberNotFoundException","Case3", cdPlayer2,new NegativeInputException()),
Arguments.of("[chooseItem() by validInput] => shouldReturnMsgWithinTheItemNr","Case4", cdPlayer2,null)
);
}
@ParameterizedTest
@MethodSource("changePlaySourceData")
void changePlaySourceTest(String testName,String cases, CDPlayer _cdPlayer) {
if(cases.equals("Case1")) {
String returnVal = _cdPlayer.changePlaySource();
assertThat(returnVal).describedAs(testName).isEqualTo("CDWechseler");
}
if(cases.equals("Case2")) {
String returnVal = _cdPlayer.changePlaySource();
assertThat(returnVal).describedAs(testName).isEqualTo("CDDrive");
}
}
static Stream<Arguments> changePlaySourceData () {
CDPlayer cdPlayer1 = new CDPlayer();
CDPlayer cdPlayer2 = new CDPlayer();
cdPlayer2.changePlaySource();
return Stream.of(
Arguments.of("[changePlaySource() by activeSource=CDDrive ] => shouldReturnCDWechseler","Case1", cdPlayer1),
Arguments.of("[changePlaySource() by activeSource=CDWechseler ] => shouldReturnCDDrive","Case2", cdPlayer2)
);
}
@ParameterizedTest
@MethodSource("loadCDWechselerData")
void loadCDWechselerTest(String testName,String cases, CDPlayer _cdPlayer,CD cd,Exception exception) {
if(cases.equals("Case1")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd,0));
assertEquals(CDWechselerNotRunningException.class, newException.getClass());
}
if(cases.equals("Case2")) {
_cdPlayer.changePlaySource();
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd,0));
assertEquals(FormatNotSupportedException.class, newException.getClass());
}
if(cases.equals("Case3")) {
_cdPlayer.changePlaySource();
_cdPlayer.loadCDWechseler(cd,0);
CD firstCD=_cdPlayer.getCdWechseler().getCDList().get(0);
assertThat(firstCD).describedAs(testName).isNotEqualTo(null);
}
if(cases.equals("Case4")) {
_cdPlayer.changePlaySource();
Exception newException=assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd, 12));
assertEquals(MaxCapacityExceededException.class, newException.getClass());
}
}
static Stream<Arguments> loadCDWechselerData () {
CDPlayer cdPlayer1 = new CDPlayer();
String[] videoPlayList=new String[]{"Video 01","Video 02","Video 03","Video 04","Video 05"};
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"};
CD audioCD1=new CD("Audio",audioPlayList);
CD DVD=new CD("DVD",videoPlayList);
return Stream.of(
Arguments.of("[loadCDWechseler() by notRunning=CDWechseler ] => shouldThrowAnException", "Case1", cdPlayer1,audioCD1,new CDWechselerNotRunningException()),
Arguments.of("[loadCDWechseler() by WrongCDFormat ] => shouldThrowAnException", "Case2", cdPlayer1,DVD,new FormatNotSupportedException()),
Arguments.of("[loadCDWechseler() by leadingFirstCD ] => CDListOfCDWechselerShouldHaveLength1", "Case3", cdPlayer1,audioCD1,null),
Arguments.of("[loadCDWechseler() by MaxCapacityExceeded:Max=10 ] => shouldThrowAnException", "Case4", cdPlayer1,audioCD1,new MaxCapacityExceededException())
);
}
@ParameterizedTest
@MethodSource("changeToNextCDData")
void changeToNextCDTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception) {
if(cases.equals("Case1")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.changeToNextCD());
assertEquals(ChangeCDOnlyOnCDWechselerException.class, newException.getClass());
}
if(cases.equals("Case2")) {
CD actualCD=_cdPlayer.getCD();
_cdPlayer.changeToNextCD();
CD nextCD=_cdPlayer.getCD();
assertThat(nextCD).describedAs(testName).isNotEqualTo(null);
}
if(cases.equals("Case3")) {
CD actualCD=_cdPlayer.getCD();
_cdPlayer.changeToNextCD();
CD nextCD=_cdPlayer.getCD();
assertThat(nextCD.getId()==actualCD.getId()).describedAs(testName).isNotEqualTo(true);
}
if(cases.equals("Case4")) {
CD actualCdBefore=_cdPlayer.getCD();
for (int i = 0; i <3 ; i++) {
_cdPlayer.changeToNextCD();
}
CD actualCdAfter=_cdPlayer.getCD();
assertThat(actualCdBefore.getId()==actualCdAfter.getId()).describedAs(testName).isEqualTo(true);
}
}
static Stream<Arguments> changeToNextCDData () {
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"};
CD audioCD1=new CD("Audio","PopMusic",audioPlayList,"XAc20044");
CD audioCD2=new CD("Audio","RockMusic",audioPlayList,"BLXPP78");
CD audioCD3=new CD("Audio","SalsaMusic",audioPlayList,"KKRP118");
CDPlayer cdPlayer1 = new CDPlayer();
CDPlayer cdPlayer2 = new CDPlayer();
cdPlayer2.changePlaySource();
cdPlayer2.loadCDWechseler(audioCD1,0);
cdPlayer2.loadCDWechseler(audioCD2,1);
cdPlayer2.loadCDWechseler(audioCD3,2);
CDPlayer cdPlayer3 = new CDPlayer();
cdPlayer3.changePlaySource();
cdPlayer3.loadCDWechseler(audioCD1,0);
cdPlayer3.loadCDWechseler(audioCD2,1);
cdPlayer3.loadCDWechseler(audioCD3,2);
CDPlayer cdPlayer4 = new CDPlayer();
cdPlayer4.changePlaySource();
cdPlayer4.loadCDWechseler(audioCD1,0);
cdPlayer4.loadCDWechseler(audioCD2,1);
cdPlayer4.loadCDWechseler(audioCD3,2);
return Stream.of(
Arguments.of("[changeToNextCD() by CDWechselerNotSelected ] => shouldThrowAnException", "Case1", cdPlayer1,new ChangeCDOnlyOnCDWechselerException()),
Arguments.of("[changeToNextCD() checking the effect ] => loadedCDShouldNotReturnNull", "Case2", cdPlayer2,null),
Arguments.of("[changeToNextCD() checking the effect 2 ] => loadedCDShouldNotHaveTheSameIdAsPrev", "Case3", cdPlayer3,null),
Arguments.of("[3x changeToNextCD() changing from last to first CD] => FirstCDShouldBeTaken", "Case4", cdPlayer4,null)
);
}
@ParameterizedTest
@MethodSource("addToFavoriteSongsData")
void addToFavoriteSongsTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception) {
if(cases.equals("Case1")) {
String myFavoriteSong = _cdPlayer.getCD().getPlayList()[0];
_cdPlayer.addToFavoriteSongs(myFavoriteSong);
assertThat(_cdPlayer.getFavoriteSongs().get(0)).describedAs(testName).isEqualTo(myFavoriteSong);
}
if(cases.equals("Case2")) {
String myFavoriteSong1 = _cdPlayer.getCD().getPlayList()[0];
String myFavoriteSong2 = _cdPlayer.getCD().getPlayList()[0];
_cdPlayer.addToFavoriteSongs(myFavoriteSong1);
_cdPlayer.addToFavoriteSongs(myFavoriteSong2);
assertThat(_cdPlayer.getFavoriteSongs().size()>1).describedAs(testName).isNotEqualTo(true);
}
if(cases.equals("Case3")) {
String myFavoriteSong1 = _cdPlayer.getCD().getPlayList()[0];
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.addToFavoriteSongs(myFavoriteSong1));
assertEquals(CDWechselerNotRunningException.class, newException.getClass());
}
}
static Stream<Arguments> addToFavoriteSongsData () {
String[] audioPlayList = new String[]{"Audio 01", "Audio 02", "Audio 03", "Audio 04", "Audio 05"};
CD audioCD1 = new CD("Audio", "PopMusic", audioPlayList, "XAc20044");
CD audioCD2=new CD("Audio","RockMusic",audioPlayList,"BLXPP78");
CDPlayer cdPlayer1 = new CDPlayer();
cdPlayer1.changePlaySource();
cdPlayer1.loadCDWechseler(audioCD1, 0);
cdPlayer1.loadCDWechseler(audioCD2, 1);
CDPlayer cdPlayer2 = new CDPlayer();
cdPlayer2.setCD(audioCD2);
return Stream.of(
Arguments.of("[addToFavoriteSongs() by addingOneSong] => favoriteSongsShouldReturnsThatAddedSong", "Case1", cdPlayer1, null),
Arguments.of("[addToFavoriteSongs() by addingDuplicatedSong] => SongShouldNotBeAdded", "Case2", cdPlayer1, null),
Arguments.of("[addToFavoriteSongs() by NotSelectingCDWechseler] => shouldThrowAnException", "Case3", cdPlayer2, new CDWechselerNotRunningException())
);
}
@ParameterizedTest
@MethodSource("muteTestData")
void muteTest(String testName,String cases, CDPlayer _cdPlayer,String expectedResult) {
if(cases.equals("Case1")) {
assertThat(_cdPlayer.mute()).describedAs(testName).isEqualTo(expectedResult);
}
if(cases.equals("Case2")) {
_cdPlayer.mute();
assertThat(_cdPlayer.isMuted()).describedAs(testName).isEqualTo(true);
}
if(cases.equals("Case3")) {
_cdPlayer.louder();
_cdPlayer.louder();
_cdPlayer.mute();
assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(0);
}
if(cases.equals("Case4")) {
for (int i = 0; i < 5; i++) {
_cdPlayer.louder();
}
_cdPlayer.mute();
assertThat(_cdPlayer.getOldVolume()).describedAs(testName).isEqualTo(5);
}
}
static Stream<Arguments> muteTestData () {
CDPlayer cdPlayer1 = new CDPlayer();
return Stream.of(
Arguments.of("[mute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume muted."),
Arguments.of("[mute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeTrue", "Case2", cdPlayer1, "Volume muted."),
Arguments.of("[mute() after 2x louder() by checkingTheVolume] => VolumeShouldBeSetTo0", "Case3", cdPlayer1, "Volume muted."),
Arguments.of("[mute() after 5x louder() by checkingTheSavedOldVolume] => getOldVolumeShouldReturns_5", "Case4", cdPlayer1, "Volume muted.")
);
}
@ParameterizedTest
@MethodSource("unmuteTestData")
void unmuteTest(String testName,String cases, CDPlayer _cdPlayer,String expectedResult) {
if(cases.equals("Case1")) {
assertThat(_cdPlayer.unmute()).describedAs(testName).isEqualTo(expectedResult);
}
if(cases.equals("Case2")) {
_cdPlayer.unmute();
assertThat(_cdPlayer.isMuted()).describedAs(testName).isEqualTo(false);
}
if(cases.equals("Case3")) {
for (int i = 0; i < 5; i++) {
_cdPlayer.louder();
}
_cdPlayer.mute();
_cdPlayer.unmute();
assertThat(_cdPlayer.isMuted()).describedAs(testName).isEqualTo(false);
assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(5);
}
if(cases.equals("Case4")) {
for (int i = 0; i < 6; i++) {
_cdPlayer.louder();
}
_cdPlayer.mute();
_cdPlayer.unmute();
assertThat(_cdPlayer.isMuted()).describedAs(testName).isEqualTo(false);
assertThat(_cdPlayer.getOldVolume()).describedAs(testName).isEqualTo(0);
}
}
static Stream<Arguments> unmuteTestData () {
CDPlayer cdPlayer1 = new CDPlayer();
return Stream.of(
Arguments.of("[unmute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume unmute."),
Arguments.of("[unmute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeFalse", "Case2", cdPlayer1, "Volume unmute."),
Arguments.of("[unmute() by 5x louder()-> mute()] => getVolumeShouldReturn_5", "Case3", cdPlayer1, "Volume unmute."),
Arguments.of("[unmute() by 6x louder()-> mute()] => getOldVolumeShouldReturn_0", "Case4", cdPlayer1, "Volume unmute.")
);
}
} }

60
src/test/java/device/radioPlayer/RadioPlayerTest.java

@ -101,40 +101,38 @@ class RadioPlayerTest {
); );
} }
@Test
void YouFMInfoByTimeTest() {
RadioPlayer rp = new RadioPlayer();
assertThat(rp.getYouFMInfoByTime(8)).describedAs("YouFM info by Time at 8.00").isEqualTo("YOUFM Good Morning Show");
}
@Test
void YouFMInfoByTime2Test() {
RadioPlayer rp = new RadioPlayer();
assertThat(rp.getYouFMInfoByTime(3)).describedAs("YouFM info by Time at 3.00").isEqualTo("YOUFM Junge Nacht der ARD");
}
@Test
void AntenneBYInfoByTimeTest() {
RadioPlayer rp = new RadioPlayer();
assertThat(rp.getAntenneBYInfoByTime(8)).describedAs("AntenneBY info by Time at 8.00").isEqualTo("ANTENNE BAYERN Guten Morgen Bayern");
}
@Test
void AntenneBYInfoByTime2Test() {
RadioPlayer rp = new RadioPlayer();
assertThat(rp.getAntenneBYInfoByTime(3)).describedAs("AntenneBY info by Time at 3.00").isEqualTo("ANTENNE BAYERN Hit-Nacht");
}
@Test
void BR3InfoByTimeTest() {
RadioPlayer rp = new RadioPlayer();
assertThat(rp.getBR3InfoByTime(5)).describedAs("BR3 info by Time at 5.00").isEqualTo("Sebastian Winkler und die Frühaufdreher");
@ParameterizedTest
@MethodSource("infoByTimeOptions")
void infoByTimeInfo(String testName, RadioPlayer testRp, String testTyp, int hour, String expectedResult) {
if(testTyp.equals("YouFM")) assertThat(testRp.getYouFMInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult);
if(testTyp.equals("BR3")) assertThat(testRp.getBR3InfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult);
if(testTyp.equals("AntenneBY")) assertThat(testRp.getAntenneBYInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult);
} }
@Test
void BR3InfoByTime2Test() {
static Stream<Arguments> infoByTimeOptions() {
RadioPlayer rp = new RadioPlayer(); RadioPlayer rp = new RadioPlayer();
assertThat(rp.getBR3InfoByTime(21)).describedAs("BR3 info by Time at 21.00").isEqualTo("Matuschke - der etwas andere Abend");
return Stream.of(
Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 5, rp.YouFMInfo[0]),
Arguments.of("Station info YouFm at 10:00 am", rp, "YouFM", 10, rp.YouFMInfo[1]),
Arguments.of("Station info YouFm at 2:00 pm", rp, "YouFM", 14, rp.YouFMInfo[2]),
Arguments.of("Station info YouFm at 6:00 pm", rp, "YouFM", 18, rp.YouFMInfo[3]),
Arguments.of("Station info YouFm at 8:00 pm", rp, "YouFM", 20, rp.YouFMInfo[4]),
Arguments.of("Station info YouFm at 10:00 pm", rp, "YouFM", 22, rp.YouFMInfo[5]),
Arguments.of("Station info YouFm at 3:00 am", rp, "YouFM", 3, rp.YouFMInfo[6]),
Arguments.of("Station info BR3 at 5:00 am", rp, "BR3", 5, rp.BR3Info[0]),
Arguments.of("Station info BR3 at 9:00 am", rp, "BR3", 9, rp.BR3Info[1]),
Arguments.of("Station info BR3 at 12:00 am", rp, "BR3", 12, rp.BR3Info[2]),
Arguments.of("Station info BR3 at 1:00 pm", rp, "BR3", 13, rp.BR3Info[3]),
Arguments.of("Station info BR3 at 4:00 pm", rp, "BR3", 16, rp.BR3Info[4]),
Arguments.of("Station info BR3 at 7:00 pm", rp, "BR3", 19, rp.BR3Info[5]),
Arguments.of("Station info BR3 at 9:00 pm", rp, "BR3", 21, rp.BR3Info[6]),
Arguments.of("Station info BR3 at 3:00 am", rp, "BR3", 3, rp.BR3Info[7]),
Arguments.of("Station info AntenneBY at 5:00 am", rp, "AntenneBY", 5, rp.AntenneBYInfo[0]),
Arguments.of("Station info AntenneBY at 9:00 am", rp, "AntenneBY", 9, rp.AntenneBYInfo[1]),
Arguments.of("Station info AntenneBY at 12:00 am", rp, "AntenneBY", 12, rp.AntenneBYInfo[2]),
Arguments.of("Station info AntenneBY at 3:00 pm", rp, "AntenneBY", 15, rp.AntenneBYInfo[3]),
Arguments.of("Station info AntenneBY at 3:00 am", rp, "AntenneBY", 3, rp.AntenneBYInfo[4])
);
} }
@ParameterizedTest @ParameterizedTest

3
src/test/java/device/usbPlayer/USB_StickTest.java

@ -47,7 +47,6 @@ class USB_StickTest {
); );
} }
//ChangeAlbum
@ParameterizedTest @ParameterizedTest
@MethodSource("ChangeAlbumOptions") @MethodSource("ChangeAlbumOptions")
void ChangeAlbumTest(String testName, USB_Stick s) throws NoFolderFound { void ChangeAlbumTest(String testName, USB_Stick s) throws NoFolderFound {
@ -68,4 +67,6 @@ class USB_StickTest {
); );
} }
} }

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

@ -9,9 +9,10 @@ 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")
@ -21,21 +22,22 @@ class UsbPlayerTest {
} }
static Stream<Arguments> PlayOptions() { 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(""); up8.setPlayTrack("");
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
ArrayList<String> l = new ArrayList<String>(); ArrayList<String> l = new ArrayList<String>();
l.add("a.mp3"); l.add("a.mp3");
l.add("b.mp3"); l.add("b.mp3");
l.add("c.gif"); l.add("c.gif");
up2.setPlaylist(l); up2.setPlaylist(l);
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
ArrayList<String> Pl = new ArrayList<String>(); ArrayList<String> Pl = new ArrayList<String>();
up3.setPlaylist(Pl); up3.setPlaylist(Pl);
UsbPlayer up6 = new UsbPlayer();
UsbPlayer up6 = new UsbPlayer(USBDrive);
up6.setDefect(true); up6.setDefect(true);
UsbPlayer up7 = new UsbPlayer();
UsbPlayer up7 = new UsbPlayer(USBDrive);
up7.setConnected(false); up7.setConnected(false);
@ -57,14 +59,31 @@ class UsbPlayerTest {
} }
static Stream<Arguments> louderOptions() { static Stream<Arguments> louderOptions() {
UsbPlayer up11 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up11 = new UsbPlayer(USBDrive);
up11.louder(); up11.louder();
UsbPlayer up22 = new UsbPlayer();
//second case
UsbPlayer up22 = new UsbPlayer(USBDrive);
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 : 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() { static Stream<Arguments> quieterOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.quieter(); up1.quieter();
UsbPlayer up2 = new UsbPlayer();
//second case
UsbPlayer up2 = new UsbPlayer(USBDrive);
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 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() { static Stream<Arguments> NextOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.next(); up1.next();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
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();
UsbPlayer up3 = new UsbPlayer(USBDrive);
for (int i = 1; i < up3.getPlaylist().size(); i++) { for (int i = 1; i < up3.getPlaylist().size(); i++) {
up3.next(); up3.next();
} }
@ -123,9 +162,10 @@ class UsbPlayerTest {
} }
static Stream<Arguments> PrevOptions() { static Stream<Arguments> PrevOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.prev(); up1.prev();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
for (int i = 1; i < up2.getPlaylist().size(); i++) {//3 for (int i = 1; i < up2.getPlaylist().size(); i++) {//3
up2.prev(); up2.prev();
} }
@ -145,22 +185,37 @@ class UsbPlayerTest {
} }
static Stream<Arguments> louder_10_Options() { 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(); 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.Louder_10();
} }
up2.quieter_10();
UsbPlayer up3 = new UsbPlayer();
//third case
UsbPlayer up3 = new UsbPlayer(USBDrive);
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 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() { 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.setLautstaerke(10);
up1.quieter_10(); up1.quieter_10();
UsbPlayer up2 = new UsbPlayer();
//second case
UsbPlayer up2 = new UsbPlayer(USBDrive);
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();
} }
UsbPlayer up3 = new UsbPlayer();
//third case
UsbPlayer up3 = new UsbPlayer(USBDrive);
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 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() { static Stream<Arguments> FindSongOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
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),
@ -222,16 +293,17 @@ class UsbPlayerTest {
} }
static Stream<Arguments> GoToOptions() { static Stream<Arguments> GoToOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.GoTo("Musik 03.mp3"); up1.GoTo("Musik 03.mp3");
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.GoTo("Musik 04.mp3"); up2.GoTo("Musik 04.mp3");
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.GoTo("Musik 02"); up3.GoTo("Musik 02");
UsbPlayer up4 = new UsbPlayer();
UsbPlayer up4 = new UsbPlayer(USBDrive);
up4.next(); up4.next();
up4.GoTo("Musik"); up4.GoTo("Musik");
@ -252,45 +324,46 @@ class UsbPlayerTest {
} }
static Stream<Arguments> isAllAudioOptions() { static Stream<Arguments> isAllAudioOptions() {
USB_Stick USBDrive = new USB_Stick();
//mp3 //mp3
UsbPlayer up1 = new UsbPlayer();
UsbPlayer up1 = new UsbPlayer(USBDrive);
//mp4 //mp4
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
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();
UsbPlayer up3 = new UsbPlayer(USBDrive);
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();
UsbPlayer up4 = new UsbPlayer(USBDrive);
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();
UsbPlayer up5 = new UsbPlayer(USBDrive);
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();
UsbPlayer up6 = new UsbPlayer(USBDrive);
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();
UsbPlayer up7 = new UsbPlayer(USBDrive);
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");
@ -318,14 +391,15 @@ class UsbPlayerTest {
} }
static Stream<Arguments> GoToFirstOptions() { static Stream<Arguments> GoToFirstOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.GoToFirst(); up1.GoToFirst();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.GoToFirst(); up2.GoToFirst();
up2.GoToFirst(); up2.GoToFirst();
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.next(); up3.next();
up3.GoToFirst(); up3.GoToFirst();
@ -344,15 +418,16 @@ class UsbPlayerTest {
} }
static Stream<Arguments> GoToLastOptions() { static Stream<Arguments> GoToLastOptions() {
USB_Stick USBDrive = new USB_Stick();
//first case //first case
UsbPlayer up1 = new UsbPlayer();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.GoToLast(); up1.GoToLast();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.GoToLast(); up2.GoToLast();
up2.GoToLast(); up2.GoToLast();
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.next(); up3.next();
up3.GoToLast(); up3.GoToLast();
@ -372,16 +447,17 @@ class UsbPlayerTest {
} }
static Stream<Arguments> setPlayTrackOptions() { static Stream<Arguments> setPlayTrackOptions() {
USB_Stick USBDrive = new USB_Stick();
//first case //first case
UsbPlayer up1 = new UsbPlayer();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.setPlayTrack("Musik 02.mp3"); up1.setPlayTrack("Musik 02.mp3");
//Second Case //Second Case
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.setPlayTrack("Musik 02.mp3"); up2.setPlayTrack("Musik 02.mp3");
//Third Case //Third Case
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.setPlayTrack("Musik 04.mp3"); up3.setPlayTrack("Musik 04.mp3");
return Stream.of( return Stream.of(
@ -389,6 +465,127 @@ class UsbPlayerTest {
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") 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