|
|
@ -1,5 +1,6 @@ |
|
|
|
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; |
|
|
@ -16,37 +17,85 @@ import static org.junit.jupiter.api.Assertions.*; |
|
|
|
class CDPlayerTest { |
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
|
@MethodSource("quieterTestData") |
|
|
|
void quieterTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, int expectedResult) { |
|
|
|
for (int i = 0; i < anzClicks; i++) { |
|
|
|
_cdPlayer.quieter(); |
|
|
|
@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); |
|
|
|
} |
|
|
|
|
|
|
|
if(testDirection.equals("VolumeDecreased")){ |
|
|
|
for (int i = 0; i < 20; i++) { |
|
|
|
_cdPlayer.louder(); |
|
|
|
} |
|
|
|
for (int i = 0; i < anzClicks; i++) { |
|
|
|
_cdPlayer.quieter(); |
|
|
|
} |
|
|
|
assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(expectedResult); |
|
|
|
} |
|
|
|
if(testDirection.equals("VolumeHasNotChanged")){ |
|
|
|
assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(expectedResult); |
|
|
|
}if(testDirection.equals("VolumeNotIncreased")){ |
|
|
|
static Stream<Arguments> 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); |
|
|
|
|
|
|
|
assertThat(_cdPlayer.getVolume()).describedAs(testName).isNotEqualTo(expectedResult); |
|
|
|
} |
|
|
|
} |
|
|
|
//some CDPlayers |
|
|
|
CDPlayer cdPlayer1=new CDPlayer(); |
|
|
|
|
|
|
|
CDPlayer cdPlayer2=new CDPlayer(); |
|
|
|
cdPlayer2.tapOnCdFlap(); |
|
|
|
cdPlayer2.tapOnCdFlap(); |
|
|
|
|
|
|
|
CDPlayer cdPlayer3=new CDPlayer(); |
|
|
|
cdPlayer3.tapOnCdFlap(); |
|
|
|
|
|
|
|
CDPlayer cdPlayer4=new CDPlayer(); |
|
|
|
cdPlayer4.tapOnCdFlap(); |
|
|
|
cdPlayer4.setCD(videoCD1); |
|
|
|
|
|
|
|
//=================================== |
|
|
|
CDPlayer cdPlayer5=new CDPlayer(); |
|
|
|
cdPlayer5.tapOnCdFlap(); |
|
|
|
cdPlayer5.setCD(videoCD1); |
|
|
|
cdPlayer5.tapOnCdFlap(); |
|
|
|
|
|
|
|
CDPlayer cdPlayer6=new CDPlayer(); |
|
|
|
cdPlayer6.tapOnCdFlap(); |
|
|
|
cdPlayer6.setCD(videoCD2); |
|
|
|
cdPlayer6.tapOnCdFlap(); |
|
|
|
//=================================== |
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
static Stream<Arguments> quieterTestData () { |
|
|
|
CDPlayer cdPlayer=new CDPlayer(); |
|
|
|
return Stream.of( |
|
|
|
Arguments.of("[getVolume() after 20x quieter() starting by 20] => VolumeHasDecreased","VolumeDecreased", cdPlayer, 19, 1), |
|
|
|
Arguments.of("[getVolume() after 20x quieter() starting by 0] => VolumeHasNotChanged","VolumeHasNotChanged" ,cdPlayer,20,0), |
|
|
|
Arguments.of("[getVolume() after 5x quieter() starting by 0] => VolumeNotIncreased","VolumeNotIncreased", cdPlayer,5,5) |
|
|
|
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") |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |