Browse Source

Method getInfoText of CDPlayer tested on MessageShouldContainInfoOfActualPlayTrack.

feature-pr-RadioPlayer-getOptions
JPANZO 3 years ago
parent
commit
1f11a8366c
  1. 6
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 26
      src/test/java/device/cdPlayer/CDPlayerTest.java

6
src/main/java/device/cdPlayer/CDPlayer.java

@ -161,7 +161,9 @@ public class CDPlayer implements Device {
return actualPlayTrack; return actualPlayTrack;
} }
public void setInfoText(String intoText) {
this.infoText=intoText;
public void setInfoText(String infoText) {
this.infoText=infoText;
} }
} }

26
src/test/java/device/cdPlayer/CDPlayerTest.java

@ -278,21 +278,41 @@ class CDPlayerTest {
@ParameterizedTest @ParameterizedTest
@MethodSource("getInfoTestData") @MethodSource("getInfoTestData")
void getInfoTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception , String expectedResult){ void getInfoTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception , String expectedResult){
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.getInfoText());
if(cases.equals("Case1")) { if(cases.equals("Case1")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.getInfoText());
assertEquals(ReturnValueNullException.class, newException.getClass()); assertEquals(ReturnValueNullException.class, newException.getClass());
} }
if(cases.equals("Case2")) { if(cases.equals("Case2")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.getInfoText());
assertThat(newException.getMessage()).describedAs(testName).isEqualTo(expectedResult); assertThat(newException.getMessage()).describedAs(testName).isEqualTo(expectedResult);
} }
if(cases.equals("Case3")) {
String[] album= _cdPlayer.getItemList();
boolean containsInfoOfActualPlayTrack=false;
for (int i = 0; i < album.length; i++) {
if(_cdPlayer.getInfoText().contains(expectedResult))
containsInfoOfActualPlayTrack=true;
}
assertThat(containsInfoOfActualPlayTrack).describedAs(testName).isEqualTo(true);
}
} }
static Stream<Arguments> getInfoTestData () { static Stream<Arguments> getInfoTestData () {
CDPlayer cdPlayer1 = new CDPlayer(); CDPlayer cdPlayer1 = new CDPlayer();
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"};
//some CDs
CD audioCD1=new CD("Audio",audioPlayList);
CDPlayer cdPlayer2 = new CDPlayer();
cdPlayer2.tapOnCdFlap();
cdPlayer2.setCD(audioCD1);
cdPlayer2.tapOnCdFlap();
cdPlayer2.setInfoText("CDPlayer: Item->"+cdPlayer2.getActualPlayTrack()+" from Album->"+"AlbumName"+" running.");
return Stream.of( return Stream.of(
Arguments.of("[getInfoText() by infoText=null ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),""), Arguments.of("[getInfoText() by infoText=null ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),""),
Arguments.of("[getInfoText() by infoText=null ] => ExceptionShouldReturnAMessage","Case2",cdPlayer1,new ReturnValueNullException(),"Method should not return a Null-Value.")
Arguments.of("[getInfoText() by infoText=null ] => ExceptionShouldReturnAMessage","Case2",cdPlayer1,new ReturnValueNullException(),"Method should not return a Null-Value."),
Arguments.of("[getInfoText() by infoText=Message ] => MessageShouldContainInfoOfActualPlayTrack","Case3",cdPlayer2,null,"")
); );
} }
Loading…
Cancel
Save