Browse Source

Merge branch 'master' into feature-pr-RadioPlayer-chooseItem

feature-pr-RadioPlayer-chooseItem
Jan Ortner 3 years ago
parent
commit
d6dbffa485
  1. 7
      src/main/java/device/Device.java
  2. 10
      src/main/java/device/cdPlayer/CDPlayer.java
  3. 10
      src/main/java/device/radioPlayer/RadioPlayer.java
  4. 10
      src/main/java/device/usbPlayer/UsbPlayer.java
  5. 31
      src/test/java/device/cdPlayer/CDPlayerTest.java

7
src/main/java/device/Device.java

@ -7,6 +7,7 @@ public interface Device {
int getVolume(); int getVolume();
void next(); void next();
void prev(); void prev();
String play();
//get deviceName, Album and current Item //get deviceName, Album and current Item
String getInfoText(); String getInfoText();
//get a list of public methods //get a list of public methods
@ -15,6 +16,8 @@ public interface Device {
String chooseItem(int itemNr); String chooseItem(int itemNr);
// get the actual album // get the actual album
String[] getItemList(); String[] getItemList();
String play();
//mute the Volume and returns an Info.
String mute();
//unmute the Volume and returns an Info.
String unmute();
} }

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

@ -90,6 +90,16 @@ public class CDPlayer implements Device {
return loadedCD.getPlayList(); return loadedCD.getPlayList();
} }
@Override
public String mute() {
return null;
}
@Override
public String unmute() {
return null;
}
@Override @Override
public String play() { public String play() {
if(isCdFlapOpen()){ if(isCdFlapOpen()){

10
src/main/java/device/radioPlayer/RadioPlayer.java

@ -188,6 +188,16 @@ public class RadioPlayer implements Device {
return null; return null;
} }
@Override
public String mute() {
return null;
}
@Override
public String unmute() {
return null;
}
@Override @Override
public String play() { public String play() {

10
src/main/java/device/usbPlayer/UsbPlayer.java

@ -160,6 +160,16 @@ public class UsbPlayer implements Device {
return null; return null;
} }
@Override
public String mute() {
return null;
}
@Override
public String unmute() {
return null;
}
@Override @Override
public String play() { public String play() {

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

@ -1,12 +1,18 @@
package device.cdPlayer; package device.cdPlayer;
import device.Device;
import device.cdPlayer.exceptions.*; import device.cdPlayer.exceptions.*;
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;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -231,22 +237,39 @@ class CDPlayerTest {
@ParameterizedTest @ParameterizedTest
@MethodSource("getOptionsTestData") @MethodSource("getOptionsTestData")
void getOptionsTest(String testName,String testDirection, CDPlayer _cdPlayer, String expectedResult){
void getOptionsTest(String testName,String testDirection, CDPlayer _cdPlayer){
if(testDirection.equals("ReturnValueNotNull")) { if(testDirection.equals("ReturnValueNotNull")) {
assertThat(_cdPlayer.getOptions()).describedAs(testName).isNotEqualTo(null); assertThat(_cdPlayer.getOptions()).describedAs(testName).isNotEqualTo(null);
} }
if(testDirection.equals("ArrayLengthGreaterThen0")) { if(testDirection.equals("ArrayLengthGreaterThen0")) {
assertThat(_cdPlayer.getOptions().length).describedAs(testName).isNotEqualTo(0); assertThat(_cdPlayer.getOptions().length).describedAs(testName).isNotEqualTo(0);
} }
if(testDirection.equals("ArrayContainsInterfaceMethods")) {
Method[]interfaceMethods=Device.class.getDeclaredMethods();
List<String> deviceMethods = new ArrayList<String>(Arrays.asList(_cdPlayer.getOptions()));
for (int i = 0; i < interfaceMethods.length; i++) {
assertThat(deviceMethods.contains(interfaceMethods[i].getName())).describedAs(testName).isEqualTo(true);
}
}
} }
static Stream<Arguments> getOptionsTestData () { static Stream<Arguments> getOptionsTestData () {
CDPlayer cdPlayer1 = new CDPlayer(); CDPlayer cdPlayer1 = new CDPlayer();
return Stream.of( return Stream.of(
Arguments.of("[getOptions(): shouldNotReturnNull] => ReturnValueNotNull", "ReturnValueNotNull", cdPlayer1,null),
Arguments.of("[getOptions(): shouldReturnAnArrayWithLengthGreaterThen0] => ArrayLengthGreaterThen0", "ArrayLengthGreaterThen0", cdPlayer1,null)
Arguments.of("[getOptions(): shouldNotReturnNull] => ReturnValueNotNull", "ReturnValueNotNull", cdPlayer1),
Arguments.of("[getOptions(): shouldReturnAnArrayWithLengthGreaterThen0] => ArrayLengthGreaterThen0", "ArrayLengthGreaterThen0", cdPlayer1),
Arguments.of("[getOptions(): shouldReturnAnArrayWithInAllInterfaceMethods] => ArrayContainsInterfaceMethods", "ArrayContainsInterfaceMethods", cdPlayer1)
); );
} }
@Test
void getVolumeReturnValueBetween0And100(){
CDPlayer cdPlayer1 = new CDPlayer();
boolean volumeIstInValueRange=false;
int volume=cdPlayer1.getVolume();
if(volume>=0 && volume <=100){
volumeIstInValueRange=true;
}
assertThat(volumeIstInValueRange).isEqualTo(true);
}
} }
Loading…
Cancel
Save