From 3d0f3997f212333fc70adf6c30f83fbb4abd05d8 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 17:11:12 +0100 Subject: [PATCH] Method changeToNextCD of CDPlayer tested on CDWechselerNotSelected -> shouldThrowAnException. --- src/main/java/device/cdPlayer/CDPlayer.java | 6 ++++++ .../ChangeCDOnlyOnCDWechselerException.java | 7 +++++++ src/test/java/device/cdPlayer/CDPlayerTest.java | 15 +++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index a60009a..90a1f92 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -154,6 +154,12 @@ public class CDPlayer implements Device { cdWechseler.loadOneCD(cd,index); System.out.println(index); } + public void changeToNextCD(){ + if(activeSource.equals("CDDrive")){ + throw new ChangeCDOnlyOnCDWechselerException(); + } + + } //Getters, Setters und SupportMethods public void setCD(CD _loadedCD) { diff --git a/src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java b/src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java new file mode 100644 index 0000000..ab81555 --- /dev/null +++ b/src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java @@ -0,0 +1,7 @@ +package device.cdPlayer.exceptions; + +public class ChangeCDOnlyOnCDWechselerException extends RuntimeException{ + public ChangeCDOnlyOnCDWechselerException(){ + super("Change to next CD olny when CDWechseler is selected"); + } +} diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 1eb3043..add6d31 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -428,5 +428,20 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("changeToNextCDData") + void changeToNextCDTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.changeToNextCD()); + assertEquals(ChangeCDOnlyOnCDWechselerException.class, newException.getClass()); + } + static Stream changeToNextCDData () { + CDPlayer cdPlayer1 = new CDPlayer(); + + return Stream.of( + Arguments.of("[changeToNextCD() by CDWechselerNotSelected ] => shouldThrowAnException", "Case1", cdPlayer1,new ChangeCDOnlyOnCDWechselerException()) + ); + } + + } \ No newline at end of file