diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 561e456..755566d 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -89,9 +89,13 @@ public class CDPlayer implements Device { if(this.loadedCD==null){ throw new ReturnValueNullException(); } + if(itemNr<0){ + throw new NegativeInputException(); + } if(!(itemNr>=0 && itemNr _cdPlayer.chooseItem(200)); assertEquals(ItemNumberNotFoundException.class, newException.getClass()); } + if(cases.equals("Case3")) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(-1)); + assertEquals(NegativeInputException.class, newException.getClass()); + } } static Stream chooseItemTestData () { CDPlayer cdPlayer1 = new CDPlayer(); @@ -351,7 +355,8 @@ class CDPlayerTest { return Stream.of( 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(),"") ); }