Browse Source

Merge commit '067a5c3d70fb8706e80667a50cd73ba67ae1289d' into HEAD

feature-pr-RadioPlayer-cleanUp
Jenkins 3 years ago
parent
commit
fa0526cffb
  1. 14
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 38
      src/test/java/device/cdPlayer/CDPlayerTest.java

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

@ -23,6 +23,8 @@ public class CDPlayer implements Device {
private CDWechseler cdWechseler=null;
private String activeSource="CDDrive";//or CDWechseler
private List<String>favoriteSongs=new ArrayList<>();
@Override
public void louder() {
if(volume < 100) {
@ -164,6 +166,14 @@ public class CDPlayer implements Device {
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
public void setCD(CD _loadedCD) {
@ -215,4 +225,8 @@ public class CDPlayer implements Device {
public CDWechseler getCdWechseler() {
return cdWechseler;
}
public List<String> getFavoriteSongs() {
return favoriteSongs;
}
}

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

@ -491,6 +491,44 @@ class CDPlayerTest {
);
}
@ParameterizedTest
@MethodSource("addToFavoriteSongsData")
void addToFavoriteSongs(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())
);
}
}
Loading…
Cancel
Save