From 3f1d220ac84f5b77a9d29983fce2aa97d9770b3d Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 21:45:43 +0100 Subject: [PATCH 1/8] Method mute of CDPlayer tested on checkingTheReturnValue -> ShouldReturnAString. --- src/main/java/device/cdPlayer/CDPlayer.java | 2 +- src/test/java/device/cdPlayer/CDPlayerTest.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 304d03d..e1da09f 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -109,7 +109,7 @@ public class CDPlayer implements Device { @Override public String mute() { - return null; + return ("Volume muted."); } @Override diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index c3cda36..354719a 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,19 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("muteTestData") + void muteTest(String testName,String cases, CDPlayer _cdPlayer,String expectedResult) { + assertThat(_cdPlayer.mute()).describedAs(testName).isEqualTo(expectedResult); + } + static Stream muteTestData () { + CDPlayer cdPlayer1 = new CDPlayer(); + return Stream.of( + Arguments.of("[mute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume muted.") + ); + } + + + + } \ No newline at end of file From c0ed52776b4fcfdeb9a8f1b97c16d2a2d697678b Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 21:59:30 +0100 Subject: [PATCH 2/8] Method mute of CDPlayer tested on checkingTheEffectAfterRun -> VariableMutedShouldBeTrue. --- src/main/java/device/cdPlayer/CDPlayer.java | 7 +++++++ src/test/java/device/cdPlayer/CDPlayerTest.java | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index e1da09f..23714be 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -25,6 +25,8 @@ public class CDPlayer implements Device { private ListfavoriteSongs=new ArrayList<>(); + private boolean muted=false; + @Override public void louder() { if(volume < 100) { @@ -109,6 +111,7 @@ public class CDPlayer implements Device { @Override public String mute() { + muted=true; return ("Volume muted."); } @@ -229,4 +232,8 @@ public class CDPlayer implements Device { public List getFavoriteSongs() { return favoriteSongs; } + + public boolean isMuted() { + return muted; + } } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 354719a..1786fc8 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -534,12 +534,19 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("muteTestData") void muteTest(String testName,String cases, CDPlayer _cdPlayer,String expectedResult) { - assertThat(_cdPlayer.mute()).describedAs(testName).isEqualTo(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); + } } static Stream muteTestData () { CDPlayer cdPlayer1 = new CDPlayer(); return Stream.of( - Arguments.of("[mute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume muted.") + Arguments.of("[mute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume muted."), + Arguments.of("[mute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeTrue", "Case2", cdPlayer1, "Volume muted.") ); } From aaee24a3c5e83849ba78366a01738a24334c0690 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:07:24 +0100 Subject: [PATCH 3/8] Method mute of CDPlayer tested after 2x louder() by checkingTheVolume -> VolumeShouldBeSetTo0. --- src/main/java/device/cdPlayer/CDPlayer.java | 1 + src/test/java/device/cdPlayer/CDPlayerTest.java | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 23714be..618bc1d 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -112,6 +112,7 @@ public class CDPlayer implements Device { @Override public String mute() { muted=true; + volume=0; return ("Volume muted."); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 1786fc8..2f4a4dc 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -541,12 +541,19 @@ class CDPlayerTest { _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); + } } 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() by checkingTheEffectAfterRun ] => VariableMutedShouldBeTrue", "Case2", cdPlayer1, "Volume muted."), + Arguments.of("[mute() after 2x louder() by checkingTheVolume] => VolumeShouldBeSetTo0", "Case3", cdPlayer1, "Volume muted.") ); } From 9d7abe2b431c29945b56c24daf5cfba0810917a8 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:14:40 +0100 Subject: [PATCH 4/8] Method mute of CDPlayer tested after 5x louder() by checkingTheSavedOldVolume -> getOldVolumeShouldReturns_5. --- src/main/java/device/cdPlayer/CDPlayer.java | 7 +++++++ src/test/java/device/cdPlayer/CDPlayerTest.java | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 618bc1d..09e52fa 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -26,6 +26,7 @@ public class CDPlayer implements Device { private ListfavoriteSongs=new ArrayList<>(); private boolean muted=false; + private int oldVolume=0; @Override public void louder() { @@ -112,6 +113,7 @@ public class CDPlayer implements Device { @Override public String mute() { muted=true; + oldVolume=volume; volume=0; return ("Volume muted."); } @@ -237,4 +239,9 @@ public class CDPlayer implements Device { 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 2f4a4dc..5975e17 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -547,13 +547,21 @@ class CDPlayerTest { _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 2x louder() by checkingTheVolume] => VolumeShouldBeSetTo0", "Case3", cdPlayer1, "Volume muted."), + Arguments.of("[mute() after 5x louder() by checkingTheSavedOldVolume] => getOldVolumeShouldReturns_5", "Case4", cdPlayer1, "Volume muted.") ); } From 5b1c8e910161737a42e9707d8972c896eecba71c Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:23:18 +0100 Subject: [PATCH 5/8] Method mute of CDPlayer tested on checkingTheReturnValue -> ShouldReturnAString. --- src/main/java/device/cdPlayer/CDPlayer.java | 2 +- src/test/java/device/cdPlayer/CDPlayerTest.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 09e52fa..7ee9b81 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -120,7 +120,7 @@ public class CDPlayer implements Device { @Override public String unmute() { - return null; + return ("Volume unmute."); } @Override diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 5975e17..31353b1 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -565,7 +565,17 @@ class CDPlayerTest { ); } - + @ParameterizedTest + @MethodSource("unmuteTestData") + void unmuteTest(String testName,String cases, CDPlayer _cdPlayer,String expectedResult) { + assertThat(_cdPlayer.unmute()).describedAs(testName).isEqualTo(expectedResult); + } + static Stream unmuteTestData () { + CDPlayer cdPlayer1 = new CDPlayer(); + return Stream.of( + Arguments.of("[unmute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume unmute.") + ); + } } \ No newline at end of file From d26513380d5c8def25d11cca201739a601feda08 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:34:43 +0100 Subject: [PATCH 6/8] Method mute of CDPlayer tested on checkingTheEffectAfterRun -> VariableMutedShouldBeFalse. --- src/main/java/device/cdPlayer/CDPlayer.java | 1 + src/test/java/device/cdPlayer/CDPlayerTest.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 7ee9b81..c33f53f 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -120,6 +120,7 @@ public class CDPlayer implements Device { @Override public String unmute() { + muted=false; return ("Volume unmute."); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 31353b1..67fbafc 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -568,12 +568,20 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("unmuteTestData") void unmuteTest(String testName,String cases, CDPlayer _cdPlayer,String expectedResult) { - assertThat(_cdPlayer.unmute()).describedAs(testName).isEqualTo(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); + } } static Stream unmuteTestData () { CDPlayer cdPlayer1 = new CDPlayer(); + cdPlayer1.mute(); return Stream.of( - Arguments.of("[unmute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume unmute.") + Arguments.of("[unmute() by checkingTheReturnValue ] => ShouldReturnAString", "Case1", cdPlayer1, "Volume unmute."), + Arguments.of("[unmute() by checkingTheEffectAfterRun ] => VariableMutedShouldBeFalse", "Case2", cdPlayer1, "Volume unmute.") ); } From 9836e3a26c2d8bd2eccfe936c8e3c3c07024f2fb Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:44:06 +0100 Subject: [PATCH 7/8] Method mute of CDPlayer tested on 5x louder()-> mute() -> getVolumeShouldReturn_5. --- src/main/java/device/cdPlayer/CDPlayer.java | 1 + src/test/java/device/cdPlayer/CDPlayerTest.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index c33f53f..b08c602 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -121,6 +121,7 @@ public class CDPlayer implements Device { @Override public String unmute() { muted=false; + volume=oldVolume; return ("Volume unmute."); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 67fbafc..988a878 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -575,13 +575,22 @@ class CDPlayerTest { _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); + } } static Stream unmuteTestData () { CDPlayer cdPlayer1 = new CDPlayer(); - cdPlayer1.mute(); 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 checkingTheEffectAfterRun ] => VariableMutedShouldBeFalse", "Case2", cdPlayer1, "Volume unmute."), + Arguments.of("[unmute() by 5x louder()-> mute()] => getVolumeShouldReturn_5", "Case3", cdPlayer1, "Volume unmute.") ); } From 9c4084e47940870dd0b38e6ad15b0be0b2820bd3 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:49:18 +0100 Subject: [PATCH 8/8] Method mute of CDPlayer tested on 6x louder()-> mute() -> getOldVolumeShouldReturn_0. --- src/main/java/device/cdPlayer/CDPlayer.java | 1 + src/test/java/device/cdPlayer/CDPlayerTest.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index b08c602..ca99dfb 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -122,6 +122,7 @@ public class CDPlayer implements Device { public String unmute() { muted=false; volume=oldVolume; + oldVolume=0; return ("Volume unmute."); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 988a878..06cdff8 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -584,13 +584,23 @@ class CDPlayerTest { 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 5x louder()-> mute()] => getVolumeShouldReturn_5", "Case3", cdPlayer1, "Volume unmute."), + Arguments.of("[unmute() by 6x louder()-> mute()] => getOldVolumeShouldReturn_0", "Case4", cdPlayer1, "Volume unmute.") ); }