Browse Source

Method chooseItem of CDPlayer tested on validInput->shouldReturnMsgWithinTheItemNr.

feature-pr-BordComputer-setDevices
JPANZO 3 years ago
parent
commit
34b14f3e87
  1. 2
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 12
      src/test/java/device/cdPlayer/CDPlayerTest.java

2
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

12
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<Arguments> 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)
);
}
Loading…
Cancel
Save