From ce4ab1fbd47755d378f5e318eeb29db6f69d81af Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 17:25:00 +0100 Subject: [PATCH] Tests for CDPlayer-Method [Play] created. --- src/main/java/device/cdPlayer/CDPlayer.java | 6 +- .../java/device/cdPlayer/CDPlayerTest.java | 110 +++++++++++++----- 2 files changed, 87 insertions(+), 29 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 6cc7b77..ace5b17 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -65,7 +65,7 @@ public class CDPlayer implements Device { return null; } - //Getters und Setters + //Getters, Setters und SupportMethods public void setCD(CD _loadedCD) { loadedCD=_loadedCD; this.setCdDriveContent(); @@ -76,4 +76,8 @@ public class CDPlayer implements Device { CdDriveContent = 1; } + public void tapOnCdFlap(){ + this.CdFlap+=1; + } + } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index eb63e35..3d651ac 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -1,47 +1,101 @@ package device.cdPlayer; +import device.cdPlayer.exceptions.*; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.junit.jupiter.MockitoExtension; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; +@ExtendWith(MockitoExtension.class) class CDPlayerTest { -/* - @Test - void louder() { - } - @Test - void quieter() { + @ParameterizedTest + @MethodSource("playTestData") + void play(String testName, CDPlayer _cdPlayer,Exception exception , String expectedResult) { + if(exception!=null){ + Exception newException=assertThrows(exception.getClass(),()->_cdPlayer.play()); + assertEquals(expectedResult, newException.getMessage()); + }else{ + assertThat(_cdPlayer.play()).describedAs(testName).isEqualTo(expectedResult); + } } + static Stream playTestData () { + //some PlayLists + 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"}; + //some CDs + CD videoCD1=new CD("DVD",videoPlayList); + CD videoCD2=new CD("Blue-ray",videoPlayList); + CD audioCD1=new CD("Audio",audioPlayList); + CD audioCD2=new CD("MP3",audioPlayList); + CD audioCD3=new CD("WMA",audioPlayList); + CD audioCD4=new CD("AAC",audioPlayList); - @Test - void getVolume() { - } + //some CDPlayers + CDPlayer cdPlayer1=new CDPlayer(); - @Test - void next() { - } + CDPlayer cdPlayer2=new CDPlayer(); + cdPlayer2.tapOnCdFlap(); + cdPlayer2.tapOnCdFlap(); - @Test - void prev() { - } + CDPlayer cdPlayer3=new CDPlayer(); + cdPlayer3.tapOnCdFlap(); - @Test - void getInfoText() { - } + CDPlayer cdPlayer4=new CDPlayer(); + cdPlayer4.tapOnCdFlap(); + cdPlayer4.setCD(videoCD1); - @Test - void getOptions() { - } + //=================================== + CDPlayer cdPlayer5=new CDPlayer(); + cdPlayer5.tapOnCdFlap(); + cdPlayer5.setCD(videoCD1); + cdPlayer5.tapOnCdFlap(); - @Test - void chooseOption() { - } + CDPlayer cdPlayer6=new CDPlayer(); + cdPlayer6.tapOnCdFlap(); + cdPlayer6.setCD(videoCD2); + cdPlayer6.tapOnCdFlap(); + //=================================== - @Test - void play() { - } + CDPlayer cdPlayer7=new CDPlayer(); + cdPlayer7.tapOnCdFlap(); + cdPlayer7.setCD(audioCD1); + cdPlayer7.tapOnCdFlap(); + + CDPlayer cdPlayer8=new CDPlayer(); + cdPlayer8.tapOnCdFlap(); + cdPlayer8.setCD(audioCD2); + cdPlayer8.tapOnCdFlap(); - */ + CDPlayer cdPlayer9=new CDPlayer(); + cdPlayer9.tapOnCdFlap(); + cdPlayer9.setCD(audioCD3); + cdPlayer9.tapOnCdFlap(); + + CDPlayer cdPlayer10=new CDPlayer(); + cdPlayer10.tapOnCdFlap(); + cdPlayer10.setCD(audioCD4); + cdPlayer10.tapOnCdFlap(); + + return Stream.of( + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isEmpty] => NoCD", cdPlayer1, new NoCDException(), "CD must be set."), + Arguments.of("[CdFlap has been Opened and Closed, CdDriveContent=>isEmpty] => NoCD", cdPlayer2,new NoCDException(),"CD must be set."), + Arguments.of("[CdFlap=isOpen , CdDriveContent=>isEmpty] => CdFlapIsOpen", cdPlayer3,new CdFlapIsOpenException(),"Cd Flap must be closed."), + Arguments.of("[CdFlap=isOpen , CdDriveContent=>isSet] => CdFlapIsOpen", cdPlayer4,new CdFlapIsOpenException(),"Cd Flap must be closed."), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>DVD] => FormatNotSupported",cdPlayer5,new FormatNotSupportedException(),"Cd-Format not supported."), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>Blue-ray] => FormatNotSupported",cdPlayer6, new FormatNotSupportedException(),"Cd-Format not supported."), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>Audio] => AllConditionsForPlayMet", cdPlayer7,null,"AllConditionsForPlayMet"), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>MP3] => AllConditionsForPlayMet", cdPlayer8,null,"AllConditionsForPlayMet"), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>WMA] => AllConditionsForPlayMet", cdPlayer9,null,"AllConditionsForPlayMet"), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>AAC] => AllConditionsForPlayMet", cdPlayer10,null,"AllConditionsForPlayMet") + ); + } } \ No newline at end of file