From 1fb89934b18e65d097cfcecc3c86516826b8dd32 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 03:25:32 +0100 Subject: [PATCH] Method chooseItem of CDPlayer tested on invalidInput->negativeNumber. --- src/main/java/device/cdPlayer/CDPlayer.java | 4 ++++ .../device/cdPlayer/exceptions/NegativeInputException.java | 7 +++++++ src/test/java/device/cdPlayer/CDPlayerTest.java | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/main/java/device/cdPlayer/exceptions/NegativeInputException.java 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(),"") ); }