diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 304d03d..ca99dfb 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -25,6 +25,9 @@ public class CDPlayer implements Device { private ListfavoriteSongs=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 getFavoriteSongs() { return favoriteSongs; } + + public boolean isMuted() { + return muted; + } + + public int getOldVolume() { + return oldVolume; + } + } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index c3cda36..06cdff8 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/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 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 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.") + ); + } + + } \ No newline at end of file