From 77ce33d615fbc124bb040a12b6997fbb6a57cfe9 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 15:00:52 +0100 Subject: [PATCH] Method loadCDWechseler of CDPlayer tested on WrongCDFormat -> shouldThrowAnException. --- src/main/java/device/cdPlayer/CDPlayer.java | 7 ++++++- .../java/device/cdPlayer/CDPlayerTest.java | 21 +++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 16f9d66..da243d6 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -135,14 +135,19 @@ public class CDPlayer implements Device { public String changePlaySource(){ if(activeSource.equals("CDDrive")) { this.activeSource = "CDWechseler"; + this.cdWechseler=new CDWechseler(); + this.cdWechseler.activate(); }else this.activeSource="CDDrive"; return activeSource; } - public void loadCDWechseler(ListcdList){ + public void loadCDWechseler(CD cd){ if(cdWechseler==null||!cdWechseler.isRunning()){ throw new CDWechselerNotRunningException(); } + if(!(this.supportedFormats.contains(cd.getFormat()))){ + throw new FormatNotSupportedException(); + } } //Getters, Setters und SupportMethods diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index d159604..d093081 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -391,18 +391,27 @@ 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()); + void loadCDWechselerTest(String testName,String cases, CDPlayer _cdPlayer,CD cd,Exception exception) { + if(cases.equals("Case1")) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd)); + assertEquals(CDWechselerNotRunningException.class, newException.getClass()); + } + if(cases.equals("Case2")) { + _cdPlayer.changePlaySource(); + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd)); + assertEquals(FormatNotSupportedException.class, newException.getClass()); + } } static Stream loadCDWechselerData () { CDPlayer cdPlayer1 = new CDPlayer(); + String[] videoPlayList=new String[]{"Video 01","Video 02","Video 03","Video 04","Video 05"}; String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; - CD audioCD1=new CD("Audio",audioPlayList); - ListCdList1=Arrays.asList(audioCD1); + CD audioCD1=new CD("Audio",audioPlayList); + CD DVD=new CD("DVD",videoPlayList); return Stream.of( - Arguments.of("[loadCDWechseler() by notRunning=CDWechseler ] => shouldThrowAnException", "Case1", cdPlayer1,CdList1,new CDWechselerNotRunningException()) + Arguments.of("[loadCDWechseler() by notRunning=CDWechseler ] => shouldThrowAnException", "Case1", cdPlayer1,audioCD1,new CDWechselerNotRunningException()), + Arguments.of("[loadCDWechseler() by WrongCDFormat ] => shouldThrowAnException", "Case2", cdPlayer1,DVD,new FormatNotSupportedException()) ); }