diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index c3d0ce1..14ace41 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -161,7 +161,9 @@ public class CDPlayer implements Device { return actualPlayTrack; } - public void setInfoText(String intoText) { - this.infoText=intoText; + public void setInfoText(String infoText) { + this.infoText=infoText; } + + } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 4e9e7c4..e6b26e9 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -278,21 +278,41 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("getInfoTestData") void getInfoTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception , String expectedResult){ - Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.getInfoText()); + if(cases.equals("Case1")) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.getInfoText()); assertEquals(ReturnValueNullException.class, newException.getClass()); } if(cases.equals("Case2")) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.getInfoText()); 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 getInfoTestData () { - 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( 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,"") ); }