Browse Source

Merge commit 'ecf5a3e4ad2363a766081e57c9e30ec4f7cfbc62' into HEAD

feature-pr-playAddedRegionIndicator
Jenkins 3 years ago
parent
commit
c2ae912a58
  1. 117
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 41
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -11,15 +11,18 @@ public class RadioPlayer implements Device {
public RadioPlayer() {
super();
Playlist.add("YouFM");
Playlist.add("Teddy");
Playlist.add("MegaHits");
playTrack=Playlist.get(0);
savedPlaylist.add("YouFM");
savedPlaylist.add("Teddy");
savedPlaylist.add("MegaHits");
playedStation = savedPlaylist.get(0);
}
ArrayList<String> Playlist=new ArrayList<String>();
ArrayList<String> savedPlaylist = new ArrayList<String>();
ArrayList<String> regionPlaylist = new ArrayList<String>();
LocalDateTime now = LocalDateTime.now();
int hour = now.getHour();
int Lautstaerke = 0;
String playedStation = "";
public String getYouFMInfoByTime(int x) {
if (x >= 5 && x < 10) return YouFMInfo[0];
@ -57,9 +60,6 @@ public class RadioPlayer implements Device {
String[] AntenneBYInfo = {"ANTENNE BAYERN Guten Morgen Bayern", "ANTENNE BAYERN bei der Arbeit", "ANTENNE BAYERN am Nachmittag", "ANTENNE BAYERN am Abend", "ANTENNE BAYERN Hit-Nacht"};
int Lautstaerke = 0;
String playTrack="";
public void setLautstaerke(int lautstaerke) {
Lautstaerke = lautstaerke;
}
@ -67,50 +67,46 @@ public class RadioPlayer implements Device {
public void changeRegion(String region) {
switch (region) {
case "BY":
Playlist.clear();
Playlist.add("Antenne Bayern");
Playlist.add("Bayern 1");
Playlist.add("Bayern 3");
Playlist.add("Hit Radio N1");
playTrack=Playlist.get(0);
regionPlaylist.clear();
regionPlaylist.add("Antenne Bayern");
regionPlaylist.add("Bayern 1");
regionPlaylist.add("Bayern 3");
regionPlaylist.add("Hit Radio N1");
playedStation = regionPlaylist.get(0);
break;
case "HE":
Playlist.clear();
Playlist.add("Hit Radio FFH");
Playlist.add("HR 1");
Playlist.add("HR 3");
Playlist.add("YouFM");
playTrack=Playlist.get(0);
regionPlaylist.clear();
regionPlaylist.add("Hit Radio FFH");
regionPlaylist.add("HR 1");
regionPlaylist.add("HR 3");
regionPlaylist.add("YouFM");
playedStation = regionPlaylist.get(0);
break;
case "BW":
Playlist.clear();
Playlist.add("DASDING");
Playlist.add("SWR 1");
Playlist.add("SWR 3");
Playlist.add("sunshine live");
playTrack=Playlist.get(0);
break;
default:
Playlist.clear();
Playlist.add("YouFM");
Playlist.add("Teddy");
Playlist.add("MegaHits");
playTrack=Playlist.get(0);
regionPlaylist.clear();
regionPlaylist.add("DASDING");
regionPlaylist.add("SWR 1");
regionPlaylist.add("SWR 3");
regionPlaylist.add("sunshine live");
playedStation = regionPlaylist.get(0);
break;
}
}
@Override
public void louder() {
if(Lautstaerke < 100){Lautstaerke+=1;}
else Lautstaerke = 100;
if (Lautstaerke < 100) {
Lautstaerke += 1;
} else Lautstaerke = 100;
}
@Override
public void quieter() {
if(Lautstaerke > 0){Lautstaerke-=1;}
else Lautstaerke = 0;
if (Lautstaerke > 0) {
Lautstaerke -= 1;
} else Lautstaerke = 0;
}
@Override
public int getVolume() {
return Lautstaerke;
@ -118,17 +114,36 @@ public class RadioPlayer implements Device {
@Override
public void next() {
int currentIndex=Playlist.indexOf(playTrack);
int nextIndex=(currentIndex+1)%Playlist.size();
playTrack=Playlist.get(nextIndex);
if (regionPlaylist.contains(playedStation)) {
int currentIndex = regionPlaylist.indexOf(playedStation);
int nextIndex = (currentIndex + 1) % regionPlaylist.size();
playedStation = regionPlaylist.get(nextIndex);
} else {
int currentIndex = savedPlaylist.indexOf(playedStation);
int nextIndex = (currentIndex + 1) % savedPlaylist.size();
playedStation = savedPlaylist.get(nextIndex);
}
}
@Override
public void prev() {
int currentIndex=Playlist.indexOf(playTrack);
int nextIndex=Playlist.size()-1;
if(currentIndex!=0){nextIndex=(currentIndex-1);}
playTrack=Playlist.get(nextIndex);
if (regionPlaylist.contains(playedStation)) {
int currentIndex = regionPlaylist.indexOf(playedStation);
int nextIndex = regionPlaylist.size() - 1;
if (currentIndex != 0) {
nextIndex = (currentIndex - 1);
}
playedStation = regionPlaylist.get(nextIndex);
} else {
{
int currentIndex = savedPlaylist.indexOf(playedStation);
int nextIndex = savedPlaylist.size() - 1;
if (currentIndex != 0) {
nextIndex = (currentIndex - 1);
}
playedStation = savedPlaylist.get(nextIndex);
}
}
}
@Override
@ -149,20 +164,28 @@ public class RadioPlayer implements Device {
@Override
public String play() {
return ("Radio is playing station: 0"+(Playlist.indexOf(playTrack)+1)+ " "+this.playTrack);
return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation);
}
public String showStationInfo() {
switch (playTrack) {
switch (playedStation) {
case "Antenne Bayern":
return getAntenneBYInfoByTime(hour);
case "YouFM":
return getYouFMInfoByTime(hour);
case "Bayern 3":
return getBR3InfoByTime(hour);
default: return "";
default:
return "";
}
}
public String saveStation() {
if (savedPlaylist.contains(playedStation)) return "Station " + playedStation + " is already saved";
else
savedPlaylist.add(playedStation);
return "Station " + playedStation + " is saved in your Station list";
}
}

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

@ -1,8 +1,6 @@
package device.radioPlayer;
import device.radioPlayer.RadioPlayer;
import device.usbPlayer.UsbPlayer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@ -15,7 +13,6 @@ import static org.assertj.core.api.Assertions.assertThat;
class RadioPlayerTest {
@ParameterizedTest
@MethodSource("quieterLouderOptions")
void quieterLouderTest(String testName, RadioPlayer testRp, int expectedResult) {
@ -47,7 +44,7 @@ class RadioPlayerTest {
@ParameterizedTest
@MethodSource("changeRegionOptions")
void changeRegionTest(String testName, RadioPlayer testRp, String expectedResult) {
String station = testRp.playTrack;
String station = testRp.playedStation;
assertThat(station).describedAs(testName).isEqualTo(expectedResult);
}
@ -70,7 +67,7 @@ class RadioPlayerTest {
@ParameterizedTest
@MethodSource("prevNextOptions")
void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) {
String station = testRp.playTrack;
String station = testRp.playedStation;
assertThat(station).describedAs(testName).isEqualTo(expectedResult);
}
@ -78,14 +75,22 @@ class RadioPlayerTest {
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
RadioPlayer rp3 = new RadioPlayer();
RadioPlayer rp4 = new RadioPlayer();
RadioPlayer rp5 = new RadioPlayer();
rp1.next();
rp2.next();
rp2.prev();
rp3.prev();
rp4.changeRegion("BY");
rp4.next();
rp5.changeRegion("BY");
rp5.prev();
return Stream.of(
Arguments.of("Next Station Test", rp1, "Teddy"),
Arguments.of("Prev Station Test", rp2, "YouFM"),
Arguments.of("Prev works on first Station ", rp3, "MegaHits")
Arguments.of("Next Station Test for saved Stations", rp1, "Teddy"),
Arguments.of("Prev Station Test for saved Stations", rp2, "YouFM"),
Arguments.of("Prev works on first Station for saved Stations", rp3, "MegaHits"),
Arguments.of("changed Region and going to next station", rp4, "Bayern 1"),
Arguments.of("changed Region and going to prev station", rp5, "Hit Radio N1")
);
}
@ -180,4 +185,24 @@ void testPlay(String testName, RadioPlayer testRp, String expectedResult) {
);
}
@ParameterizedTest
@MethodSource("saveStationOptions")
void testSaveStation(String testName, RadioPlayer testRp, String expectedResult) {
String savedStation = testRp.savedPlaylist.get(testRp.savedPlaylist.size() - 1);
assertThat(savedStation).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> saveStationOptions() {
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
rp1.changeRegion("BY");
rp1.saveStation();
rp2.saveStation();
return Stream.of(
Arguments.of("Test for saving station in saved playlist", rp1, "Antenne Bayern"),
Arguments.of("Test for not saving station which is already in saved playlist", rp2, "MegaHits")
);
}
}
Loading…
Cancel
Save