|
|
@ -330,13 +330,28 @@ class CDPlayerTest { |
|
|
|
@ParameterizedTest |
|
|
|
@MethodSource("chooseItemTestData") |
|
|
|
void chooseItemTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception , String expectedResult) { |
|
|
|
Exception newException = assertThrows(exception.getClass(), () -> _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<Arguments> 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(),"") |
|
|
|
); |
|
|
|
} |
|
|
|
|