9 Commits

  1. 22
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 76
      src/test/java/device/cdPlayer/CDPlayerTest.java

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

@ -25,6 +25,9 @@ public class CDPlayer implements Device {
private List<String>favoriteSongs=new ArrayList<>();
private boolean muted=false;
private int oldVolume=0;
@Override
public void louder() {
if(volume < 100) {
@ -109,12 +112,18 @@ public class CDPlayer implements Device {
@Override
public String mute() {
return null;
muted=true;
oldVolume=volume;
volume=0;
return ("Volume muted.");
}
@Override
public String unmute() {
return null;
muted=false;
volume=oldVolume;
oldVolume=0;
return ("Volume unmute.");
}
@Override
@ -229,4 +238,13 @@ public class CDPlayer implements Device {
public List<String> getFavoriteSongs() {
return favoriteSongs;
}
public boolean isMuted() {
return muted;
}
public int getOldVolume() {
return oldVolume;
}
}

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

@ -493,7 +493,7 @@ class CDPlayerTest {
@ParameterizedTest
@MethodSource("addToFavoriteSongsData")
void addToFavoriteSongs(String testName,String cases, CDPlayer _cdPlayer,Exception exception) {
void addToFavoriteSongsTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception) {
if(cases.equals("Case1")) {
String myFavoriteSong = _cdPlayer.getCD().getPlayList()[0];
_cdPlayer.addToFavoriteSongs(myFavoriteSong);
@ -531,4 +531,78 @@ class CDPlayerTest {
);
}
@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.")
);
}
}
Loading…
Cancel
Save