Browse Source

Method addToFavoriteSongs of CDPlayer tested on NotSelectingCDWechseler -> shouldThrowAnException.

feature-pr-jacksonsNewFeature
JPANZO 3 years ago
parent
commit
067a5c3d70
  1. 3
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 10
      src/test/java/device/cdPlayer/CDPlayerTest.java

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

@ -167,6 +167,9 @@ public class CDPlayer implements Device {
this.loadedCD=CDList.get(nextIndex);
}
public void addToFavoriteSongs(String song){
if(activeSource.equals("CDDrive")){
throw new CDWechselerNotRunningException();
}
if(!(favoriteSongs.contains(song))) {
favoriteSongs.add(song);
}

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

@ -506,6 +506,11 @@ class CDPlayerTest {
_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"};
@ -517,9 +522,12 @@ class CDPlayerTest {
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 addingDuplicatedSong] => SongShouldNotBeAdded", "Case2", cdPlayer1, null),
Arguments.of("[addToFavoriteSongs() by NotSelectingCDWechseler] => shouldThrowAnException", "Case3", cdPlayer2, new CDWechselerNotRunningException())
);
}
Loading…
Cancel
Save