Browse Source

added saveStation() and first test for adding station to savedPlaylist

feature-pr-saveStations
Jan Ortner 3 years ago
parent
commit
d38a65b490
  1. 108
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 38
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -11,18 +11,21 @@ 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];
if (x >= 5 && x < 10) return YouFMInfo[0];
else if (x >= 10 && x < 14) return YouFMInfo[1];
else if (x >= 14 && x < 18) return YouFMInfo[2];
else if (x >= 18 && x < 20) return YouFMInfo[3];
@ -34,7 +37,7 @@ public class RadioPlayer implements Device {
String[] YouFMInfo = {"YOUFM Good Morning Show", "YOUFM Worktime", "YOUFM am Nachmittag", "YOUFM am Abend", "YOUFM Wir feiern euch", "YOUFM Deutschrap ideal", "YOUFM Junge Nacht der ARD"};
public String getBR3InfoByTime(int x) {
if(x >= 5 && x <9) return BR3Info[0];
if (x >= 5 && x < 9) return BR3Info[0];
else if (x >= 9 && x < 12) return BR3Info[1];
else if (x == 12) return BR3Info[2];
else if (x >= 13 && x < 16) return BR3Info[3];
@ -44,10 +47,10 @@ public class RadioPlayer implements Device {
else return BR3Info[7];
}
String[] BR3Info = {"Sebastian Winkler und die Frühaufdreher", "BAYERN 3 - und DU mittendrin!", "Update", "Hits, Hits, Hits für euren Nachmittag", "Die Zwei für euren Feierabend", "Was geht?!", "Matuschke - der etwas andere Abend","Die Nacht"};
String[] BR3Info = {"Sebastian Winkler und die Frühaufdreher", "BAYERN 3 - und DU mittendrin!", "Update", "Hits, Hits, Hits für euren Nachmittag", "Die Zwei für euren Feierabend", "Was geht?!", "Matuschke - der etwas andere Abend", "Die Nacht"};
public String getAntenneBYInfoByTime(int x) {
if(x >= 5 && x <9) return AntenneBYInfo[0];
if (x >= 5 && x < 9) return AntenneBYInfo[0];
else if (x >= 9 && x < 12) return AntenneBYInfo[1];
else if (x >= 12 && x < 15) return AntenneBYInfo[2];
else if (x >= 15 && x < 19) return AntenneBYInfo[3];
@ -57,60 +60,53 @@ 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;
}
public void changeRegion(String region){
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,19 @@ public class RadioPlayer implements Device {
@Override
public void next() {
int currentIndex=Playlist.indexOf(playTrack);
int nextIndex=(currentIndex+1)%Playlist.size();
playTrack=Playlist.get(nextIndex);
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);
int currentIndex = savedPlaylist.indexOf(playedStation);
int nextIndex = savedPlaylist.size() - 1;
if (currentIndex != 0) {
nextIndex = (currentIndex - 1);
}
playedStation = savedPlaylist.get(nextIndex);
}
@Override
@ -149,20 +147,26 @@ 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() {
savedPlaylist.add(playedStation);
return "";
}
}

38
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,9 +67,9 @@ 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);
}
}
static Stream<Arguments> prevNextOptions() {
RadioPlayer rp1 = new RadioPlayer();
@ -151,7 +148,7 @@ class RadioPlayerTest {
);
}
/*
/*
@Test
void getInfoText() {
@ -164,13 +161,13 @@ class RadioPlayerTest {
@Test
void chooseOption() {
}
*/
@ParameterizedTest
@MethodSource("testPlayOptions")
void testPlay(String testName, RadioPlayer testRp, String expectedResult) {
*/
@ParameterizedTest
@MethodSource("testPlayOptions")
void testPlay(String testName, RadioPlayer testRp, String expectedResult) {
String playedStation = testRp.play();
assertThat(playedStation).describedAs(testName).isEqualTo(expectedResult);
}
}
static Stream<Arguments> testPlayOptions() {
RadioPlayer rp1 = new RadioPlayer();
@ -180,4 +177,21 @@ 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();
rp1.changeRegion("BY");
rp1.saveStation();
return Stream.of(
Arguments.of("Test for saving station in saved playlist", rp1, "Antenne Bayern")
);
}
}
Loading…
Cancel
Save