From 34b14f3e87bd16d5cf39b293969c10615dcdc3b5 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 03:46:21 +0100 Subject: [PATCH] Method chooseItem of CDPlayer tested on validInput->shouldReturnMsgWithinTheItemNr. --- src/main/java/device/cdPlayer/CDPlayer.java | 2 +- src/test/java/device/cdPlayer/CDPlayerTest.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 755566d..99b3b81 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -96,7 +96,7 @@ public class CDPlayer implements Device { throw new ItemNumberNotFoundException(); } - return null; + return loadedCD.getPlayList()[itemNr]; } @Override diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 98c8920..3e68055 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -329,7 +329,7 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("chooseItemTestData") - void chooseItemTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception , String expectedResult) { + void chooseItemTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception ) { if(cases.equals("Case1")) { Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(1)); assertEquals(ReturnValueNullException.class, newException.getClass()); @@ -342,6 +342,9 @@ class CDPlayerTest { Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(-1)); assertEquals(NegativeInputException.class, newException.getClass()); } + if(cases.equals("Case4")) { + assertThat(_cdPlayer.chooseItem(1).contains("2")).describedAs(testName).isEqualTo(true); + } } static Stream chooseItemTestData () { CDPlayer cdPlayer1 = new CDPlayer(); @@ -354,9 +357,10 @@ class CDPlayerTest { cdPlayer2.tapOnCdFlap(); 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:negativeNumber] => shouldThrowItemNumberNotFoundException","Case3", cdPlayer2,new NegativeInputException(),"") + 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:negativeNumber] => shouldThrowItemNumberNotFoundException","Case3", cdPlayer2,new NegativeInputException()), + Arguments.of("[chooseItem() by validInput] => shouldReturnMsgWithinTheItemNr","Case4", cdPlayer2,null) ); }