From aac81d6b2272f4a06cd72f444fd13eee407a2d7a Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 03:13:09 +0100 Subject: [PATCH] Method chooseItem of CDPlayer tested on invalidInput->greater than PlayListSize. --- src/main/java/device/cdPlayer/CDPlayer.java | 3 +++ .../ItemNumberNotFoundException.java | 7 +++++++ .../java/device/cdPlayer/CDPlayerTest.java | 21 ++++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/main/java/device/cdPlayer/exceptions/ItemNumberNotFoundException.java diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index d70ffca..561e456 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/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 _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 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(),"") ); }