From c0ed52776b4fcfdeb9a8f1b97c16d2a2d697678b Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 21:59:30 +0100 Subject: [PATCH] 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.") ); }