Browse Source

Method loadCDWechseler of CDPlayer tested on WrongCDFormat -> shouldThrowAnException.

feature-pr-BordComputer-setDevices
JPANZO 2 years ago
parent
commit
77ce33d615
  1. 7
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 21
      src/test/java/device/cdPlayer/CDPlayerTest.java

7
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(List<CD>cdList){
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

21
src/test/java/device/cdPlayer/CDPlayerTest.java

@ -391,18 +391,27 @@ class CDPlayerTest {
@ParameterizedTest
@MethodSource("loadCDWechselerData")
void loadCDWechselerTest(String testName,String cases, CDPlayer _cdPlayer,List<CD>cdList,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<Arguments> 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);
List<CD>CdList1=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())
);
}

Loading…
Cancel
Save