Browse Source

Merge branch 'feature-pr-cdPlayerPlayTest' into feature-pr-organization

# Conflicts:
#	src/test/java/device/cdPlayer/CDPlayerTest.java
feature-pr-organization
JPANZO 3 years ago
parent
commit
69d8e5b2b7
  1. 38
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 99
      src/test/java/device/cdPlayer/CDPlayerTest.java

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

@ -1,7 +1,7 @@
package device.cdPlayer; package device.cdPlayer;
import device.Device; import device.Device;
import device.cdPlayer.exceptions.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -16,8 +16,6 @@ public class CDPlayer implements Device {
private String actualPlayTrack=""; private String actualPlayTrack="";
private CD loadedCD; private CD loadedCD;
private String[] cdAlbum=new String[]{};
@Override @Override
public void louder() { public void louder() {
@ -70,10 +68,23 @@ public class CDPlayer implements Device {
@Override @Override
public String play() { public String play() {
if(isCdFlapOpen()){
throw new CdFlapIsOpenException();
}
else if(!isCdFlapOpen()&&getCdDriveContent()==0){
throw new NoCDException();
}
else if(!isCdFlapOpen()&&getCdDriveContent()==1&&!checkFormat(loadedCD.getFormat())){
throw new FormatNotSupportedException();
}
else if(!isCdFlapOpen()&&getCdDriveContent()==1&&checkFormat(loadedCD.getFormat())){
System.out.println(loadedCD.getFormat()+" "+this.actualPlayTrack+" is playing.");
return "AllConditionsForPlayMet";
}
return null; return null;
} }
//Getters und Setters
//Getters, Setters und SupportMethods
public void setCD(CD _loadedCD) { public void setCD(CD _loadedCD) {
loadedCD=_loadedCD; loadedCD=_loadedCD;
this.setCdDriveContent(); this.setCdDriveContent();
@ -84,4 +95,23 @@ public class CDPlayer implements Device {
CdDriveContent = 1; CdDriveContent = 1;
} }
public void tapOnCdFlap(){
this.CdFlap+=1;
}
private boolean checkFormat(String format){
if(this.supportedFormats.contains(format))
return true;
else return false;
}
private int getCdDriveContent() {
return CdDriveContent;
}
private boolean isCdFlapOpen() {
if(CdFlap==1) {
return true;
}
else
return false;
}
} }

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

@ -1,5 +1,6 @@
package device.cdPlayer; package device.cdPlayer;
import device.cdPlayer.exceptions.*;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
@ -16,37 +17,85 @@ import static org.junit.jupiter.api.Assertions.*;
class CDPlayerTest { class CDPlayerTest {
@ParameterizedTest @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( 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")
); );
} }
} }
Loading…
Cancel
Save