Browse Source

BordComputer.play; instance of CDPlayer -> without fulfilling preconditions: ShouldReturnAnException.

feature-pr-lastUpdate
JPANZO 3 years ago
parent
commit
14c63c6a1e
  1. 9
      src/main/java/BordComputer.java
  2. 7
      src/main/java/exception/NoItemEvenAllPreconditionAreMet.java
  3. 16
      src/test/java/BordComputerTest.java

9
src/main/java/BordComputer.java

@ -4,6 +4,7 @@ import device.cdPlayer.CDPlayer;
import device.radioPlayer.RadioPlayer;
import device.usbPlayer.USB_Stick;
import device.usbPlayer.UsbPlayer;
import exception.NoItemEvenAllPreconditionAreMet;
import java.io.FileReader;
import java.lang.reflect.InvocationTargetException;
@ -42,7 +43,13 @@ public class BordComputer {
}
public String play(){
String itemToPlay=activeDevice.play();
String itemToPlay=null;
try {
itemToPlay=activeDevice.play();
}catch (RuntimeException exception) {
throw new NoItemEvenAllPreconditionAreMet();
}
return itemToPlay;
}

7
src/main/java/exception/NoItemEvenAllPreconditionAreMet.java

@ -0,0 +1,7 @@
package exception;
public class NoItemEvenAllPreconditionAreMet extends RuntimeException{
public NoItemEvenAllPreconditionAreMet(){
super("No Item returned even all preconditions are met.");
}
}

16
src/test/java/BordComputerTest.java

@ -1,7 +1,9 @@
import device.Device;
import device.cdPlayer.CDPlayer;
import device.cdPlayer.exceptions.NegativeInputException;
import device.radioPlayer.RadioPlayer;
import device.usbPlayer.UsbPlayer;
import exception.NoItemEvenAllPreconditionAreMet;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@ -100,15 +102,25 @@ class BordComputerTest {
bordComputer.meetAllPreconditionForPlay();
assertThat(bordComputer.play()).describedAs(testName).isNotEqualTo(null);
}
if(testCase.equals("Case4")) {
Exception newException = assertThrows(NoItemEvenAllPreconditionAreMet.class, () -> bordComputer.play());
assertEquals(NoItemEvenAllPreconditionAreMet.class, newException.getClass());
assertEquals(newException.getMessage(), "No Item returned even all preconditions are met.");
}
}
static Stream<Arguments> playDate()throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
BordComputer bordComputer = new BordComputer();
bordComputer.readConfig();
bordComputer.readConfig();
BordComputer bordComputer2 = new BordComputer();
bordComputer2.readConfig();
return Stream.of(
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"),
Arguments.of("[UsbPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case3",bordComputer,"UsbPlayer")
Arguments.of("[UsbPlayer-> play(): after all preconditions are met] => ShouldReturnAnItemToPlay","Case3",bordComputer,"UsbPlayer"),
Arguments.of("[CDPlayer-> play(): without fulfilling preconditions] => ShouldReturnAnException","Case4",bordComputer2,"CDPlayer")
);
}

Loading…
Cancel
Save