From b2b4e340375e92d729dfe466efd616b9bb075311 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 17:00:23 +0100 Subject: [PATCH 1/3] ProjectStructure changed, CD and ExceptionClasses added. --- Geraete.config | 7 +- src/main/java/device/CDPlayer.java | 50 ------------ src/main/java/device/cdPlayer/CD.java | 33 ++++++++ src/main/java/device/cdPlayer/CDPlayer.java | 79 +++++++++++++++++++ .../exceptions/CdFlapIsOpenException.java | 8 ++ .../FormatNotSupportedException.java | 8 ++ .../cdPlayer/exceptions/NoCDException.java | 8 ++ .../device/{ => radioPlayer}/RadioPlayer.java | 4 +- .../device/{ => usbPlayer}/UsbPlayer.java | 4 +- .../device/{ => cdPlayer}/CDPlayerTest.java | 3 +- .../{ => radioPlayer}/RadioPlayerTest.java | 4 +- .../device/{ => usbPlayer}/UsbPlayerTest.java | 2 +- 12 files changed, 152 insertions(+), 58 deletions(-) delete mode 100644 src/main/java/device/CDPlayer.java create mode 100644 src/main/java/device/cdPlayer/CD.java create mode 100644 src/main/java/device/cdPlayer/CDPlayer.java create mode 100644 src/main/java/device/cdPlayer/exceptions/CdFlapIsOpenException.java create mode 100644 src/main/java/device/cdPlayer/exceptions/FormatNotSupportedException.java create mode 100644 src/main/java/device/cdPlayer/exceptions/NoCDException.java rename src/main/java/device/{ => radioPlayer}/RadioPlayer.java (97%) rename src/main/java/device/{ => usbPlayer}/UsbPlayer.java (95%) rename src/test/java/device/{ => cdPlayer}/CDPlayerTest.java (94%) rename src/test/java/device/{ => radioPlayer}/RadioPlayerTest.java (95%) rename src/test/java/device/{ => usbPlayer}/UsbPlayerTest.java (96%) diff --git a/Geraete.config b/Geraete.config index cb2ada9..a98abfd 100644 --- a/Geraete.config +++ b/Geraete.config @@ -1,3 +1,4 @@ -CD=device.CdPlayer -Radio=device.RadioPlayer -USB=device.UsbPlayer \ No newline at end of file +CD=device.cdPlayer.CdPlayer +Radio=device.radioPlayer.RadioPlayer +USB=device.usbPlayer.UsbPlayer + diff --git a/src/main/java/device/CDPlayer.java b/src/main/java/device/CDPlayer.java deleted file mode 100644 index 366ac5f..0000000 --- a/src/main/java/device/CDPlayer.java +++ /dev/null @@ -1,50 +0,0 @@ -package device; - -public class CDPlayer implements Device { - @Override - public void louder() { - - } - - @Override - public void quieter() { - - } - - @Override - public int getVolume() { - return 0; - } - - @Override - public void next() { - - } - - @Override - public void prev() { - - } - - @Override - public String getInfoText() { - return null; - } - - @Override - public String[] getOptions() { - return new String[0]; - } - - @Override - public String[] getItemList() { - return new String[0]; - } - - - @Override - public String play() { - return null; - } - -} diff --git a/src/main/java/device/cdPlayer/CD.java b/src/main/java/device/cdPlayer/CD.java new file mode 100644 index 0000000..e1f61b3 --- /dev/null +++ b/src/main/java/device/cdPlayer/CD.java @@ -0,0 +1,33 @@ +package device.cdPlayer; + +public class CD { + private String format; + private String[] playList; + + public CD() {} + + public CD(String format) { + this.format = format; + } + + public CD(String format, String[] playList) { + this.format = format; + this.playList = playList; + } + + public String getFormat() { + return format; + } + + public void setFormat(String format) { + this.format = format; + } + + public String[] getPlayList() { + return playList; + } + + public void setPlayList(String[] playList) { + this.playList = playList; + } +} diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java new file mode 100644 index 0000000..6cc7b77 --- /dev/null +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -0,0 +1,79 @@ +package device.cdPlayer; + +import device.Device; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class CDPlayer implements Device { + + // 0-Leer; true-1 + private int CdDriveContent=0; + private int CdFlap=0; + private int volume = 0; + private List supportedFormats = new ArrayList(Arrays.asList(new String[] {"Audio","MP3","WMA","AAC"})); + + private String actualPlayTrack=""; + private CD loadedCD; + private String[] cdAlbum=new String[]{}; + + + @Override + public void louder() { + + } + + @Override + public void quieter() { + + } + + @Override + public int getVolume() { + return 0; + } + + @Override + public void next() { + + } + + @Override + public void prev() { + + } + + @Override + public String getInfoText() { + return null; + } + + @Override + public String[] getOptions() { + return new String[0]; + } + + @Override + public String[] getItemList() { + return new String[0]; + } + + + @Override + public String play() { + return null; + } + + //Getters und Setters + public void setCD(CD _loadedCD) { + loadedCD=_loadedCD; + this.setCdDriveContent(); + this.actualPlayTrack=loadedCD.getPlayList()[0]; + } + + private void setCdDriveContent() { + CdDriveContent = 1; + } + +} diff --git a/src/main/java/device/cdPlayer/exceptions/CdFlapIsOpenException.java b/src/main/java/device/cdPlayer/exceptions/CdFlapIsOpenException.java new file mode 100644 index 0000000..079e03d --- /dev/null +++ b/src/main/java/device/cdPlayer/exceptions/CdFlapIsOpenException.java @@ -0,0 +1,8 @@ +package device.cdPlayer.exceptions; + +public class CdFlapIsOpenException extends RuntimeException{ + //String message="Cd Flap must be closed."; + public CdFlapIsOpenException() { + super("Cd Flap must be closed."); + } +} diff --git a/src/main/java/device/cdPlayer/exceptions/FormatNotSupportedException.java b/src/main/java/device/cdPlayer/exceptions/FormatNotSupportedException.java new file mode 100644 index 0000000..2b398d2 --- /dev/null +++ b/src/main/java/device/cdPlayer/exceptions/FormatNotSupportedException.java @@ -0,0 +1,8 @@ +package device.cdPlayer.exceptions; + +public class FormatNotSupportedException extends RuntimeException{ + //String message="Cd-Format not supported."; + public FormatNotSupportedException() { + super("Cd-Format not supported."); + } +} diff --git a/src/main/java/device/cdPlayer/exceptions/NoCDException.java b/src/main/java/device/cdPlayer/exceptions/NoCDException.java new file mode 100644 index 0000000..be85d53 --- /dev/null +++ b/src/main/java/device/cdPlayer/exceptions/NoCDException.java @@ -0,0 +1,8 @@ +package device.cdPlayer.exceptions; + +public class NoCDException extends RuntimeException { + //String message="CD must be set."; + public NoCDException() { + super("CD must be set."); + } +} diff --git a/src/main/java/device/RadioPlayer.java b/src/main/java/device/radioPlayer/RadioPlayer.java similarity index 97% rename from src/main/java/device/RadioPlayer.java rename to src/main/java/device/radioPlayer/RadioPlayer.java index ac4fd34..e2cc7d1 100644 --- a/src/main/java/device/RadioPlayer.java +++ b/src/main/java/device/radioPlayer/RadioPlayer.java @@ -1,4 +1,6 @@ -package device; +package device.radioPlayer; + +import device.Device; import java.util.ArrayList; diff --git a/src/main/java/device/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java similarity index 95% rename from src/main/java/device/UsbPlayer.java rename to src/main/java/device/usbPlayer/UsbPlayer.java index a9a6509..87b63ab 100644 --- a/src/main/java/device/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -1,4 +1,6 @@ -package device; +package device.usbPlayer; + +import device.Device; public class UsbPlayer implements Device { diff --git a/src/test/java/device/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java similarity index 94% rename from src/test/java/device/CDPlayerTest.java rename to src/test/java/device/cdPlayer/CDPlayerTest.java index 7658a13..eb63e35 100644 --- a/src/test/java/device/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -1,4 +1,4 @@ -package device; +package device.cdPlayer; import org.junit.jupiter.api.Test; @@ -43,4 +43,5 @@ class CDPlayerTest { } */ + } \ No newline at end of file diff --git a/src/test/java/device/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java similarity index 95% rename from src/test/java/device/RadioPlayerTest.java rename to src/test/java/device/radioPlayer/RadioPlayerTest.java index edb8bd3..1d0549f 100644 --- a/src/test/java/device/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -1,5 +1,7 @@ -package device; +package device.radioPlayer; + +import device.radioPlayer.RadioPlayer; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/device/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java similarity index 96% rename from src/test/java/device/UsbPlayerTest.java rename to src/test/java/device/usbPlayer/UsbPlayerTest.java index c9901a1..bf170fe 100644 --- a/src/test/java/device/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -1,4 +1,4 @@ -package device; +package device.usbPlayer; import org.junit.jupiter.api.Test; From 1649116dd08d5ccb2eebab1473a5438fa06b74bd Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 21:39:50 +0100 Subject: [PATCH 2/3] 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 From 4440235c0c68437cbda4a62a5d68c18400992aff Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 21:54:28 +0100 Subject: [PATCH 3/3] Production-Code for CDPlayer-Method [Quieter] produced. --- src/main/java/device/cdPlayer/CDPlayer.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 1f5ea0e..f0b82a6 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -21,12 +21,20 @@ public class CDPlayer implements Device { @Override public void louder() { - + if(volume < 100) { + volume += 1; + } else { + volume = 100; + } } @Override public void quieter() { - + if(volume > 0) { + volume -= 1; + } else { + volume = 0; + } } @Override