Browse Source

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

feature-pr-lastUpdate
JPANZO 3 years ago
parent
commit
73677960d4
  1. 15
      src/main/java/BordComputer.java
  2. 10
      src/test/java/BordComputerTest.java

15
src/main/java/BordComputer.java

@ -47,18 +47,10 @@ public class BordComputer {
//===== Hilf-Funktionen ======
public Object getInstanceByName(String deviceName){
public Device 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 installedDevices[i];
}
}
return null;
@ -78,4 +70,7 @@ public class BordComputer {
activeDevice=cdPlayer;
}
public void setActiveDevice(Device activeDevice) {
this.activeDevice = activeDevice;
}
}

10
src/test/java/BordComputerTest.java

@ -85,15 +85,23 @@ class BordComputerTest {
@ParameterizedTest
@MethodSource("playDate")
void playTest(String testName, String testCase,BordComputer bordComputer,String instanceName) {
if(testCase.equals("Case1")) {
bordComputer.meetAllPreconditionForPlay();
assertThat(bordComputer.play()).describedAs(testName).isNotEqualTo(null);
}
if(testCase.equals("Case2")) {
Device radioPlayer=bordComputer.getInstanceByName(instanceName);
bordComputer.setActiveDevice(radioPlayer);
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")
Arguments.of("[CDPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case1",bordComputer,"CDPlayer"),
Arguments.of("[RadioPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case2",bordComputer,"RadioPlayer")
);
}

Loading…
Cancel
Save