Browse Source

Method addToFavoriteSongs of CDPlayer tested on addingDuplicatedSong -> SongShouldNotBeAdded.

feature-pr-jacksonsNewFeature
JPANZO 3 years ago
parent
commit
9e5960da87
  1. 4
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 19
      src/test/java/device/cdPlayer/CDPlayerTest.java

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

@ -167,7 +167,9 @@ public class CDPlayer implements Device {
this.loadedCD=CDList.get(nextIndex);
}
public void addToFavoriteSongs(String song){
favoriteSongs.add(song);
if(!(favoriteSongs.contains(song))) {
favoriteSongs.add(song);
}
}
//Getters, Setters und SupportMethods

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

@ -494,10 +494,18 @@ class CDPlayerTest {
@ParameterizedTest
@MethodSource("addToFavoriteSongsData")
void addToFavoriteSongs(String testName,String cases, CDPlayer _cdPlayer,Exception exception) {
String myFavoriteSong=_cdPlayer.getCD().getPlayList()[0];
_cdPlayer.addToFavoriteSongs(myFavoriteSong);
assertThat(_cdPlayer.getFavoriteSongs().get(0)).describedAs(testName).isEqualTo(myFavoriteSong);
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);
}
}
static Stream<Arguments> addToFavoriteSongsData () {
String[] audioPlayList = new String[]{"Audio 01", "Audio 02", "Audio 03", "Audio 04", "Audio 05"};
@ -510,7 +518,8 @@ class CDPlayerTest {
cdPlayer1.loadCDWechseler(audioCD2, 1);
return Stream.of(
Arguments.of("[addToFavoriteSongs() by addingOneSong] => favoriteSongsShouldReturnsThatAddedSong", "Case1", cdPlayer1, null)
Arguments.of("[addToFavoriteSongs() by addingOneSong] => favoriteSongsShouldReturnsThatAddedSong", "Case1", cdPlayer1, null),
Arguments.of("[addToFavoriteSongs() by addingDuplicatedSong] => SongShouldNotBeAdded", "Case2", cdPlayer1, null)
);
}
Loading…
Cancel
Save