From 29aa121c19fe04d6bf3716be1168a4042243769d Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 14:41:34 +0100 Subject: [PATCH] Method loadCDWechseler of CDPlayer tested on notRunning=CDWechseler -> shouldThrowAnException. --- src/main/java/device/cdPlayer/CDPlayer.java | 7 ++++++- .../CDWechselerNotRunningException.java | 8 ++++++++ src/test/java/device/cdPlayer/CDPlayerTest.java | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/main/java/device/cdPlayer/exceptions/CDWechselerNotRunningException.java diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 89f6ad9..16f9d66 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -20,7 +20,7 @@ public class CDPlayer implements Device { private String actualPlayTrack=""; private CD loadedCD=null; - private CDWechseler cdWechseler; + private CDWechseler cdWechseler=null; private String activeSource="CDDrive";//or CDWechseler @Override @@ -139,6 +139,11 @@ public class CDPlayer implements Device { return activeSource; } + public void loadCDWechseler(ListcdList){ + if(cdWechseler==null||!cdWechseler.isRunning()){ + throw new CDWechselerNotRunningException(); + } + } //Getters, Setters und SupportMethods public void setCD(CD _loadedCD) { diff --git a/src/main/java/device/cdPlayer/exceptions/CDWechselerNotRunningException.java b/src/main/java/device/cdPlayer/exceptions/CDWechselerNotRunningException.java new file mode 100644 index 0000000..a2bb44d --- /dev/null +++ b/src/main/java/device/cdPlayer/exceptions/CDWechselerNotRunningException.java @@ -0,0 +1,8 @@ +package device.cdPlayer.exceptions; + +public class CDWechselerNotRunningException extends RuntimeException { + + public CDWechselerNotRunningException() { + super("CDWechseler must be active for using."); + } +} diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index f0ef16a..d159604 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -389,6 +389,22 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("loadCDWechselerData") + void loadCDWechselerTest(String testName,String cases, CDPlayer _cdPlayer,ListcdList,Exception exception) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cdList)); + assertEquals(CDWechselerNotRunningException.class, newException.getClass()); + } + static Stream loadCDWechselerData () { + CDPlayer cdPlayer1 = new CDPlayer(); + String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; + CD audioCD1=new CD("Audio",audioPlayList); + ListCdList1=Arrays.asList(audioCD1); + + return Stream.of( + Arguments.of("[loadCDWechseler() by notRunning=CDWechseler ] => shouldThrowAnException", "Case1", cdPlayer1,CdList1,new CDWechselerNotRunningException()) + ); + } } \ No newline at end of file