|
|
@ -327,4 +327,106 @@ class CDPlayerTest { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@ParameterizedTest |
|
|
|
@MethodSource("chooseItemTestData") |
|
|
|
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()); |
|
|
|
} |
|
|
|
if(cases.equals("Case2")) { |
|
|
|
Exception newException = assertThrows(exception.getClass(), () -> _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()); |
|
|
|
} |
|
|
|
if(cases.equals("Case4")) { |
|
|
|
assertThat(_cdPlayer.chooseItem(1).contains("2")).describedAs(testName).isEqualTo(true); |
|
|
|
} |
|
|
|
} |
|
|
|
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 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) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
|
@MethodSource("changePlaySourceData") |
|
|
|
void changePlaySourceTest(String testName,String cases, CDPlayer _cdPlayer) { |
|
|
|
|
|
|
|
if(cases.equals("Case1")) { |
|
|
|
String returnVal = _cdPlayer.changePlaySource(); |
|
|
|
assertThat(returnVal).describedAs(testName).isEqualTo("CDWechseler"); |
|
|
|
} |
|
|
|
if(cases.equals("Case2")) { |
|
|
|
String returnVal = _cdPlayer.changePlaySource(); |
|
|
|
assertThat(returnVal).describedAs(testName).isEqualTo("CDDrive"); |
|
|
|
} |
|
|
|
} |
|
|
|
static Stream<Arguments> changePlaySourceData () { |
|
|
|
CDPlayer cdPlayer1 = new CDPlayer(); |
|
|
|
|
|
|
|
CDPlayer cdPlayer2 = new CDPlayer(); |
|
|
|
cdPlayer2.changePlaySource(); |
|
|
|
|
|
|
|
return Stream.of( |
|
|
|
Arguments.of("[changePlaySource() by activeSource=CDDrive ] => shouldReturnCDWechseler","Case1", cdPlayer1), |
|
|
|
Arguments.of("[changePlaySource() by activeSource=CDWechseler ] => shouldReturnCDDrive","Case2", cdPlayer2) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
|
@MethodSource("loadCDWechselerData") |
|
|
|
void loadCDWechselerTest(String testName,String cases, CDPlayer _cdPlayer,CD cd,Exception exception) { |
|
|
|
if(cases.equals("Case1")) { |
|
|
|
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd,0)); |
|
|
|
assertEquals(CDWechselerNotRunningException.class, newException.getClass()); |
|
|
|
} |
|
|
|
if(cases.equals("Case2")) { |
|
|
|
_cdPlayer.changePlaySource(); |
|
|
|
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd,0)); |
|
|
|
assertEquals(FormatNotSupportedException.class, newException.getClass()); |
|
|
|
} |
|
|
|
if(cases.equals("Case3")) { |
|
|
|
_cdPlayer.changePlaySource(); |
|
|
|
_cdPlayer.loadCDWechseler(cd,0); |
|
|
|
CD firstCD=_cdPlayer.getCdWechseler().getCDList()[0]; |
|
|
|
assertThat(firstCD).describedAs(testName).isNotEqualTo(null); |
|
|
|
} |
|
|
|
if(cases.equals("Case4")) { |
|
|
|
_cdPlayer.changePlaySource(); |
|
|
|
Exception newException=assertThrows(exception.getClass(), () -> _cdPlayer.loadCDWechseler(cd, 12)); |
|
|
|
assertEquals(MaxCapacityExceededException.class, newException.getClass()); |
|
|
|
} |
|
|
|
} |
|
|
|
static Stream<Arguments> loadCDWechselerData () { |
|
|
|
CDPlayer cdPlayer1 = new CDPlayer(); |
|
|
|
String[] videoPlayList=new String[]{"Video 01","Video 02","Video 03","Video 04","Video 05"}; |
|
|
|
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; |
|
|
|
|
|
|
|
CD audioCD1=new CD("Audio",audioPlayList); |
|
|
|
CD DVD=new CD("DVD",videoPlayList); |
|
|
|
return Stream.of( |
|
|
|
Arguments.of("[loadCDWechseler() by notRunning=CDWechseler ] => shouldThrowAnException", "Case1", cdPlayer1,audioCD1,new CDWechselerNotRunningException()), |
|
|
|
Arguments.of("[loadCDWechseler() by WrongCDFormat ] => shouldThrowAnException", "Case2", cdPlayer1,DVD,new FormatNotSupportedException()), |
|
|
|
Arguments.of("[loadCDWechseler() by leadingFirstCD ] => CDListOfCDWechselerShouldHaveLength1", "Case3", cdPlayer1,audioCD1,null), |
|
|
|
Arguments.of("[loadCDWechseler() by MaxCapacityExceeded:Max=10 ] => shouldThrowAnException", "Case4", cdPlayer1,audioCD1,new MaxCapacityExceededException()) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |