Browse Source

Method chooseItem of CDPlayer tested on invalidInput->greater than PlayListSize.

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

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

@ -89,6 +89,9 @@ public class CDPlayer implements Device {
if(this.loadedCD==null){
throw new ReturnValueNullException();
}
if(!(itemNr>=0 && itemNr<loadedCD.getPlayList().length)){
throw new ItemNumberNotFoundException();
}
return null;
}

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

@ -0,0 +1,7 @@
package device.cdPlayer.exceptions;
public class ItemNumberNotFoundException extends RuntimeException {
public ItemNumberNotFoundException() {
super("Given ItemNumber ist not in the Album.");
}
}

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

@ -330,13 +330,28 @@ class CDPlayerTest {
@ParameterizedTest
@MethodSource("chooseItemTestData")
void chooseItemTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception , String expectedResult) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(1));
assertEquals(ReturnValueNullException.class, newException.getClass());
if(cases.equals("Case1")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(1));
assertEquals(ReturnValueNullException.class, newException.getClass());
}
if(cases.equals("Case2")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(200));
assertEquals(ItemNumberNotFoundException.class, newException.getClass());
}
}
static Stream<Arguments> chooseItemTestData () {
CDPlayer cdPlayer1 = new CDPlayer();
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"};
CD audioCD1=new CD("Audio",audioPlayList);
CDPlayer cdPlayer2 = new CDPlayer();
cdPlayer2.tapOnCdFlap();
cdPlayer2.setCD(audioCD1);
cdPlayer2.tapOnCdFlap();
return Stream.of(
Arguments.of("[chooseItem() by notSetCD ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),"")
Arguments.of("[chooseItem() by notSetCD ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),""),
Arguments.of("[chooseItem() by invalidInput ] => shouldThrowItemNumberNotFoundException","Case2", cdPlayer2,new ItemNumberNotFoundException(),"")
);
}
Loading…
Cancel
Save