Browse Source

Method loadCDWechseler of CDPlayer tested on MaxCapacityExceeded:Max=10 -> shouldThrowAnException.

feature-pr-BordComputer-setDevices
JPANZO 3 years ago
parent
commit
7c7ae70a2b
  1. 8
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 8
      src/main/java/device/cdPlayer/CDWechseler.java
  3. 7
      src/main/java/device/cdPlayer/exceptions/MaxCapacityExceededException.java
  4. 18
      src/test/java/device/cdPlayer/CDPlayerTest.java

8
src/main/java/device/cdPlayer/CDPlayer.java

@ -141,14 +141,18 @@ public class CDPlayer implements Device {
return activeSource; return activeSource;
} }
public void loadCDWechseler(CD cd){
public void loadCDWechseler(CD cd,int index){
if(cdWechseler==null||!cdWechseler.isRunning()){ if(cdWechseler==null||!cdWechseler.isRunning()){
throw new CDWechselerNotRunningException(); throw new CDWechselerNotRunningException();
} }
if(!(this.supportedFormats.contains(cd.getFormat()))){ if(!(this.supportedFormats.contains(cd.getFormat()))){
throw new FormatNotSupportedException(); throw new FormatNotSupportedException();
} }
cdWechseler.loadOneCD(cd);
if(index>10){
throw new MaxCapacityExceededException();
}
cdWechseler.loadOneCD(cd,index);
System.out.println(index);
} }
//Getters, Setters und SupportMethods //Getters, Setters und SupportMethods

8
src/main/java/device/cdPlayer/CDWechseler.java

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CDWechseler { public class CDWechseler {
private List<CD>CDList=new ArrayList<>();
private CD[]CDList=new CD[10];
private boolean running=false; private boolean running=false;
@ -16,11 +16,11 @@ public class CDWechseler {
this.running = true; this.running = true;
} }
public List<CD> getCDList() {
public CD[] getCDList() {
return CDList; return CDList;
} }
public void loadOneCD(CD cd){
CDList.add(cd);
public void loadOneCD(CD cd,int index){
CDList[index]=cd;
} }
} }

7
src/main/java/device/cdPlayer/exceptions/MaxCapacityExceededException.java

@ -0,0 +1,7 @@
package device.cdPlayer.exceptions;
public class MaxCapacityExceededException extends RuntimeException{
public MaxCapacityExceededException(){
super("Max capacity of 10-CDs is already exceeded.");
}
}

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

@ -393,19 +393,24 @@ class CDPlayerTest {
@MethodSource("loadCDWechselerData") @MethodSource("loadCDWechselerData")
void loadCDWechselerTest(String testName,String cases, CDPlayer _cdPlayer,CD cd,Exception exception) { void loadCDWechselerTest(String testName,String cases, CDPlayer _cdPlayer,CD cd,Exception exception) {
if(cases.equals("Case1")) { if(cases.equals("Case1")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd));
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd,0));
assertEquals(CDWechselerNotRunningException.class, newException.getClass()); assertEquals(CDWechselerNotRunningException.class, newException.getClass());
} }
if(cases.equals("Case2")) { if(cases.equals("Case2")) {
_cdPlayer.changePlaySource(); _cdPlayer.changePlaySource();
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd));
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd,0));
assertEquals(FormatNotSupportedException.class, newException.getClass()); assertEquals(FormatNotSupportedException.class, newException.getClass());
} }
if(cases.equals("Case3")) { if(cases.equals("Case3")) {
_cdPlayer.changePlaySource(); _cdPlayer.changePlaySource();
_cdPlayer.loadCDWechseler(cd);
int length=_cdPlayer.getCdWechseler().getCDList().size();
assertThat(length).describedAs(testName).isEqualTo(1);
_cdPlayer.loadCDWechseler(cd,0);
CD firstCD=_cdPlayer.getCdWechseler().getCDList()[0];
assertThat(firstCD).describedAs(testName).isNotEqualTo(null);
}
if(cases.equals("Case4")) {
_cdPlayer.changePlaySource();
Exception newException=assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd, 12));
assertEquals(MaxCapacityExceededException.class, newException.getClass());
} }
} }
static Stream<Arguments> loadCDWechselerData () { static Stream<Arguments> loadCDWechselerData () {
@ -418,7 +423,8 @@ class CDPlayerTest {
return Stream.of( return Stream.of(
Arguments.of("[loadCDWechseler() by notRunning=CDWechseler ] => shouldThrowAnException", "Case1", cdPlayer1,audioCD1,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()), Arguments.of("[loadCDWechseler() by WrongCDFormat ] => shouldThrowAnException", "Case2", cdPlayer1,DVD,new FormatNotSupportedException()),
Arguments.of("[loadCDWechseler() by leadingFirstCD ] => CDListOfCDWechselerShouldHaveLength1", "Case3", cdPlayer1,audioCD1,null)
Arguments.of("[loadCDWechseler() by leadingFirstCD ] => CDListOfCDWechselerShouldHaveLength1", "Case3", cdPlayer1,audioCD1,null),
Arguments.of("[loadCDWechseler() by MaxCapacityExceeded:Max=10 ] => shouldThrowAnException", "Case4", cdPlayer1,audioCD1,new MaxCapacityExceededException())
); );
} }

Loading…
Cancel
Save