123 Commits

Author SHA1 Message Date
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
Jan Ortner 32b80ec46d cleaned up RadioPlayer & RadioPlayerTest 3 years ago
Jenkins af8d3066c4 Merge commit '9ca1d2a492283b9860b6d2a40adeb4596db5d13c' into HEAD 3 years ago
Jan Ortner 9ca1d2a492 added third test case for RadioPlayer getOptions() 3 years ago
Jan Ortner f6361c27b8 added second test case for RadioPlayer getOptions() & added productive code 3 years ago
Jan Ortner 96c9e5c3b6 added first test case for RadioPlayer getOptions() 3 years ago
Jenkins e9946609b5 Merge commit '561d5f6bc27a64088b1bc2d52587508230337ab3' into HEAD 3 years ago
Jan Ortner 561d5f6bc2 added eighth test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jan Ortner 0ff584dc0a added sevens test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jenkins 603b2e0029 Merge commit '33d834e7022e8fbebbe8f15124da3e92400910f6' into HEAD 3 years ago
sahar 33d834e702 Merge branch 'master' into feature-pr-USB-otherTests 3 years ago
sahar 002db4c71f USB_StickTest.getAlbumTest Second Case 3 years ago
Jan Ortner e6541cf2b9 added six test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jenkins 1b557c8ad3 Merge commit 'dff29bea43d8fa550cb061fe11dbc1d095eecd6d' into HEAD 3 years ago
JPANZO dff29bea43 Merge branch 'master' into feature-pr-jacksonsNewFeature 3 years ago
JPANZO f51c6d783c Method getInfoText of CDPlayer tested on MessageShouldContainInfoAboutDevice. 3 years ago
Jan Ortner dd88b2967c added fifth test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
JPANZO c5c7ea8c95 Method getInfoText of CDPlayer tested on MessageShouldContainInfoAboutAlbum. 3 years ago
Jan Ortner f754c0a5ce added fourth test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jan Ortner 9d20decf08 added third test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jan Ortner bc0ecd2675 added second test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jan Ortner 57114df69a added first test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jenkins 9830ace3fd Merge commit 'de82f475dd2f7f7453406f886519043de7ea7998' into HEAD 3 years ago
Jan Ortner de82f475dd added test case for unmute() & and added productive code for RadioPlayer 3 years ago
JPANZO 1f11a8366c Method getInfoText of CDPlayer tested on MessageShouldContainInfoOfActualPlayTrack. 3 years ago
Jan Ortner 8b23b50442 added second test case for mute() & and added productive code for RadioPlayer 3 years ago
Jan Ortner f8bcf0c62b added first test case for mute() & and added productive code for RadioPlayer 3 years ago
sahar 88078ff752 USB_StickTest.ChangeAlbumTest First Case 3 years ago
Jenkins 75f23114b2 Merge commit 'b7b79badda3d9c14f0fa7360b8256ec51fe3cde0' into HEAD 3 years ago
Jan Ortner b7b79badda added second test case for getItemList() & and added productive code for RadioPlayer 3 years ago
JPANZO d606a41ef7 Method getInfoText of CDPlayer tested on ExceptionShouldReturnAMessage. 3 years ago
sahar d1b481b3d0 USB_StickTest.getAlbumTest First Case 3 years ago
Jan Ortner d61ea26007 added first test case for getItemList() & and added productive code for RadioPlayer 3 years ago
JPANZO 007aa5d415 Method getInfoText of CDPlayer tested on shouldThrowReturnValueNullException. 3 years ago
sahar 85e3d47217 Changes in the Structure if device.usbPlayer , USB_Stick.java was added and changes in the UsbPlayer.java 3 years ago
Jenkins 2ad8951143 Merge commit 'd6dbffa4855f3d4ba2e98c5523719806b312c8c3' into HEAD 3 years ago
Jan Ortner d6dbffa485 Merge branch 'master' into feature-pr-RadioPlayer-chooseItem 3 years ago
Jan Ortner 419699e4bc added six test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
Jan Ortner acfc2fef2b added fifth test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
Jan Ortner a5c936d270 added fourth test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
Jan Ortner cd09cb8775 added third test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
Jan Ortner 820d148f30 added second test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
Jenkins ec66817f43 Merge commit '0e9662561a8188138ec8e83fbac713782c5d980b' into HEAD 3 years ago
JPANZO 0e9662561a changes on Interface 4. 3 years ago
JPANZO 0e4bbd07dd Method getVolume of CDPlayer tested on getVolumeReturnValueBetween0And100. 3 years ago
Jan Ortner e5b9f46ce7 added first test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
Jenkins f67ab57e52 Merge commit '63db5393e8846bedaf0c237f6ffa6cf4043444a8' into HEAD 3 years ago
sahar 308057ae4b UsbPlayerTest.setPlayTrackTest Third Case 3 years ago
sahar 648baabab0 UsbPlayerTest.setPlayTrackTest Second Case 3 years ago
sahar 95977c9ae7 UsbPlayerTest.setPlayTrackTest first Case 3 years ago
sahar 945bb15abf UsbPlayerTest.GoToLastTest third Case 3 years ago
sahar 9bf794bbea UsbPlayerTest.GoToLastTest fiSecond Case 3 years ago
JPANZO 63db5393e8 getOptions from CDPlayer tested on ArrayContainsInterfaceMethods. 3 years ago
Jenkins 7f86735e36 Merge commit '6c5989e12f15df61ecedbb5357c3e8c7688c9b23' into HEAD 3 years ago
JPANZO 6c5989e12f getOptions from CDPlayer tested on ArrayLengthGreaterThen 0. 3 years ago
JPANZO aa3c6ef4d4 getOptions from CDPlayer tested on Returning Null. 3 years ago
JPANZO 31e51d9a3f changes in the Interface 0.2. 3 years ago
JPANZO 74242d1cb5 changes in the Interface. 3 years ago
Jenkins 1310253866 Merge commit '15ddf95671998e3ed736d151e654817feada8328' into HEAD 3 years ago
sahar 15ddf95671 UsbPlayerTest.GoToLastTest first Case correction 3 years ago
sahar 27f942760b UsbPlayerTest.GoToLastTest first Case 3 years ago
Jenkins a71a1e51a1 Merge commit 'd5b13dadc8b57b1d4ebb73dce23c7b406e771cf9' into HEAD 3 years ago
sahar ba0578b7ba UsbPlayerTest.GoToFirstTest third Case 3 years ago
sahar e21ac14932 UsbPlayerTest.GoToFirstTest Second Case 3 years ago
sahar 280b8843f2 UsbPlayerTest.GoToFirstTest first Case 3 years ago
JPANZO d5b13dadc8 test+productive code for case:3 of method prev in CDPlayer created. 3 years ago
Jenkins 88b9019cd7 Merge commit '0cc9fe4b88f46895ac2340f3bcfeb20f4819efb4' into HEAD 3 years ago
Jan Ortner 0cc9fe4b88 added third test case for changeOrderInSavedPlaylist() & and added productive code 3 years ago
Jan Ortner 6776f0b752 added second test case for changeOrderInSavedPlaylist() & and added productive code 3 years ago
sahar f98223ea57 UsbPlayerTest.isAllAudioTestTest seventh Case (mixed Audio and txt) 3 years ago
JPANZO ffd65cc96f test+productive code for case:2 of method prev in CDPlayer created. 3 years ago
sahar b2e9f26d0a UsbPlayerTest.isAllAudioTestTest Sixth Case (aac) 3 years ago
sahar 3175b14cde UsbPlayerTest.isAllAudioTestTest Fifth Case (wma) 3 years ago
sahar 0188a43e11 UsbPlayerTest.isAllAudioTestTest Forth Case correction(wav) 3 years ago
Jan Ortner 799360763a added first test case for changeOrderInSavedPlaylist() & and added productive code 3 years ago
JPANZO fc6f610b6a test+productive code for case:1 of method prev in CDPlayer created. 3 years ago
sahar 356bcaf539 UsbPlayerTest.isAllAudioTestTest Forth Case (flac) 3 years ago
sahar 36b6cc48c9 UsbPlayerTest.isAllAudioTestTest Third Case (m4a) 3 years ago
JPANZO e7972264de Revert "test+productive code for case:1 of method prev in CDPlayer created." 3 years ago
sahar 3fa2cfb862 UsbPlayerTest.isAllAudioTestTest Second Case (mp4) 3 years ago
JPANZO b4583eece1 test+productive code for case:1 of method prev in CDPlayer created. 3 years ago
sahar e68d22daf4 UsbPlayerTest.isAllAudioTestTest First Case 3 years ago
Jenkins 159a41d17c Merge commit '0a02c7b9cdea159b75a781abdac4db4ab846240b' into HEAD 3 years ago
Jan Ortner 0a02c7b9cd added second test case for changeToSavedPlaylist() & and added productive code 3 years ago
Jan Ortner 5d52b2f721 added first test case for changeToSavedPlaylist() & and added productive code 3 years ago
Jenkins 2ce7da7c02 Merge commit '2b0ee697b60772cc5871b04c9ca71ceddfabecb2' into HEAD 3 years ago
Jan Ortner 2b0ee697b6 added new test case for deleteStation() & code for saved station delete until there is only one station in savedPlaylist 3 years ago
Jenkins 5d0e3168a2 Merge commit '54ac5f48b32f398f1329ebd22b94b9fa36fe9e37' into HEAD 3 years ago
Jan Ortner 54ac5f48b3 added new test case for play() & changed play() to show if playedStation is in regional or saved playlist 3 years ago
Jan Ortner 492cbdb790 added new test case for play() & changed play() to show if playedStation is in regional or saved playlist 3 years ago
Jenkins 26ca86cee3 Merge commit '9f78d7aa9b5826b88cd386deb8f8f81a9e99f2e8' into HEAD 3 years ago
Jan Ortner 9f78d7aa9b added new test case for saveStation & changed saveStation() to jump back to savedPlaylist after station is saved 3 years ago
Jenkins c2ae912a58 Merge commit 'ecf5a3e4ad2363a766081e57c9e30ec4f7cfbc62' into HEAD 3 years ago
Jan Ortner ecf5a3e4ad added new test case for saveStation & changed saveStation() to not saving duplicate stations 3 years ago
Jan Ortner 74fa5f4bb6 added new test case for prev() & changed prev() to work with regional and saved stations 3 years ago
Jan Ortner f99a208c8e added new test case for next() & changed next() to work with regional and saved stations 3 years ago
Jan Ortner d38a65b490 added saveStation() and first test for adding station to savedPlaylist 3 years ago
Jenkins c4002a49fa Merge commit 'c350b06358eaccff1c7961614bc165a0b59d3a63' into HEAD 3 years ago
Jan Ortner c350b06358 added play() and first test for first saved station 3 years ago
Jenkins 30790a3e2c Merge commit '1912744e55bbf6b11225dab37ce80d88a1b31890' into HEAD 3 years ago
Jan Ortner 1912744e55 changed from getLautstaerke() to getVolume() like it is defined in device interface 3 years ago
Jenkins 4bfe172f67 Merge commit 'd57de4380a416d172bb46c247ccf7c57db7d67fd' into HEAD 3 years ago
Jenkins 5b3231fbe8 Merge commit 'fce439259bcd626f61070c1e8f108d5c0e814772' into HEAD 3 years ago
sahar d57de4380a UsbPlayerTest.GoToTest Forth Case 3 years ago
sahar 5a74e5ea75 UsbPlayerTest.GoToTest Third Case 3 years ago
sahar d6170a230c UsbPlayerTest.GoToTest Second Case 3 years ago
sahar dfeb952e36 UsbPlayerTest.GoToTest First Case 3 years ago
sahar f8c8ff9120 UsbPlayerTest.findSongTest Forth Case 3 years ago
sahar d00dd96833 UsbPlayerTest.findSongTest Third Case 3 years ago
sahar 40ff19f935 UsbPlayerTest.findSongTest Second Case 3 years ago
sahar 692a519b76 UsbPlayerTest.findSongTest first Case 3 years ago
sahar 3d34b2c239 UsbPlayerTest.quieter_10_Test third Case 3 years ago
sahar 559b156bd5 UsbPlayerTest.quieter_10_Test second Case 3 years ago
sahar 601a10898f UsbPlayerTest.quieter_10_Test first Case 3 years ago
sahar 959a6a3a5e UsbPlayerTest.louder_10_Test() third Case 3 years ago
sahar 3d3a1d8dfc UsbPlayerTest.louder_10_Test() second Case 3 years ago
sahar cb6236b180 UsbPlayerTest.louder_10_Test() first Case 3 years ago
JPANZO fce439259b Test+Productive code for case:3 of method-test next created. 3 years ago
JPANZO d917a294b4 Test+Productive code for case:2 of method-test next created. 3 years ago
Jenkins e066b88547 Merge commit '8f91aa7a6ca733738a3ed10707080eea4f812de7' into HEAD 3 years ago
  1. 16
      src/main/java/device/Device.java
  2. 9
      src/main/java/device/cdPlayer/CD.java
  3. 55
      src/main/java/device/cdPlayer/CDPlayer.java
  4. 9
      src/main/java/device/cdPlayer/exceptions/ReturnValueNullException.java
  5. 239
      src/main/java/device/radioPlayer/RadioPlayer.java
  6. 8
      src/main/java/device/usbPlayer/NoFolderFound.java
  7. 60
      src/main/java/device/usbPlayer/USB_Stick.java
  8. 93
      src/main/java/device/usbPlayer/UsbPlayer.java
  9. 165
      src/test/java/device/cdPlayer/CDPlayerTest.java
  10. 375
      src/test/java/device/radioPlayer/RadioPlayerTest.java
  11. 71
      src/test/java/device/usbPlayer/USB_StickTest.java
  12. 268
      src/test/java/device/usbPlayer/UsbPlayerTest.java

