Browse Source

BordComputer.play; instance of CDPlayer -> after all preconditions ShouldReturnAnItemToPlay.

feature-pr-lastUpdate
JPANZO 3 years ago
parent
commit
f526cacb40
  1. 43
      src/main/java/BordComputer.java
  2. 9
      src/main/java/device/cdPlayer/CDPlayer.java
  3. 17
      src/test/java/BordComputerTest.java
  4. 3
      src/test/java/device/cdPlayer/CDPlayerTest.java

43
src/main/java/BordComputer.java

@ -1,4 +1,8 @@
import device.Device;
import device.cdPlayer.CD;
import device.cdPlayer.CDPlayer;
import device.radioPlayer.RadioPlayer;
import device.usbPlayer.UsbPlayer;
import java.io.FileReader;
import java.lang.reflect.InvocationTargetException;
@ -35,4 +39,43 @@ public class BordComputer {
installedDevices[i] = (Device) c.getConstructor().newInstance();
}
}
public String play(){
String itemToPlay=activeDevice.play();
return itemToPlay;
}
//===== Hilf-Funktionen ======
public Object getInstanceByName(String deviceName){
for (int i = 0; i <installedDevices.length ; i++) {
if(installedDevices[i].getClass().getSimpleName().equals(deviceName)){
if(deviceName.equals("CDPlayer")){
return (CDPlayer)installedDevices[i];
}
if(deviceName.equals("RadioPlayer")){
return (RadioPlayer)installedDevices[i];
}
if(deviceName.equals("UsbPlayer")){
return (UsbPlayer)installedDevices[i];
}
}
}
return null;
}
public void meetAllPreconditionForPlay(){
String[] audioPlayList = new String[]{"Audio 01", "Audio 02", "Audio 03", "Audio 04", "Audio 05"};
CD audioCD1 = new CD("Audio", "PopMusic", audioPlayList, "XAc20044");
CD audioCD2=new CD("Audio","RockMusic",audioPlayList,"BLXPP78");
CDPlayer cdPlayer=(CDPlayer) activeDevice;
cdPlayer.changePlaySource();
cdPlayer.loadCDWechseler(audioCD1, 0);
cdPlayer.loadCDWechseler(audioCD2, 1);
cdPlayer.setCD(cdPlayer.getCdWechseler().getCDList().get(0));
activeDevice=cdPlayer;
}
}

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

@ -28,6 +28,8 @@ public class CDPlayer implements Device {
private boolean muted=false;
private int oldVolume=0;
private String status="";
@Override
public void louder() {
if(volume < 100) {
@ -138,8 +140,8 @@ public class CDPlayer implements Device {
throw new FormatNotSupportedException();
}
else if(!isCdFlapOpen()&&getCdDriveContent()==1&&checkFormat(loadedCD.getFormat())){
System.out.println(loadedCD.getFormat()+" "+this.actualPlayTrack+" is playing.");
return "AllConditionsForPlayMet";
status="AllConditionsForPlayMet";
return (loadedCD.getFormat()+":"+this.actualPlayTrack+" is playing.");
}
return null;
}
@ -247,4 +249,7 @@ public class CDPlayer implements Device {
return oldVolume;
}
public String getStatus() {
return status;
}
}

17
src/test/java/BordComputerTest.java

@ -81,4 +81,21 @@ class BordComputerTest {
}
return count;
}
@ParameterizedTest
@MethodSource("playDate")
void playTest(String testName, String testCase,BordComputer bordComputer,String instanceName) {
bordComputer.meetAllPreconditionForPlay();
assertThat(bordComputer.play()).describedAs(testName).isNotEqualTo(null);
}
static Stream<Arguments> playDate()throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
BordComputer bordComputer = new BordComputer();
bordComputer.readConfig();
return Stream.of(
Arguments.of("[CDPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case1",bordComputer,"CDPlayer")
);
}
}

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

@ -30,7 +30,8 @@ class CDPlayerTest {
Exception newException=assertThrows(exception.getClass(),()->_cdPlayer.play());
assertEquals(expectedResult, newException.getMessage());
}else{
assertThat(_cdPlayer.play()).describedAs(testName).isEqualTo(expectedResult);
_cdPlayer.play();
assertThat(_cdPlayer.getStatus()).describedAs(testName).isEqualTo(expectedResult);
}
}
static Stream<Arguments> playTestData () {

Loading…
Cancel
Save