Browse Source

Method changeToNextCD of CDPlayer tested on CDWechselerNotSelected -> shouldThrowAnException.

feature-pr-jacksonsNewFeature
JPANZO 3 years ago
parent
commit
3d0f3997f2
  1. 6
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 7
      src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java
  3. 15
      src/test/java/device/cdPlayer/CDPlayerTest.java

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

@ -154,6 +154,12 @@ public class CDPlayer implements Device {
cdWechseler.loadOneCD(cd,index); cdWechseler.loadOneCD(cd,index);
System.out.println(index); System.out.println(index);
} }
public void changeToNextCD(){
if(activeSource.equals("CDDrive")){
throw new ChangeCDOnlyOnCDWechselerException();
}
}
//Getters, Setters und SupportMethods //Getters, Setters und SupportMethods
public void setCD(CD _loadedCD) { public void setCD(CD _loadedCD) {

7
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");
}
}

15
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<Arguments> changeToNextCDData () {
CDPlayer cdPlayer1 = new CDPlayer();
return Stream.of(
Arguments.of("[changeToNextCD() by CDWechselerNotSelected ] => shouldThrowAnException", "Case1", cdPlayer1,new ChangeCDOnlyOnCDWechselerException())
);
}
} }
Loading…
Cancel
Save