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