Browse Source

Method chooseItem of CDPlayer tested on invalidInput->negativeNumber.

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

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

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

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

@ -0,0 +1,7 @@
package device.cdPlayer.exceptions;
public class NegativeInputException extends RuntimeException{
public NegativeInputException() {
super("InputNumber must be positive.");
}
}

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

@ -338,6 +338,10 @@ class CDPlayerTest {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(200)); Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(200));
assertEquals(ItemNumberNotFoundException.class, newException.getClass()); assertEquals(ItemNumberNotFoundException.class, newException.getClass());
} }
if(cases.equals("Case3")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(-1));
assertEquals(NegativeInputException.class, newException.getClass());
}
} }
static Stream<Arguments> chooseItemTestData () { static Stream<Arguments> chooseItemTestData () {
CDPlayer cdPlayer1 = new CDPlayer(); CDPlayer cdPlayer1 = new CDPlayer();
@ -351,7 +355,8 @@ class CDPlayerTest {
return Stream.of( 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(),"")
Arguments.of("[chooseItem() by invalidInput ] => shouldThrowItemNumberNotFoundException","Case2", cdPlayer2,new ItemNumberNotFoundException(),""),
Arguments.of("[chooseItem() by invalidInput:negativeNumber] => shouldThrowItemNumberNotFoundException","Case3", cdPlayer2,new NegativeInputException(),"")
); );
} }
Loading…
Cancel
Save