Browse Source

Merge remote-tracking branch 'origin/master'

feature-pr-organization
JPANZO 3 years ago
parent
commit
f53ab10cde
  1. 110
      src/main/java/device/usbPlayer/UsbPlayer.java
  2. 39
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -2,9 +2,50 @@ package device.usbPlayer;
import device.Device; import device.Device;
import java.util.ArrayList;
public class UsbPlayer implements Device { public class UsbPlayer implements Device {
private int Lautstaerke = 0;
private ArrayList<String> Playlist = new ArrayList<String>();
private String playTrack = "";
private Boolean isConnected;
private Boolean isDefect;
int Lautstaerke = 0;
//*********setters und getters********
public ArrayList<String> getPlaylist() {
return Playlist;
}
public void setPlaylist(ArrayList<String> playlist) {
Playlist = playlist;
}
public Boolean getDefect() {
return isDefect;
}
public void setDefect(Boolean defect) {
isDefect = defect;
}
public Boolean getConnected() {
return isConnected;
}
public void setConnected(Boolean connected) {
isConnected = connected;
}
public String getPlayTrack() {
return playTrack;
}
public void setPlayTrack(String playTrack) {
this.playTrack = playTrack;
}
public void setLautstaerke(int ls) { public void setLautstaerke(int ls) {
if (ls <= 100) { if (ls <= 100) {
@ -16,15 +57,35 @@ public class UsbPlayer implements Device {
return Lautstaerke; return Lautstaerke;
} }
@Override
public void louder() {
if(Lautstaerke < 100) {
Lautstaerke += 1;
} else {
Lautstaerke = 100;
//*********constructure********
public UsbPlayer() {
super();
isDefect = false;
isConnected = true;
Playlist.add("Musik 01.mp3");
Playlist.add("Musik 02.mp3");
Playlist.add("Musik 03.mp3");
playTrack = Playlist.get(0);
}
//**********search method*************
private boolean isAllAudio() {
String song = "";
boolean flag = true;
for (int i = 0; i < Playlist.size(); i++) {
song = Playlist.get(i).substring(Playlist.get(i).length() - 4);
if (song.equals(".mp3") | song.equals(".mp4") | song.equals(".wav")) {
flag = true;
} else {
flag = false;
break;
}
} }
return flag;
} }
//**********search method*************
@Override @Override
public void quieter() { public void quieter() {
if(Lautstaerke > 0) { if(Lautstaerke > 0) {
@ -34,6 +95,15 @@ public class UsbPlayer implements Device {
} }
} }
@Override
public void louder() {
if(Lautstaerke < 100) {
Lautstaerke += 1;
} else {
Lautstaerke = 100;
}
}
@Override @Override
public int getVolume() { public int getVolume() {
return 0; return 0;
@ -67,7 +137,29 @@ public class UsbPlayer implements Device {
@Override @Override
public String play() { public String play() {
return null;
String result = "USB : ";
if (isConnected == true) {
result += "connected,";
if (isDefect == false) {
result += "working";
if (this.Playlist.size() != 0) {
result += ",have a list";
if (this.isAllAudio()) {
result += ",Audio";
if (!playTrack.equals(""))
result += ",point to a track.";
else
result += ",doesn't point to a track.";
} else {
result += ",not Audio.";
}
} else result += ",have no list.";
} else {
result += "not working.";
}
} else result = "not connected.";
return result;
} }
} }

39
src/test/java/device/radioPlayer/RadioPlayerTest.java

@ -2,7 +2,13 @@ package device.radioPlayer;
import device.radioPlayer.RadioPlayer; import device.radioPlayer.RadioPlayer;
import device.usbPlayer.UsbPlayer;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -43,22 +49,31 @@ class RadioPlayerTest {
void getVolume() { void getVolume() {
} }
*/ */
@Test
void next() {
rp.next();
int currentIndex=rp.Playlist.indexOf(rp.playTrack);
assertThat(rp.playTrack).isEqualTo(rp.Playlist.get((currentIndex)%rp.Playlist.size()));
}
@Test
void prev() {
rp.prev();
int currentIndex=rp.Playlist.indexOf(rp.playTrack);
assertThat(rp.playTrack).isEqualTo(rp.Playlist.get((currentIndex)%rp.Playlist.size()));
@ParameterizedTest
@MethodSource("prevNextOptions")
void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) {
String station = testRp.playTrack;
assertThat(station).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> prevNextOptions() {
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
RadioPlayer rp3 = new RadioPlayer();
rp1.next();
rp2.next();
rp2.prev();
rp3.prev();
return Stream.of(
Arguments.of("Next Station Test", rp1, "Radio Teddy"),
Arguments.of("Prev Station Test", rp2, "Radio YouFM"),
Arguments.of("Prev works on first Station ", rp3, "Radio MegaHits")
);
} }
/* /*
@Test @Test
void getInfoText() { void getInfoText() {
} }

Loading…
Cancel
Save