From 9d7abe2b431c29945b56c24daf5cfba0810917a8 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 22:14:40 +0100 Subject: [PATCH] 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.") ); }