16
src/main/java/device/Device.java

@ -7,13 +7,17 @@ public interface Device {
int getVolume();
void next();
void prev();
String play();
//get deviceName, Album and current Item
String getInfoText();
//returns an array with Method-Names to bee listed
//get a list of public methods
String[] getOptions();
//returns an array with contents to bee played
//get an Item of the Album
String chooseItem(int itemNr);
// get the actual album
String[] getItemList();
String play();
//mute the Volume and returns an Info.
String mute();
//unmute the Volume and returns an Info.
String unmute();
}

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

@ -2,6 +2,7 @@ package device.cdPlayer;
public class CD {
private String format;
private String albumName;
private String[] playList;
public CD() {}
@ -30,4 +31,12 @@ public class CD {
public void setPlayList(String[] playList) {
this.playList = playList;
}
public String getAlbumName() {
return albumName;
}
public void setAlbumName(String albumName) {
this.albumName = albumName;
}
}

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

@ -2,6 +2,8 @@ package device.cdPlayer;
import device.Device;
import device.cdPlayer.exceptions.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -12,6 +14,7 @@ public class CDPlayer implements Device {
private int CdDriveContent=0;
private int CdFlap=0;
private int volume = 0;
private String infoText=null;
private List<String> supportedFormats = new ArrayList<String>(Arrays.asList(new String[] {"Audio","MP3","WMA","AAC"}));
private String actualPlayTrack="";
@ -44,30 +47,62 @@ public class CDPlayer implements Device {
public void next() {
List<String> playList = Arrays.asList(loadedCD.getPlayList());
int indexOfActualPlayTrack=playList.indexOf(actualPlayTrack);
this.actualPlayTrack=playList.get(indexOfActualPlayTrack +1);
int indexOfNextPlayTrack=(indexOfActualPlayTrack+1)%loadedCD.getPlayList().length;
//System.out.println("actualIndex= "+indexOfActualPlayTrack);
this.actualPlayTrack=playList.get(indexOfNextPlayTrack );
//System.out.println("nextSong= "+actualPlayTrack);
}
@Override
public void prev() {
List<String> playList = Arrays.asList(loadedCD.getPlayList());
int actualIndex=playList.indexOf(actualPlayTrack);
if(actualIndex>0){
actualIndex-=1;
}else{
actualIndex=0;
}
this.actualPlayTrack=playList.get(actualIndex);
}
@Override
public String getInfoText() {
return null;
if(infoText==null){
throw new ReturnValueNullException();
}
return infoText;
}
@Override
public String[] getOptions() {
return new String[0];
Method[] methods=this.getClass().getDeclaredMethods();
String[] outMethods=new String[methods.length];
for (int i = 0; i <methods.length ; i++) {
outMethods[i]=methods[i].getName();
}
return outMethods;
}
@Override
public String chooseItem(int itemNr) {
return null;
}
@Override
public String[] getItemList() {
return new String[0];
return loadedCD.getPlayList();
}
@Override
public String mute() {
return null;
}
@Override
public String unmute() {
return null;
}
@Override
public String play() {
@ -126,4 +161,12 @@ public class CDPlayer implements Device {
return actualPlayTrack;
}
public void setInfoText() {
this.infoText=this.getClass().getSimpleName()+": Item->"+actualPlayTrack+" from Album->"+this.loadedCD.getAlbumName()+" running.";
}
public CD getCD() {
return this.loadedCD;
}
}

9
src/main/java/device/cdPlayer/exceptions/ReturnValueNullException.java

@ -0,0 +1,9 @@
package device.cdPlayer.exceptions;
public class ReturnValueNullException extends RuntimeException{
public ReturnValueNullException() {
super("Method should not return a Null-Value.");
}
}

239
src/main/java/device/radioPlayer/RadioPlayer.java

@ -1,28 +1,31 @@
package device.radioPlayer;
import device.Device;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
public class RadioPlayer implements Device {
private int x;
public RadioPlayer() {
super();
Playlist.add("YouFM");
Playlist.add("Teddy");
Playlist.add("MegaHits");
playTrack=Playlist.get(0);
savedPlaylist.add("YouFM");
savedPlaylist.add("Teddy");
savedPlaylist.add("MegaHits");
playedStation = savedPlaylist.get(0);
}
ArrayList<String> Playlist=new ArrayList<String>();
ArrayList<String> savedPlaylist = new ArrayList<>();
ArrayList<String> regionPlaylist = new ArrayList<>();
LocalDateTime now = LocalDateTime.now();
int hour = now.getHour();
int volume = 0;
int savedVolume;
String playedStation;
public String getYouFMInfoByTime(int x) {
if(x >= 5 && x <10 ) return YouFMInfo[0];
if (x >= 5 && x < 10) return YouFMInfo[0];
else if (x >= 10 && x < 14) return YouFMInfo[1];
else if (x >= 14 && x < 18) return YouFMInfo[2];
else if (x >= 18 && x < 20) return YouFMInfo[3];
@ -34,7 +37,7 @@ public class RadioPlayer implements Device {
String[] YouFMInfo = {"YOUFM Good Morning Show", "YOUFM Worktime", "YOUFM am Nachmittag", "YOUFM am Abend", "YOUFM Wir feiern euch", "YOUFM Deutschrap ideal", "YOUFM Junge Nacht der ARD"};
public String getBR3InfoByTime(int x) {
if(x >= 5 && x <9) return BR3Info[0];
if (x >= 5 && x < 9) return BR3Info[0];
else if (x >= 9 && x < 12) return BR3Info[1];
else if (x == 12) return BR3Info[2];
else if (x >= 13 && x < 16) return BR3Info[3];
@ -44,129 +47,233 @@ public class RadioPlayer implements Device {
else return BR3Info[7];
}
String[] BR3Info = {"Sebastian Winkler und die Frühaufdreher", "BAYERN 3 - und DU mittendrin!", "Update", "Hits, Hits, Hits für euren Nachmittag", "Die Zwei für euren Feierabend", "Was geht?!", "Matuschke - der etwas andere Abend","Die Nacht"};
String[] BR3Info = {"Sebastian Winkler und die Frühaufdreher", "BAYERN 3 - und DU mittendrin!", "Update", "Hits, Hits, Hits für euren Nachmittag", "Die Zwei für euren Feierabend", "Was geht?!", "Matuschke - der etwas andere Abend", "Die Nacht"};
public String getAntenneBYInfoByTime(int x) {
if(x >= 5 && x <9) return AntenneBYInfo[0];
if (x >= 5 && x < 9) return AntenneBYInfo[0];
else if (x >= 9 && x < 12) return AntenneBYInfo[1];
else if (x >= 12 && x < 15) return AntenneBYInfo[2];
else if (x >= 15 && x < 19) return AntenneBYInfo[3];
else return AntenneBYInfo[4];
}
String[] AntenneBYInfo = {"ANTENNE BAYERN Guten Morgen Bayern", "ANTENNE BAYERN bei der Arbeit", "ANTENNE BAYERN am Nachmittag", "ANTENNE BAYERN am Abend", "ANTENNE BAYERN Hit-Nacht"};
int Lautstaerke = 0;
String playTrack="";
String[] AntenneBYInfo = {"ANTENNE BAYERN Guten Morgen Bayern", "ANTENNE BAYERN bei der Arbeit", "ANTENNE BAYERN am Nachmittag", "ANTENNE BAYERN am Abend", "ANTENNE BAYERN Hit-Nacht"};
public void setLautstaerke(int lautstaerke) {
Lautstaerke = lautstaerke;
}
public int getLautstaerke() {
return Lautstaerke;
public void setVolume(int volume) {
this.volume = volume;
}
public void changeRegion(String region){
public void changeRegion(String region) {
switch (region) {
case "BY":
Playlist.clear();
Playlist.add("Antenne Bayern");
Playlist.add("Bayern 1");
Playlist.add("Bayern 3");
Playlist.add("Hit Radio N1");
playTrack=Playlist.get(0);
regionPlaylist.clear();
regionPlaylist.add("Antenne Bayern");
regionPlaylist.add("Bayern 1");
regionPlaylist.add("Bayern 3");
regionPlaylist.add("Hit Radio N1");
playedStation = regionPlaylist.get(0);
break;
case "HE":
Playlist.clear();
Playlist.add("Hit Radio FFH");
Playlist.add("HR 1");
Playlist.add("HR 3");
Playlist.add("YouFM");
playTrack=Playlist.get(0);
regionPlaylist.clear();
regionPlaylist.add("Hit Radio FFH");
regionPlaylist.add("HR 1");
regionPlaylist.add("HR 3");
regionPlaylist.add("YouFM");
playedStation = regionPlaylist.get(0);
break;
case "BW":
Playlist.clear();
Playlist.add("DASDING");
Playlist.add("SWR 1");
Playlist.add("SWR 3");
Playlist.add("sunshine live");
playTrack=Playlist.get(0);
break;
default:
Playlist.clear();
Playlist.add("YouFM");
Playlist.add("Teddy");
Playlist.add("MegaHits");
playTrack=Playlist.get(0);
regionPlaylist.clear();
regionPlaylist.add("DASDING");
regionPlaylist.add("SWR 1");
regionPlaylist.add("SWR 3");
regionPlaylist.add("sunshine live");
playedStation = regionPlaylist.get(0);
break;
}
}
@Override
public void louder() {
if(Lautstaerke < 100){Lautstaerke+=1;}
else Lautstaerke = 100;
if (volume < 100) {
volume += 1;
} else volume = 100;
}
@Override
public void quieter() {
if(Lautstaerke > 0){Lautstaerke-=1;}
else Lautstaerke = 0;
if (volume > 0) {
volume -= 1;
} else volume = 0;
}
@Override
public int getVolume() {
return 0;
return volume;
}
@Override
public void next() {
int currentIndex=Playlist.indexOf(playTrack);
int nextIndex=(currentIndex+1)%Playlist.size();
playTrack=Playlist.get(nextIndex);
if (regionPlaylist.contains(playedStation)) {
int currentIndex = regionPlaylist.indexOf(playedStation);
int nextIndex = (currentIndex + 1) % regionPlaylist.size();
playedStation = regionPlaylist.get(nextIndex);
} else {
int currentIndex = savedPlaylist.indexOf(playedStation);
int nextIndex = (currentIndex + 1) % savedPlaylist.size();
playedStation = savedPlaylist.get(nextIndex);
}
}
@Override
public void prev() {
int currentIndex=Playlist.indexOf(playTrack);
int nextIndex=Playlist.size()-1;
if(currentIndex!=0){nextIndex=(currentIndex-1);}
playTrack=Playlist.get(nextIndex);
if (regionPlaylist.contains(playedStation)) {
int currentIndex = regionPlaylist.indexOf(playedStation);
int nextIndex = regionPlaylist.size() - 1;
if (currentIndex != 0) {
nextIndex = (currentIndex - 1);
}
playedStation = regionPlaylist.get(nextIndex);
} else {
{
int currentIndex = savedPlaylist.indexOf(playedStation);
int nextIndex = savedPlaylist.size() - 1;
if (currentIndex != 0) {
nextIndex = (currentIndex - 1);
}
playedStation = savedPlaylist.get(nextIndex);
}
}
}
@Override
public String getInfoText() {
return null;
if (showStationInfo().equals("")) return buildInfoText();
return (buildInfoText() + "\n Now playing: " + showStationInfo());
}
private String buildInfoText() {
String infoText = playedStation;
if (regionPlaylist.contains(playedStation))
return ("Regional playlist: " + (regionPlaylist.indexOf(playedStation) + 1) + infoText);
else return ("Saved playlist: " + (savedPlaylist.indexOf(playedStation) + 1) + infoText);
}
@Override
public String[] getOptions() {
return new String[0];
Method[] methods = this.getClass().getDeclaredMethods();
return Arrays.stream(methods).map(Method::getName).toArray(String[]::new);
}
@Override
public String chooseItem(int itemNr) {
if (regionPlaylist.contains(playedStation)) {
if (itemNr > regionPlaylist.size()) {
playedStation = regionPlaylist.get(regionPlaylist.size() - 1);
return ("Radio is playing station: 0" + regionPlaylist.size() + " " + this.playedStation + " from regional playlist");
} else if (itemNr < 1) {
playedStation = regionPlaylist.get(0);
return ("Radio is playing station: 01 " + this.playedStation + " from regional playlist");
} else {
playedStation = regionPlaylist.get(itemNr - 1);
return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
}
} else {
if (itemNr > savedPlaylist.size()) {
playedStation = savedPlaylist.get(savedPlaylist.size() - 1);
return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist");
} else if (itemNr < 1) {
playedStation = savedPlaylist.get(0);
return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist");
} else {
playedStation = savedPlaylist.get(itemNr - 1);
return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
}
}
}
@Override
public String[] getItemList() {
return new String[0];
if (regionPlaylist.contains(playedStation))
return regionPlaylist.toArray(new String[0]);
else
return savedPlaylist.toArray(new String[0]);
}
@Override
public String mute() {
savedVolume = getVolume();
setVolume(0);
return "RadioPlayer is muted now";
}
@Override
public String unmute() {
setVolume(savedVolume);
return ("RadioPlayer is unmuted Volume is set to " + getVolume());
}
@Override
public String play() {
return null;
if (regionPlaylist.contains(playedStation))
return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
else
return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
}
public String showStationInfo() {
switch (playTrack) {
switch (playedStation) {
case "Antenne Bayern":
return getAntenneBYInfoByTime(hour);
case "YouFM":
return getYouFMInfoByTime(hour);
case "Bayern 3":
return getBR3InfoByTime(hour);
default: return "";
default:
return "";
}
}
public String saveStation() {
if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved";
else savedPlaylist.add(playedStation);
regionPlaylist.clear();
return "Station " + playedStation + " is saved in your Station list";
}
public String deleteStation() {
String station = playedStation;
if ((savedPlaylist.size()) > 1) {
savedPlaylist.remove(playedStation);
playedStation = savedPlaylist.get(0);
return "Station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + station + " has been deleted";
} else return " Last Station: 01 " + station + " can´t by deleted";
}
public String changeToSavedPlaylist() {
if (regionPlaylist.contains(playedStation)) {
playedStation = savedPlaylist.get(0);
regionPlaylist.clear();
return "Playlist switched now playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist";
}
return "You are already in saved Playlist!";
}
public String changeOrderInSavedPlaylist(int nr) {
String station = playedStation;
if ((nr - 1) > savedPlaylist.size()) {
savedPlaylist.remove(playedStation);
savedPlaylist.add(savedPlaylist.size(), station);
return "Station " + playedStation + " is now on place 0" + (savedPlaylist.size() + 1) + "in saved playlist";
} else if (nr < 0) {
savedPlaylist.remove(playedStation);
savedPlaylist.add(0, station);
return "Station " + playedStation + " is now on place 01 in saved playlist";
} else {
savedPlaylist.remove(playedStation);
savedPlaylist.add(nr - 1, station);
return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist";
}
}
}

8
src/main/java/device/usbPlayer/NoFolderFound.java

@ -0,0 +1,8 @@
package device.usbPlayer;
public class NoFolderFound extends Exception{
public NoFolderFound(String message)
{
super(message);
}
}

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

@ -0,0 +1,60 @@
package device.usbPlayer;
import java.util.ArrayList;
import device.usbPlayer.NoFolderFound;
public class USB_Stick {
public ArrayList<ArrayList<String>> Folders = new ArrayList<>();
int currentAlbum ;
USB_Stick() {
ArrayList<String> a1 = new ArrayList<String>();
a1.add("Musik 01.mp3");
a1.add("Musik 02.mp3");
a1.add("Musik 03.mp3");
Folders.add(0,a1);
ArrayList<String> a2 = new ArrayList<String>();
a2.add("File 01.txt");
a2.add("File 02.txt");
a2.add("File 03.txt");
Folders.add(1,a2);
ArrayList<String> a3 = new ArrayList<String>();
a3.add("Photo 01.gif");
a3.add("Photo 02.gif");
a3.add("Photo 03.gif");
Folders.add(2,a3);
ArrayList<String> a4 = new ArrayList<String>();
a4.add("Music 01.mp3");
a4.add("Music 02.mp3");
a4.add("Music 03.mp3");
Folders.add(3,a4);
currentAlbum = 0;
}
USB_Stick(String a){
}
public ArrayList<String> getAlbum() throws NoFolderFound{
if(Folders.size()==0) {
System.out.println("list ist leer");
throw new NoFolderFound("The USB Drive is empty");
}
else {
System.out.println("nicht leer");
return Folders.get(currentAlbum);
}
}
public void ChangeAlbum(){
++currentAlbum;
}
}

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

@ -6,13 +6,14 @@ import java.util.ArrayList;
public class UsbPlayer implements Device {
private ArrayList<String> Playlist = new ArrayList<String>();
private String playTrack = "";
private Boolean isConnected;
private Boolean isDefect;
int Lautstaerke = 0;
public USB_Stick USBDrive = new USB_Stick();
//*********setters und getters********
public ArrayList<String> getPlaylist() {
return Playlist;
}
@ -43,7 +44,9 @@ public class UsbPlayer implements Device {
}
public void setPlayTrack(String playTrack) {
this.playTrack = playTrack;
if (this.findSong(playTrack) != -1) {
this.playTrack = playTrack;
} else System.out.println("The Song does not exist in the Albume");
}
@ -62,21 +65,28 @@ public class UsbPlayer implements Device {
super();
isDefect = false;
isConnected = true;
Playlist.add("Musik 01.mp3");
/*Playlist.add("Musik 01.mp3");
Playlist.add("Musik 02.mp3");
Playlist.add("Musik 03.mp3");
playTrack = Playlist.get(0);*/
try {
Playlist = USBDrive.getAlbum();
} catch (NoFolderFound e) {
e.printStackTrace();
}
playTrack = Playlist.get(0);
}
//**********search method*************
private boolean isAllAudio() {
public boolean isAllAudio() {
String song = "";
boolean flag = true;
for (int i = 0; i < Playlist.size(); i++) {
song = Playlist.get(i).substring(Playlist.get(i).length() - 4);
if (song.equals(".mp3") | song.equals(".mp4") | song.equals(".wav")) {
if (song.equals(".mp3") | song.equals(".mp4") | song.equals(".m4a") | song.equals(".wav") | song.equals(".wma") | song.equals(".aac")) {
flag = true;
} else {
flag = false;
@ -85,10 +95,12 @@ public class UsbPlayer implements Device {
}
return flag;
}
//**********search method*************
@Override
public void quieter() {
if(Lautstaerke > 0) {
if (Lautstaerke > 0) {
Lautstaerke -= 1;
} else {
Lautstaerke = 0;
@ -97,13 +109,27 @@ public class UsbPlayer implements Device {
@Override
public void louder() {
if(Lautstaerke < 100) {
if (Lautstaerke < 100) {
Lautstaerke += 1;
} else {
Lautstaerke = 100;
}
}
public void Louder_10() {
Lautstaerke += 10;
if (Lautstaerke > 100) {
Lautstaerke = 100;
}
}
public void quieter_10() {
Lautstaerke -= 10;
if (Lautstaerke < 0) {
Lautstaerke = 0;
}
}
@Override
public int getVolume() {
return 0;
@ -136,9 +162,24 @@ public class UsbPlayer implements Device {
return new String[0];
}
@Override
public String chooseItem(int itemNr) {
return null;
}
@Override
public String[] getItemList() {
return new String[0];
return null;
}
@Override
public String mute() {
return null;
}
@Override
public String unmute() {
return null;
}
@ -169,4 +210,40 @@ public class UsbPlayer implements Device {
}
public int findSong(String songName) {
int songIndex = -1, index = -1;
String song;
for (int j = 0; j < getPlaylist().size(); j++) {
song = getPlaylist().get(j);
songIndex = song.toLowerCase().indexOf(songName.toLowerCase());
if (songIndex != -1) {
index = j;
break;
}
}
return index;
}
public boolean GoTo(String songName) {
if (findSong(songName) != -1) {
playTrack = getPlaylist().get(findSong(songName));//songName;
return true;
} else
//playTrack = songName;
return false;
}
public void GoToFirst() {
//go to the first song in the list
setPlayTrack(getPlaylist().get(0));
}
public void GoToLast() {
//go to the last Song
setPlayTrack(this.getPlaylist().get(this.getPlaylist().size() - 1));
}
}

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

@ -1,16 +1,25 @@
package device.cdPlayer;
import device.Device;
import device.cdPlayer.exceptions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class CDPlayerTest {
@ -156,10 +165,17 @@ class CDPlayerTest {
@ParameterizedTest
@MethodSource("nextTestData")
void nextTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, String expectedResult){
for (int i = 0; i < anzClicks; i++) {
_cdPlayer.next();
if(testDirection.equals("SecondSongSelected")|| testDirection.equals("ThirdSongSelected")){
for (int i = 0; i < anzClicks; i++) {
_cdPlayer.next();
}
assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult);
}
if(testDirection.equals("SecondSongSelected")){
if(testDirection.equals("FirstSongSelected")){
for (int i = 0; i <anzClicks; i++) {
_cdPlayer.next();
}
assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult);
}
}
@ -168,13 +184,146 @@ class CDPlayerTest {
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"};
CD audioCD=new CD("Audio",audioPlayList);
CDPlayer cdPlayer=new CDPlayer();
cdPlayer.tapOnCdFlap();
cdPlayer.setCD(audioCD);
cdPlayer.tapOnCdFlap();
CDPlayer cdPlayer1=new CDPlayer();
cdPlayer1.tapOnCdFlap();
cdPlayer1.setCD(audioCD);
cdPlayer1.tapOnCdFlap();
CDPlayer cdPlayer2=new CDPlayer();
cdPlayer2.tapOnCdFlap();
cdPlayer2.setCD(audioCD);
cdPlayer2.tapOnCdFlap();
CDPlayer cdPlayer3=new CDPlayer();
cdPlayer3.tapOnCdFlap();
cdPlayer3.setCD(audioCD);
cdPlayer3.tapOnCdFlap();
return Stream.of(
Arguments.of("[getActualPlayTrack() after 1x next() starting by firstSong] => SecondSongSelected","SecondSongSelected", cdPlayer1, 1, cdPlayer1.getSongByNumber(1)),
Arguments.of("[getActualPlayTrack() after 2x next() starting by firstSong] => ThirdSongSelected","ThirdSongSelected" ,cdPlayer2,2,cdPlayer2.getSongByNumber(2)),
Arguments.of("[getActualPlayTrack() after 1x next() starting by lastSong] => FirstSongSelected","FirstSongSelected", cdPlayer3,cdPlayer3.getItemList().length,cdPlayer3.getSongByNumber(0))
);
}
@ParameterizedTest
@MethodSource("prevTestData")
void prevTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, String expectedResult){
if(testDirection.equals("StartingBySecondSong")) {
_cdPlayer.next();
}
if(testDirection.equals("StartingByThirdSong")) {
_cdPlayer.next();
_cdPlayer.next();
}
for (int i = 0; i < anzClicks; i++) {
_cdPlayer.prev();
}
assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> prevTestData () {
String[] audioPlayList = new String[]{"Audio 01", "Audio 02", "Audio 03", "Audio 04", "Audio 05"};
CD audioCD = new CD("Audio", audioPlayList);
CDPlayer cdPlayer1 = new CDPlayer();
cdPlayer1.tapOnCdFlap();
cdPlayer1.setCD(audioCD);
cdPlayer1.tapOnCdFlap();
return Stream.of(
Arguments.of("[getActualPlayTrack() after 1x prev() starting by secondSong] => FirstSongSelected", "StartingBySecondSong", cdPlayer1, 1, cdPlayer1.getSongByNumber(0)),
Arguments.of("[getActualPlayTrack() after 2x prev() starting by thirdSong] => FirstSongSelected", "StartingByThirdSong", cdPlayer1, 2, cdPlayer1.getSongByNumber(0)),
Arguments.of("[getActualPlayTrack() after 1x prev() starting by firstSong] => FirstSongSelected", "StartingByFirstSong", cdPlayer1, 1, cdPlayer1.getSongByNumber(0))
);
}
@ParameterizedTest
@MethodSource("getOptionsTestData")
void getOptionsTest(String testName,String testDirection, CDPlayer _cdPlayer){
if(testDirection.equals("ReturnValueNotNull")) {
assertThat(_cdPlayer.getOptions()).describedAs(testName).isNotEqualTo(null);
}
if(testDirection.equals("ArrayLengthGreaterThen0")) {
assertThat(_cdPlayer.getOptions().length).describedAs(testName).isNotEqualTo(0);
}
if(testDirection.equals("ArrayContainsInterfaceMethods")) {
Method[]interfaceMethods=Device.class.getDeclaredMethods();
List<String> deviceMethods = new ArrayList<String>(Arrays.asList(_cdPlayer.getOptions()));
for (int i = 0; i < interfaceMethods.length; i++) {
assertThat(deviceMethods.contains(interfaceMethods[i].getName())).describedAs(testName).isEqualTo(true);
}
}
}
static Stream<Arguments> getOptionsTestData () {
CDPlayer cdPlayer1 = new CDPlayer();
return Stream.of(
Arguments.of("[getOptions(): shouldNotReturnNull] => ReturnValueNotNull", "ReturnValueNotNull", cdPlayer1),
Arguments.of("[getOptions(): shouldReturnAnArrayWithLengthGreaterThen0] => ArrayLengthGreaterThen0", "ArrayLengthGreaterThen0", cdPlayer1),
Arguments.of("[getOptions(): shouldReturnAnArrayWithInAllInterfaceMethods] => ArrayContainsInterfaceMethods", "ArrayContainsInterfaceMethods", cdPlayer1)
);
}
@Test
void getVolumeReturnValueBetween0And100(){
CDPlayer cdPlayer1 = new CDPlayer();
boolean volumeIstInValueRange=false;
int volume=cdPlayer1.getVolume();
if(volume>=0 && volume <=100){
volumeIstInValueRange=true;
}
assertThat(volumeIstInValueRange).isEqualTo(true);
}
@ParameterizedTest
@MethodSource("getInfoTestData")
void getInfoTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception , String expectedResult){
if(cases.equals("Case1")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.getInfoText());
assertEquals(ReturnValueNullException.class, newException.getClass());
}
if(cases.equals("Case2")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.getInfoText());
assertThat(newException.getMessage()).describedAs(testName).isEqualTo(expectedResult);
}
if(cases.equals("Case3")) {
String[] album= _cdPlayer.getItemList();
boolean containsInfoOfActualPlayTrack=false;
for (int i = 0; i < album.length; i++) {
if(_cdPlayer.getInfoText().contains(expectedResult))
containsInfoOfActualPlayTrack=true;
}
assertThat(containsInfoOfActualPlayTrack).describedAs(testName).isEqualTo(true);
}
if(cases.equals("Case4")) {
String albumName= _cdPlayer.getCD().getAlbumName();
assertThat(_cdPlayer.getInfoText().contains(albumName)).describedAs(testName).isEqualTo(true);
}
if(cases.equals("Case5")) {
assertThat(_cdPlayer.getInfoText().contains("CDPlayer")).describedAs(testName).isEqualTo(true);
}
}
static Stream<Arguments> getInfoTestData () {
CDPlayer cdPlayer1 = new CDPlayer();
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 cdPlayer2 = new CDPlayer();
cdPlayer2.tapOnCdFlap();
cdPlayer2.setCD(audioCD1);
cdPlayer2.tapOnCdFlap();
cdPlayer2.setInfoText();
return Stream.of(
Arguments.of("[getActualPlayTrack() after 1x next() starting by firstSong] => SecondSongSelected","SecondSongSelected", cdPlayer, 1, cdPlayer.getSongByNumber(1))
Arguments.of("[getInfoText() by infoText=null ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),""),
Arguments.of("[getInfoText() by infoText=null ] => ExceptionShouldReturnAMessage","Case2",cdPlayer1,new ReturnValueNullException(),"Method should not return a Null-Value."),
Arguments.of("[getInfoText() by infoText=Message ] => MessageShouldContainInfoOfActualPlayTrack","Case3",cdPlayer2,null,""),
Arguments.of("[getInfoText() by infoText=Message ] => MessageShouldContainInfoAboutAlbum","Case4",cdPlayer2,null,""),
Arguments.of("[getInfoText() by infoText=Message ] => MessageShouldContainInfoAboutDevice","Case5",cdPlayer2,null,"")
);
}

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

@ -1,25 +1,26 @@
package device.radioPlayer;
import device.radioPlayer.RadioPlayer;
import device.usbPlayer.UsbPlayer;
import device.Device;
import org.assertj.core.util.Strings;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat;
class RadioPlayerTest {
@ParameterizedTest
@MethodSource("quieterLouderOptions")
void quieterLouderTest(String testName, RadioPlayer testRp, int expectedResult) {
int volume = testRp.getLautstaerke();
int volume = testRp.getVolume();
assertThat(volume).describedAs(testName).isEqualTo(expectedResult);
}
@ -28,13 +29,13 @@ class RadioPlayerTest {
RadioPlayer rp2 = new RadioPlayer();
RadioPlayer rp3 = new RadioPlayer();
RadioPlayer rp4 = new RadioPlayer();
rp1.setLautstaerke(0);
rp1.setVolume(0);
rp1.louder();
rp2.setLautstaerke(100);
rp2.setVolume(100);
rp2.louder();
rp3.setLautstaerke(1);
rp3.setVolume(1);
rp3.quieter();
rp4.setLautstaerke(0);
rp4.setVolume(0);
rp4.quieter();
return Stream.of(
Arguments.of("Test for one step louder", rp1, 1),
@ -47,7 +48,7 @@ class RadioPlayerTest {
@ParameterizedTest
@MethodSource("changeRegionOptions")
void changeRegionTest(String testName, RadioPlayer testRp, String expectedResult) {
String station = testRp.playTrack;
String station = testRp.playedStation;
assertThat(station).describedAs(testName).isEqualTo(expectedResult);
}
@ -58,7 +59,6 @@ class RadioPlayerTest {
rp1.changeRegion("BY");
rp2.changeRegion("HE");
rp3.changeRegion("BW");
return Stream.of(
Arguments.of("Test change Region to Bayern", rp1, "Antenne Bayern"),
Arguments.of("Test change Region to Hessen", rp2, "Hit Radio FFH"),
@ -66,69 +66,73 @@ class RadioPlayerTest {
);
}
/*
@Test
void getVolume() {
}
*/
@ParameterizedTest
@MethodSource("prevNextOptions")
void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) {
String station = testRp.playTrack;
String station = testRp.playedStation;
assertThat(station).describedAs(testName).isEqualTo(expectedResult);
}
}
static Stream<Arguments> prevNextOptions() {
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
RadioPlayer rp3 = new RadioPlayer();
RadioPlayer rp4 = new RadioPlayer();
RadioPlayer rp5 = new RadioPlayer();
RadioPlayer rp6 = new RadioPlayer();
rp1.next();
rp2.next();
rp2.prev();
rp3.prev();
rp4.changeRegion("BY");
rp4.next();
rp5.changeRegion("BY");
rp5.prev();
rp6.changeRegion("BY");
rp6.saveStation();
rp6.next();
return Stream.of(
Arguments.of("Next Station Test", rp1, "Teddy"),
Arguments.of("Prev Station Test", rp2, "YouFM"),
Arguments.of("Prev works on first Station ", rp3, "MegaHits")
Arguments.of("Next Station Test for saved Stations", rp1, "Teddy"),
Arguments.of("Prev Station Test for saved Stations", rp2, "YouFM"),
Arguments.of("Prev works on first Station for saved Stations", rp3, "MegaHits"),
Arguments.of("changed Region and going to next station", rp4, "Bayern 1"),
Arguments.of("changed Region and going to prev station", rp5, "Hit Radio N1"),
Arguments.of("changed Region, saved station and going to next station", rp6, "YouFM")
);
}
@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();
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
@ -148,7 +152,6 @@ class RadioPlayerTest {
rp3.next();
RadioPlayer rp4 = new RadioPlayer();
rp4.next();
return Stream.of(
Arguments.of("Show Station Info for first saved Radio", rp1, rp1.getYouFMInfoByTime(rp1.hour)),
Arguments.of("Show Station Info for regional Station", rp2, rp2.getAntenneBYInfoByTime(rp2.hour)),
@ -157,23 +160,265 @@ class RadioPlayerTest {
);
}
/*
@ParameterizedTest
@MethodSource("chooseItemOptions")
void testChooseItem(String testName, RadioPlayer testRp, String expectedResult) {
String playedStation = testRp.playedStation;
assertThat(playedStation).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> chooseItemOptions() {
RadioPlayer rp = new RadioPlayer();
rp.chooseItem(2);
RadioPlayer rp1 = new RadioPlayer();
rp1.chooseItem(5);
RadioPlayer rp2 = new RadioPlayer();
rp2.chooseItem(-1);
RadioPlayer rp3 = new RadioPlayer();
rp3.changeRegion("BY");
rp3.chooseItem(2);
RadioPlayer rp4 = new RadioPlayer();
rp4.changeRegion("BY");
rp4.chooseItem(5);
RadioPlayer rp5 = new RadioPlayer();
rp5.changeRegion("BY");
rp5.chooseItem(-2);
return Stream.of(
Arguments.of("Test select station in saved playlist to play with nr isn`t bigger than playlist size", rp, "Teddy"),
Arguments.of("Test select station in saved playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp1, "MegaHits"),
Arguments.of("Test select station in saved playlist to play with nr is lower than 0. First station in playlist gets played", rp2, "YouFM"),
Arguments.of("Test select station in regional playlist to play with nr isn`t bigger than playlist size", rp3, "Bayern 1"),
Arguments.of("Test select station in regional playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp4, "Hit Radio N1"),
Arguments.of("Test select station in regional playlist to play with nr is lower than 0. Last station in playlist gets played", rp5, "Antenne Bayern")
);
}
@ParameterizedTest
@MethodSource("testPlayOptions")
void testPlay(String testName, RadioPlayer testRp, String expectedResult) {
String playedStation = testRp.play();
assertThat(playedStation).describedAs(testName).isEqualTo(expectedResult);
}
@Test
void getInfoText() {
static Stream<Arguments> testPlayOptions() {
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
rp2.changeRegion("BY");
return Stream.of(
Arguments.of("Test for playing first station on saved playlist", rp1, "Radio is playing station: 01 YouFM from saved playlist"),
Arguments.of("Test for playing first station on regional playlist", rp2, "Radio is playing station: 01 Antenne Bayern from regional playlist")
);
}
@Test
void getOptions() {
@ParameterizedTest
@MethodSource("saveStationOptions")
void testSaveStation(String testName, RadioPlayer testRp, String testTyp, String expectedResult) {
String savedStation;
if (testTyp.equals("normal")) {
savedStation = testRp.savedPlaylist.get(testRp.savedPlaylist.size() - 1);
} else savedStation = Boolean.toString(testRp.regionPlaylist.isEmpty());
assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult);
}
@Test
void chooseOption() {
static Stream<Arguments> saveStationOptions() {
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
RadioPlayer rp3 = new RadioPlayer();
rp1.changeRegion("BY");
rp1.saveStation();
rp2.saveStation();
rp3.changeRegion("BY");
rp3.saveStation();
return Stream.of(
Arguments.of("Test for saving station in saved playlist", rp1, "normal", "Antenne Bayern"),
Arguments.of("Test for not saving station which is already in saved playlist", rp2, "normal", "MegaHits"),
Arguments.of("Test for after saving station jump back to saved playlist", rp3, "jump", "true")
);
}
@ParameterizedTest
@MethodSource("deleteStationOptions")
void testDeleteStation(String testName, RadioPlayer testRp, String testTyp, Boolean expectedResult) {
Boolean savedStation;
if (testTyp.equals("delete")) {
savedStation = testRp.savedPlaylist.contains("YouFM");
} else savedStation = testRp.savedPlaylist.contains("MegaHits");
assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> deleteStationOptions() {
RadioPlayer rp = new RadioPlayer();
rp.deleteStation();
RadioPlayer rp1 = new RadioPlayer();
rp1.deleteStation();
rp1.deleteStation();
rp1.deleteStation();
return Stream.of(
Arguments.of("Test for delete station in saved playlist", rp, "delete", false),
Arguments.of("Test for not delete station in saved playlist if this is the last station", rp1, "noDelete", true)
);
}
@ParameterizedTest
@MethodSource("changeToSavedPlaylistOptions")
void testChangeToSavedPlaylist(String testName, RadioPlayer testRp, String expectedResult) {
String savedStation = testRp.playedStation;
assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> changeToSavedPlaylistOptions() {
RadioPlayer rp = new RadioPlayer();
rp.changeToSavedPlaylist();
RadioPlayer rp1 = new RadioPlayer();
rp1.changeRegion("BY");
rp1.changeToSavedPlaylist();
return Stream.of(
Arguments.of("Test for change to saved playlist when you already in saved playlist", rp, "YouFM"),
Arguments.of("Test for change to saved playlist when in regional playlist", rp1, "YouFM")
);
}
@ParameterizedTest
@MethodSource("changeOrderInSavedPlaylistOptions")
void testChangeOrderInSavedPlaylist(String testName, RadioPlayer testRp, int nr, String expectedResult) {
String savedStation = testRp.savedPlaylist.get(nr);
assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> changeOrderInSavedPlaylistOptions() {
RadioPlayer rp = new RadioPlayer();
rp.next();
rp.changeOrderInSavedPlaylist(1);
RadioPlayer rp1 = new RadioPlayer();
rp1.changeOrderInSavedPlaylist(5);
RadioPlayer rp2 = new RadioPlayer();
rp2.next();
rp2.changeOrderInSavedPlaylist(-1);
return Stream.of(
Arguments.of("Test for change order in saved playlist with nr isn`t bigger than playlist size", rp, 0, "Teddy"),
Arguments.of("Test for change order in saved playlist with nr is than bigger playlist size put at the end of playlist", rp1, 2, "YouFM"),
Arguments.of("Test for change order in saved playlist with nr is than smaller than 0 at front of playlist", rp2, 0, "Teddy")
);
}
@ParameterizedTest
@MethodSource("getItemListOptions")
void testGetItemList(String testName, RadioPlayer testRp, String testTyp, String[] expectedResult) {
if (testTyp.equals("region")) {
testRp.changeRegion("BY");
}
String[] playList = testRp.getItemList();
assertThat(playList).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> getItemListOptions() {
RadioPlayer rp = new RadioPlayer();
RadioPlayer rp1 = new RadioPlayer();
rp1.changeRegion("BY");
return Stream.of(
Arguments.of("Test for return saved playlist", rp, "saved", rp.savedPlaylist.toArray(new String[0])),
Arguments.of("Test for return regional playlist", rp1, "region", rp1.regionPlaylist.toArray(new String[0]))
);
}
@ParameterizedTest
@MethodSource("muteOptions")
void testMute(String testName, String testTyp, RadioPlayer testRp, int expectedResult) {
int volume;
if (testTyp.equals("actual")) volume = testRp.getVolume();
else volume = testRp.savedVolume;
assertThat(volume).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> muteOptions() {
RadioPlayer rp = new RadioPlayer();
rp.setVolume(25);
rp.mute();
RadioPlayer rp1 = new RadioPlayer();
rp1.setVolume(30);
rp1.mute();
return Stream.of(
Arguments.of("Test for mute RadioPlayer if volume is actually 0", "actual", rp, 0),
Arguments.of("Test for mute RadioPlayer if volume is saved before muting", "saved", rp1, 30)
);
}
@Test
void play() {
void testUnmute() {
RadioPlayer rp = new RadioPlayer();
rp.setVolume(40);
rp.mute();
rp.unmute();
assertThat(rp.getVolume()).describedAs("Test if unmute is setting the saved volume").isEqualTo(rp.savedVolume);
}
@ParameterizedTest
@MethodSource("getInfoTextOptions")
void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) {
Boolean bool;
if (testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText());
else if (testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation);
else if (testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist");
else if (testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist");
else if (testTyp.contains("savedNum"))
bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1);
else if (testTyp.contains("regionNum"))
bool = testRp.getInfoText().contains(("0") + testRp.regionPlaylist.indexOf(testRp.playedStation) + 1);
else if (testTyp.contains("stationInfo")) bool = testRp.getInfoText().contains("Now playing");
else bool = testRp.getInfoText().contains("Now playing");
assertThat(bool).describedAs(testName).isEqualTo(expectedResult);
}
*/
static Stream<Arguments> getInfoTextOptions() {
RadioPlayer rp = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
rp2.changeRegion("BY");
RadioPlayer rp4 = new RadioPlayer();
rp4.next();
RadioPlayer rp5 = new RadioPlayer();
rp5.changeRegion("HE");
rp5.next();
RadioPlayer rp6 = new RadioPlayer();
rp6.changeRegion("BY");
RadioPlayer rp7 = new RadioPlayer();
rp7.next();
return Stream.of(
Arguments.of("Test for getInfoText is not empty or null", "null", rp, false),
Arguments.of("Test for getInfoText contains played station", "station", rp, true),
Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true),
Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp, true),
Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true),
Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true),
Arguments.of("Test for getInfoText contains station info if station has one", "stationInfo", rp6, true),
Arguments.of("Test for getInfoText not contains station info if station not has one", "noStationInfo", rp7, false)
);
}
@ParameterizedTest
@MethodSource("getOptionsOptions")
void testGetOptions(String testName, String testTyp, RadioPlayer testRp) {
if (testTyp.equals("notNull")) assertThat(testRp.getOptions()).describedAs(testName).isNotEqualTo(null);
if (testTyp.equals("arrayLengthGreater0"))
assertThat(testRp.getOptions().length).describedAs(testName).isNotEqualTo(0);
else {
Method[] interfaceMethods = Device.class.getDeclaredMethods();
List<String> deviceMethods = new ArrayList<>(Arrays.asList(testRp.getOptions()));
for (Method interfaceMethod : interfaceMethods) {
assertThat(deviceMethods.contains(interfaceMethod.getName())).describedAs(testName).isEqualTo(true);
}
}
}
static Stream<Arguments> getOptionsOptions() {
RadioPlayer rp = new RadioPlayer();
return Stream.of(
Arguments.of("returnValue of getOptions is not null", "notNull", rp),
Arguments.of("should not return an empty array", "arrayLengthGreater0", rp),
Arguments.of("Test if all methods declared in interface device are available", "device", rp)
);
}
}

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

@ -0,0 +1,71 @@
package device.usbPlayer;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;//hasMessageMatching
import java.util.stream.Stream;
import java.util.ArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.assertj.core.api.AssertionsForClassTypes.catchThrowable;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class USB_StickTest {
@ParameterizedTest
@MethodSource("getAlbumOptions")
void getAlbumTest(String testName, USB_Stick s, int TestNr) throws NoFolderFound {
ArrayList<String> album =new ArrayList<String>();
if (TestNr == 1){
album = s.getAlbum();
assertThat(album).describedAs(testName).isNotEmpty();}
else {
// when
Throwable thrown = catchThrowable(() -> s.getAlbum());
// then
assertThat(thrown)
.isInstanceOf(NoFolderFound.class)
.hasMessageContaining("The USB Drive is empty");
}
}
static Stream<Arguments> getAlbumOptions() throws NoFolderFound {
USB_Stick stick = new USB_Stick();
USB_Stick emptyStick = new USB_Stick("");
return Stream.of(
Arguments.of("First Album is loaded", stick, 1),
Arguments.of("No Album is loaded", emptyStick, 2)
);
}
//ChangeAlbum
@ParameterizedTest
@MethodSource("ChangeAlbumOptions")
void ChangeAlbumTest(String testName, USB_Stick s) throws NoFolderFound {
ArrayList<String> a = new ArrayList<String>();
a = s.getAlbum();
assertThat(a).describedAs(testName).contains("File 01.txt", "File 02.txt", "File 03.txt");
}
static Stream<Arguments> ChangeAlbumOptions() {
USB_Stick stick = new USB_Stick();
ArrayList<String> AlbumsItems = new ArrayList<>();
stick.ChangeAlbum();
return Stream.of(
Arguments.of("First Album is loaded", stick)//,something
);
}
}

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

@ -3,6 +3,7 @@ package device.usbPlayer;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;
import java.util.ArrayList;
@ -48,12 +49,12 @@ class UsbPlayerTest {
}
@ParameterizedTest
@MethodSource("louderOptions")
void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) {
int volumeNum = inputPlay.getLautstaerke();
assertThat(volumeNum).describedAs(testName).isEqualTo(expectedResult);
}
@ParameterizedTest
@MethodSource("louderOptions")
void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) {
int volumeNum = inputPlay.getLautstaerke();
assertThat(volumeNum).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> louderOptions() {
UsbPlayer up11 = new UsbPlayer();
@ -114,7 +115,6 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) {
);
}
////////////////
@ParameterizedTest
@MethodSource("PrevOptions")
void PrevTest(String testName, UsbPlayer inputPlay, String expectedResult) {
@ -137,4 +137,258 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) {
);
}
@ParameterizedTest
@MethodSource("louder_10_Options")
void louder_10_Test(String testName, UsbPlayer inputPlay, int expectedResult) {
int volumeNum = inputPlay.getLautstaerke();
assertThat(volumeNum).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> louder_10_Options() {
UsbPlayer up1 = new UsbPlayer();
up1.Louder_10();
UsbPlayer up2 = new UsbPlayer();
for (int i = 0; i <= 3; i++) {
up2.Louder_10();
}
up2.quieter_10();
UsbPlayer up3 = new UsbPlayer();
up3.setLautstaerke(100);
up3.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)
);
}
@ParameterizedTest
@MethodSource("quieter_10_Options")
void quieter_10_Test(String testName, UsbPlayer inputPlay, int expectedResult) {
int volumeNum = inputPlay.getLautstaerke();
assertThat(volumeNum).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> quieter_10_Options() {
UsbPlayer up1 = new UsbPlayer();
up1.setLautstaerke(10);
up1.quieter_10();
UsbPlayer up2 = new UsbPlayer();
up2.setLautstaerke(50);
for (int i = 0; i < 3; i++) {
up2.quieter_10();
}
UsbPlayer up3 = new UsbPlayer();
up3.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)
);
}
@ParameterizedTest
@MethodSource("FindSongOptions")
void findSongTest(String testName, int inputPlay, int expectedResult) {
//first case: the song is not in the Album
// int songLoc1 = inputPlay.findSong("song 4");
assertThat(inputPlay).describedAs(testName).isEqualTo(expectedResult);
//Second Case: the song is in the album
// int songLoc2 = inputPlay.findSong("Musik 02");
assertThat(inputPlay).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> FindSongOptions() {
UsbPlayer up1 = new UsbPlayer();
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),
Arguments.of("Name of the Song is in lower case :", up1.findSong("musik 02"), 1),
Arguments.of("Name of the Song is in upper case :", up1.findSong("MUSIK 02"), 1)
);
}
@ParameterizedTest
@MethodSource("GoToOptions")
void GoToTest(String testName, UsbPlayer inputPlay, String expectedResult) {
String current_Track = inputPlay.getPlayTrack();
assertThat(current_Track).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> GoToOptions() {
UsbPlayer up1 = new UsbPlayer();
up1.GoTo("Musik 03.mp3");
UsbPlayer up2 = new UsbPlayer();
up2.GoTo("Musik 04.mp3");
UsbPlayer up3 = new UsbPlayer();
up3.GoTo("Musik 02");
UsbPlayer up4 = new UsbPlayer();
up4.next();
up4.GoTo("Musik");
return Stream.of(
Arguments.of("Go to Song : Musik 03.mp3 ", up1, "Musik 03.mp3"),
Arguments.of("Go to Song that is not in the Album: Musik 04.mp3 ", up2, "Musik 01.mp3"),
Arguments.of("Go to Song without writing the full Name : Musik 02 ", up3, "Musik 02.mp3"),
Arguments.of("Go to Song and write a Name that many songs starts with : Musik", up4, "Musik 01.mp3")
);
}
@ParameterizedTest
@MethodSource("isAllAudioOptions")
void isAllAudioTest(String testName, boolean inputTestResult, boolean expectedResult) {
// String current_Track = inputPlay.getPlayTrack();
assertThat(inputTestResult).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> isAllAudioOptions() {
//mp3
UsbPlayer up1 = new UsbPlayer();
//mp4
UsbPlayer up2 = new UsbPlayer();
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();
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();
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();
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();
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();
ArrayList<String> Pl5 = new ArrayList<String>();
Pl5.add("Musik 01.aac");
Pl5.add("Musik 02.txt");
Pl5.add("Musik 03.aac");
up7.setPlaylist(Pl5);
return Stream.of(
Arguments.of("Check if the Files are .mp3 ", up1.isAllAudio(), true),
Arguments.of("Check if the Files are .mp4 ", up2.isAllAudio(), true),
Arguments.of("Check if the Files are .m4a ", up3.isAllAudio(), true),
Arguments.of("Check if the Files are .wav ", up4.isAllAudio(), true),
Arguments.of("Check if the Files are .wma ", up5.isAllAudio(), true),
Arguments.of("Check if the Files are .aac ", up6.isAllAudio(), true),
Arguments.of("Check case of mixed Files", up7.isAllAudio(), false)
);
}
//GoToFirst()
@ParameterizedTest
@MethodSource("GoToFirstOptions")
void GoToFirstTest(String testName, UsbPlayer inputUSB, String expectedResult) {
String firstSong = inputUSB.getPlayTrack();
assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> GoToFirstOptions() {
UsbPlayer up1 = new UsbPlayer();
up1.GoToFirst();
UsbPlayer up2 = new UsbPlayer();
up2.GoToFirst();
up2.GoToFirst();
UsbPlayer up3 = new UsbPlayer();
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))
);
}
@ParameterizedTest
@MethodSource("GoToLastOptions")
void GoToLastTest(String testName, UsbPlayer inputUSB, String expectedResult) {
String firstSong = inputUSB.getPlayTrack();
assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> GoToLastOptions() {
//first case
UsbPlayer up1 = new UsbPlayer();
up1.GoToLast();
UsbPlayer up2 = new UsbPlayer();
up2.GoToLast();
up2.GoToLast();
UsbPlayer up3 = new UsbPlayer();
up3.next();
up3.GoToLast();
return Stream.of(
Arguments.of("It should go to the Last Song ", up1,up1.getPlaylist().get(up1.getPlaylist().size()-1)),
Arguments.of("It should go to the Last Song even after calling the function twice ", up2,up2.getPlaylist().get(up2.getPlaylist().size()-1)),
Arguments.of("It should go to the Last Song even changing the current song ", up3,up3.getPlaylist().get(up3.getPlaylist().size()-1))
);
}
@ParameterizedTest
@MethodSource("setPlayTrackOptions")
void setPlayTrackTest(String testName, UsbPlayer inputUSB, String expectedResult) {
String firstSong = inputUSB.getPlayTrack();
assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> setPlayTrackOptions() {
//first case
UsbPlayer up1 = new UsbPlayer();
up1.setPlayTrack("Musik 02.mp3");
//Second Case
UsbPlayer up2 = new UsbPlayer();
up2.setPlayTrack("Musik 02.mp3");
//Third Case
UsbPlayer up3 = new UsbPlayer();
up3.setPlayTrack("Musik 04.mp3");
return Stream.of(
Arguments.of("It should change the current Song ", up1,"Musik 02.mp3"),
Arguments.of("It should change the current Song if it is in the Albume", up2,"Musik 02.mp3"),
Arguments.of("Tried to change the Song,but the Song name does not exist in the Album(No change)", up3,"Musik 01.mp3")
);
}
}
Loading…
Cancel
Save