From 1649116dd08d5ccb2eebab1473a5438fa06b74bd Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 21:39:50 +0100 Subject: [PATCH] Production-Code for CDPlayer-Method [Quieter] produced. --- src/main/java/device/cdPlayer/CDPlayer.java | 2 +- .../java/device/cdPlayer/CDPlayerTest.java | 75 ++++++++++--------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 6cc7b77..1f5ea0e 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -31,7 +31,7 @@ public class CDPlayer implements Device { @Override public int getVolume() { - return 0; + return volume; } @Override diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index eb63e35..548d937 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -1,47 +1,52 @@ package device.cdPlayer; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.junit.jupiter.MockitoExtension; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; +@ExtendWith(MockitoExtension.class) class CDPlayerTest { -/* - @Test - void louder() { - } - - @Test - void quieter() { - } - - @Test - void getVolume() { - } - - @Test - void next() { - } - - @Test - void prev() { - } - - @Test - void getInfoText() { - } - - @Test - void getOptions() { - } - - @Test - void chooseOption() { - } - @Test - void play() { + @ParameterizedTest + @MethodSource("quieterTestData") + void quieterTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, int expectedResult) { + for (int i = 0; i < anzClicks; i++) { + _cdPlayer.quieter(); + } + + if(testDirection.equals("VolumeDecreased")){ + for (int i = 0; i < 20; i++) { + _cdPlayer.louder(); + } + for (int i = 0; i < anzClicks; i++) { + _cdPlayer.quieter(); + } + assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(expectedResult); + } + if(testDirection.equals("VolumeHasNotChanged")){ + assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(expectedResult); + }if(testDirection.equals("VolumeNotIncreased")){ + + assertThat(_cdPlayer.getVolume()).describedAs(testName).isNotEqualTo(expectedResult); + } + } + + static Stream quieterTestData () { + CDPlayer cdPlayer=new CDPlayer(); + return Stream.of( + Arguments.of("[getVolume() after 20x quieter() starting by 20] => VolumeHasDecreased","VolumeDecreased", cdPlayer, 19, 1), + Arguments.of("[getVolume() after 20x quieter() starting by 0] => VolumeHasNotChanged","VolumeHasNotChanged" ,cdPlayer,20,0), + Arguments.of("[getVolume() after 5x quieter() starting by 0] => VolumeNotIncreased","VolumeNotIncreased", cdPlayer,5,5) + ); } - */ } \ No newline at end of file