Browse Source

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

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

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

@ -11,15 +11,18 @@ public class RadioPlayer implements Device {
public RadioPlayer() { public RadioPlayer() {
super(); 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(); LocalDateTime now = LocalDateTime.now();
int hour = now.getHour(); int hour = now.getHour();
int Lautstaerke = 0;
String playedStation = "";
public String getYouFMInfoByTime(int x) { public String getYouFMInfoByTime(int x) {
if (x >= 5 && x < 10) return YouFMInfo[0]; 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"}; 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) { public void setLautstaerke(int lautstaerke) {
Lautstaerke = lautstaerke; Lautstaerke = lautstaerke;
} }
@ -67,50 +67,46 @@ public class RadioPlayer implements Device {
public void changeRegion(String region) { public void changeRegion(String region) {
switch (region) { switch (region) {
case "BY": 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; break;
case "HE": 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; break;
case "BW": 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; break;
} }
} }
@Override @Override
public void louder() { public void louder() {
if(Lautstaerke < 100){Lautstaerke+=1;}
else Lautstaerke = 100;
if (Lautstaerke < 100) {
Lautstaerke += 1;
} else Lautstaerke = 100;
} }
@Override @Override
public void quieter() { public void quieter() {
if(Lautstaerke > 0){Lautstaerke-=1;}
else Lautstaerke = 0;
if (Lautstaerke > 0) {
Lautstaerke -= 1;
} else Lautstaerke = 0;
} }
@Override @Override
public int getVolume() { public int getVolume() {
return Lautstaerke; return Lautstaerke;
@ -118,17 +114,19 @@ public class RadioPlayer implements Device {
@Override @Override
public void next() { 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 @Override
public void prev() { 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 @Override
@ -149,20 +147,26 @@ public class RadioPlayer implements Device {
@Override @Override
public String play() { 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() { public String showStationInfo() {
switch (playTrack) {
switch (playedStation) {
case "Antenne Bayern": case "Antenne Bayern":
return getAntenneBYInfoByTime(hour); return getAntenneBYInfoByTime(hour);
case "YouFM": case "YouFM":
return getYouFMInfoByTime(hour); return getYouFMInfoByTime(hour);
case "Bayern 3": case "Bayern 3":
return getBR3InfoByTime(hour); return getBR3InfoByTime(hour);
default: return "";
default:
return "";
} }
} }
public String saveStation() {
savedPlaylist.add(playedStation);
return "";
}
} }

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

@ -1,8 +1,6 @@
package device.radioPlayer; package device.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.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
@ -15,7 +13,6 @@ import static org.assertj.core.api.Assertions.assertThat;
class RadioPlayerTest { class RadioPlayerTest {
@ParameterizedTest @ParameterizedTest
@MethodSource("quieterLouderOptions") @MethodSource("quieterLouderOptions")
void quieterLouderTest(String testName, RadioPlayer testRp, int expectedResult) { void quieterLouderTest(String testName, RadioPlayer testRp, int expectedResult) {
@ -47,7 +44,7 @@ class RadioPlayerTest {
@ParameterizedTest @ParameterizedTest
@MethodSource("changeRegionOptions") @MethodSource("changeRegionOptions")
void changeRegionTest(String testName, RadioPlayer testRp, String expectedResult) { void changeRegionTest(String testName, RadioPlayer testRp, String expectedResult) {
String station = testRp.playTrack;
String station = testRp.playedStation;
assertThat(station).describedAs(testName).isEqualTo(expectedResult); assertThat(station).describedAs(testName).isEqualTo(expectedResult);
} }
@ -70,7 +67,7 @@ class RadioPlayerTest {
@ParameterizedTest @ParameterizedTest
@MethodSource("prevNextOptions") @MethodSource("prevNextOptions")
void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) { void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) {
String station = testRp.playTrack;
String station = testRp.playedStation;
assertThat(station).describedAs(testName).isEqualTo(expectedResult); assertThat(station).describedAs(testName).isEqualTo(expectedResult);
} }
@ -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