Browse Source

Merge commit '6c5989e12f15df61ecedbb5357c3e8c7688c9b23' into HEAD

feature-pr-RadioPlayer-getItemList
Jenkins 3 years ago
parent
commit
7f86735e36
  1. 9
      src/main/java/device/Device.java
  2. 16
      src/main/java/device/cdPlayer/CDPlayer.java
  3. 7
      src/main/java/device/radioPlayer/RadioPlayer.java
  4. 7
      src/main/java/device/usbPlayer/UsbPlayer.java
  5. 21
      src/test/java/device/cdPlayer/CDPlayerTest.java

9
src/main/java/device/Device.java

@ -7,13 +7,14 @@ public interface Device {
int getVolume(); int getVolume();
void next(); void next();
void prev(); void prev();
//get deviceName, Album and current Item
String getInfoText(); String getInfoText();
//returns an array with Method-Names to bee listed
//get a list of public methods
String[] getOptions(); String[] getOptions();
//returns an array with contents to bee played
//get an Item of the Album
String chooseItem(int itemNr);
// get the actual album
String[] getItemList(); String[] getItemList();
String play(); String play();
} }

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

@ -2,6 +2,8 @@ package device.cdPlayer;
import device.Device; import device.Device;
import device.cdPlayer.exceptions.*; import device.cdPlayer.exceptions.*;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -69,7 +71,18 @@ public class CDPlayer implements Device {
@Override @Override
public String[] getOptions() { public String[] getOptions() {
return new String[0];
Method[] methods=this.getClass().getDeclaredMethods();
String[] outMethods=new String[methods.length];
for (int i = 0; i <methods.length ; i++) {
outMethods[i]=methods[i].getName();
}
return outMethods;
}
@Override
public String chooseItem(int itemNr) {
return null;
} }
@Override @Override
@ -77,7 +90,6 @@ public class CDPlayer implements Device {
return loadedCD.getPlayList(); return loadedCD.getPlayList();
} }
@Override @Override
public String play() { public String play() {
if(isCdFlapOpen()){ if(isCdFlapOpen()){

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

@ -156,9 +156,14 @@ public class RadioPlayer implements Device {
return new String[0]; return new String[0];
} }
@Override
public String chooseItem(int itemNr) {
return null;
}
@Override @Override
public String[] getItemList() { public String[] getItemList() {
return new String[0];
return null;
} }

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

@ -150,9 +150,14 @@ public class UsbPlayer implements Device {
return new String[0]; return new String[0];
} }
@Override
public String chooseItem(int itemNr) {
return null;
}
@Override @Override
public String[] getItemList() { public String[] getItemList() {
return new String[0];
return null;
} }

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

@ -228,4 +228,25 @@ class CDPlayerTest {
Arguments.of("[getActualPlayTrack() after 1x prev() starting by firstSong] => FirstSongSelected", "StartingByFirstSong", cdPlayer1, 1, cdPlayer1.getSongByNumber(0)) Arguments.of("[getActualPlayTrack() after 1x prev() starting by firstSong] => FirstSongSelected", "StartingByFirstSong", cdPlayer1, 1, cdPlayer1.getSongByNumber(0))
); );
} }
@ParameterizedTest
@MethodSource("getOptionsTestData")
void getOptionsTest(String testName,String testDirection, CDPlayer _cdPlayer, String expectedResult){
if(testDirection.equals("ReturnValueNotNull")) {
assertThat(_cdPlayer.getOptions()).describedAs(testName).isNotEqualTo(null);
}
if(testDirection.equals("ArrayLengthGreaterThen0")) {
assertThat(_cdPlayer.getOptions().length).describedAs(testName).isNotEqualTo(0);
}
}
static Stream<Arguments> getOptionsTestData () {
CDPlayer cdPlayer1 = new CDPlayer();
return Stream.of(
Arguments.of("[getOptions(): shouldNotReturnNull] => ReturnValueNotNull", "ReturnValueNotNull", cdPlayer1,null),
Arguments.of("[getOptions(): shouldReturnAnArrayWithLengthGreaterThen0] => ArrayLengthGreaterThen0", "ArrayLengthGreaterThen0", cdPlayer1,null)
);
}
} }
Loading…
Cancel
Save