From 192dbd4fc3b0869c3d12ba42d04509ca6e445ed1 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 21:24:47 +0100 Subject: [PATCH 1/2] Test-Code for CDPlayer-Method [Louder] produced. --- .../java/device/cdPlayer/CDPlayerTest.java | 68 +++++++++---------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index eb63e35..1248004 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -1,47 +1,43 @@ 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 static org.junit.jupiter.api.Assertions.*; +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("louderTestData") + void louderTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, int expectedResult) { + for (int i = 0; i < anzClicks; i++) { + _cdPlayer.louder(); + } + if(testDirection.equals("VolumeIncreased")){ + assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(expectedResult); + } + if(testDirection.equals("VolumeHasChanged")){ + assertThat(_cdPlayer.getVolume()).describedAs(testName).isNotEqualTo(expectedResult); + }if(testDirection.equals("VolumeNotDecreased")){ + assertThat(_cdPlayer.getVolume()).describedAs(testName).isNotEqualTo(expectedResult); + } + } + + static Stream louderTestData () { + CDPlayer cdPlayer=new CDPlayer(); + return Stream.of( + Arguments.of("[getVolume() after 20x louder() ] => VolumeIncreased","VolumeIncreased", cdPlayer, 20, 20), + Arguments.of("[getVolume() after 2x louder() ] => VolumeHasChanged","VolumeHasChanged" ,cdPlayer,2,0), + Arguments.of("[getVolume() after 5x louder() ] => VolumeDecreased","VolumeNotDecreased", cdPlayer,5,-5) + ); } - */ } \ No newline at end of file From a1d31ab7fc5899ab396f296a5b10c0a3210b3fde Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 21:30:53 +0100 Subject: [PATCH 2/2] Production-Code for CDPlayer-Method [Louder] produced. --- src/main/java/device/cdPlayer/CDPlayer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 6cc7b77..f66c9d1 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -21,7 +21,11 @@ public class CDPlayer implements Device { @Override public void louder() { - + if(volume < 100) { + volume += 1; + } else { + volume = 100; + } } @Override @@ -31,7 +35,7 @@ public class CDPlayer implements Device { @Override public int getVolume() { - return 0; + return this.volume; } @Override