2 Commits

  1. 40
      src/main/java/device/radioPlayer/RadioPlayer.java
  2. 46
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -1,7 +1,6 @@
package device.radioPlayer;
import device.Device;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.util.ArrayList;
@ -9,8 +8,6 @@ import java.util.Arrays;
public class RadioPlayer implements Device {
private int x;
public RadioPlayer() {
super();
savedPlaylist.add("YouFM");
@ -19,13 +16,13 @@ public class RadioPlayer implements Device {
playedStation = savedPlaylist.get(0);
}
ArrayList<String> savedPlaylist = new ArrayList<String>();
ArrayList<String> regionPlaylist = new ArrayList<String>();
ArrayList<String> savedPlaylist = new ArrayList<>();
ArrayList<String> regionPlaylist = new ArrayList<>();
LocalDateTime now = LocalDateTime.now();
int hour = now.getHour();
int Lautstaerke = 0;
int volume = 0;
int savedVolume;
String playedStation = "";
String playedStation;
public String getYouFMInfoByTime(int x) {
if (x >= 5 && x < 10) return YouFMInfo[0];
@ -63,8 +60,8 @@ 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"};
public void setLautstaerke(int lautstaerke) {
Lautstaerke = lautstaerke;
public void setVolume(int volume) {
this.volume = volume;
}
public void changeRegion(String region) {
@ -98,21 +95,21 @@ public class RadioPlayer implements Device {
@Override
public void louder() {
if (Lautstaerke < 100) {
Lautstaerke += 1;
} else Lautstaerke = 100;
if (volume < 100) {
volume += 1;
} else volume = 100;
}
@Override
public void quieter() {
if (Lautstaerke > 0) {
Lautstaerke -= 1;
} else Lautstaerke = 0;
if (volume > 0) {
volume -= 1;
} else volume = 0;
}
@Override
public int getVolume() {
return Lautstaerke;
return volume;
}
@Override
@ -165,9 +162,8 @@ public class RadioPlayer implements Device {
@Override
public String[] getOptions() {
Method[] methods = this.getClass().getDeclaredMethods();
String[] returnMethods = Arrays.stream(methods).map(Method::getName).toArray(String[]::new);
return returnMethods;
return Arrays.stream(methods).map(Method::getName).toArray(String[]::new);
}
@Override
@ -208,17 +204,16 @@ public class RadioPlayer implements Device {
@Override
public String mute() {
savedVolume = getVolume();
setLautstaerke(0);
setVolume(0);
return "RadioPlayer is muted now";
}
@Override
public String unmute() {
setLautstaerke(savedVolume);
setVolume(savedVolume);
return ("RadioPlayer is unmuted Volume is set to " + getVolume());
}
@Override
public String play() {
if (regionPlaylist.contains(playedStation))
@ -238,8 +233,6 @@ public class RadioPlayer implements Device {
default:
return "";
}
}
public String saveStation() {
@ -249,7 +242,6 @@ public class RadioPlayer implements Device {
return "Station " + playedStation + " is saved in your Station list";
}
public String deleteStation() {
String station = playedStation;
if ((savedPlaylist.size()) > 1) {

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

@ -1,6 +1,5 @@
package device.radioPlayer;
import device.Device;
import org.assertj.core.util.Strings;
import org.junit.jupiter.api.Test;
@ -18,7 +17,6 @@ import static org.assertj.core.api.Assertions.assertThat;
class RadioPlayerTest {
@ParameterizedTest
@MethodSource("quieterLouderOptions")
void quieterLouderTest(String testName, RadioPlayer testRp, int expectedResult) {
@ -31,13 +29,13 @@ class RadioPlayerTest {
RadioPlayer rp2 = new RadioPlayer();
RadioPlayer rp3 = new RadioPlayer();
RadioPlayer rp4 = new RadioPlayer();
rp1.setLautstaerke(0);
rp1.setVolume(0);
rp1.louder();
rp2.setLautstaerke(100);
rp2.setVolume(100);
rp2.louder();
rp3.setLautstaerke(1);
rp3.setVolume(1);
rp3.quieter();
rp4.setLautstaerke(0);
rp4.setVolume(0);
rp4.quieter();
return Stream.of(
Arguments.of("Test for one step louder", rp1, 1),
@ -61,7 +59,6 @@ class RadioPlayerTest {
rp1.changeRegion("BY");
rp2.changeRegion("HE");
rp3.changeRegion("BW");
return Stream.of(
Arguments.of("Test change Region to Bayern", rp1, "Antenne Bayern"),
Arguments.of("Test change Region to Hessen", rp2, "Hit Radio FFH"),
@ -69,7 +66,6 @@ class RadioPlayerTest {
);
}
@ParameterizedTest
@MethodSource("prevNextOptions")
void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) {
@ -95,7 +91,6 @@ class RadioPlayerTest {
rp6.changeRegion("BY");
rp6.saveStation();
rp6.next();
return Stream.of(
Arguments.of("Next Station Test for saved Stations", rp1, "Teddy"),
Arguments.of("Prev Station Test for saved Stations", rp2, "YouFM"),
@ -159,7 +154,6 @@ class RadioPlayerTest {
rp3.next();
RadioPlayer rp4 = new RadioPlayer();
rp4.next();
return Stream.of(
Arguments.of("Show Station Info for first saved Radio", rp1, rp1.getYouFMInfoByTime(rp1.hour)),
Arguments.of("Show Station Info for regional Station", rp2, rp2.getAntenneBYInfoByTime(rp2.hour)),
@ -168,17 +162,6 @@ class RadioPlayerTest {
);
}
/*
@Test
void getInfoText() {
}
@Test
void getOptions() {
}
*/
@ParameterizedTest
@MethodSource("chooseItemOptions")
void testChooseItem(String testName, RadioPlayer testRp, String expectedResult) {
@ -202,7 +185,6 @@ class RadioPlayerTest {
RadioPlayer rp5 = new RadioPlayer();
rp5.changeRegion("BY");
rp5.chooseItem(-2);
return Stream.of(
Arguments.of("Test select station in saved playlist to play with nr isn`t bigger than playlist size", rp, "Teddy"),
Arguments.of("Test select station in saved playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp1, "MegaHits"),
@ -250,7 +232,6 @@ class RadioPlayerTest {
rp2.saveStation();
rp3.changeRegion("BY");
rp3.saveStation();
return Stream.of(
Arguments.of("Test for saving station in saved playlist", rp1, "normal", "Antenne Bayern"),
Arguments.of("Test for not saving station which is already in saved playlist", rp2, "normal", "MegaHits"),
@ -275,7 +256,6 @@ class RadioPlayerTest {
rp1.deleteStation();
rp1.deleteStation();
rp1.deleteStation();
return Stream.of(
Arguments.of("Test for delete station in saved playlist", rp, "delete", false),
Arguments.of("Test for not delete station in saved playlist if this is the last station", rp1, "noDelete", true)
@ -295,7 +275,6 @@ class RadioPlayerTest {
RadioPlayer rp1 = new RadioPlayer();
rp1.changeRegion("BY");
rp1.changeToSavedPlaylist();
return Stream.of(
Arguments.of("Test for change to saved playlist when you already in saved playlist", rp, "YouFM"),
Arguments.of("Test for change to saved playlist when in regional playlist", rp1, "YouFM")
@ -319,7 +298,6 @@ class RadioPlayerTest {
RadioPlayer rp2 = new RadioPlayer();
rp2.next();
rp2.changeOrderInSavedPlaylist(-1);
return Stream.of(
Arguments.of("Test for change order in saved playlist with nr isn`t bigger than playlist size", rp, 0, "Teddy"),
Arguments.of("Test for change order in saved playlist with nr is than bigger playlist size put at the end of playlist", rp1, 2, "YouFM"),
@ -342,7 +320,6 @@ class RadioPlayerTest {
RadioPlayer rp = new RadioPlayer();
RadioPlayer rp1 = new RadioPlayer();
rp1.changeRegion("BY");
return Stream.of(
Arguments.of("Test for return saved playlist", rp, "saved", rp.savedPlaylist.toArray(new String[0])),
Arguments.of("Test for return regional playlist", rp1, "region", rp1.regionPlaylist.toArray(new String[0]))
@ -360,12 +337,11 @@ class RadioPlayerTest {
static Stream<Arguments> muteOptions() {
RadioPlayer rp = new RadioPlayer();
rp.setLautstaerke(25);
rp.setVolume(25);
rp.mute();
RadioPlayer rp1 = new RadioPlayer();
rp1.setLautstaerke(30);
rp1.setVolume(30);
rp1.mute();
return Stream.of(
Arguments.of("Test for mute RadioPlayer if volume is actually 0", "actual", rp, 0),
Arguments.of("Test for mute RadioPlayer if volume is saved before muting", "saved", rp1, 30)
@ -375,7 +351,7 @@ class RadioPlayerTest {
@Test
void testUnmute() {
RadioPlayer rp = new RadioPlayer();
rp.setLautstaerke(40);
rp.setVolume(40);
rp.mute();
rp.unmute();
assertThat(rp.getVolume()).describedAs("Test if unmute is setting the saved volume").isEqualTo(rp.savedVolume);
@ -401,10 +377,8 @@ class RadioPlayerTest {
static Stream<Arguments> getInfoTextOptions() {
RadioPlayer rp = new RadioPlayer();
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
rp2.changeRegion("BY");
RadioPlayer rp3 = new RadioPlayer();
RadioPlayer rp4 = new RadioPlayer();
rp4.next();
RadioPlayer rp5 = new RadioPlayer();
@ -414,12 +388,11 @@ class RadioPlayerTest {
rp6.changeRegion("BY");
RadioPlayer rp7 = new RadioPlayer();
rp7.next();
return Stream.of(
Arguments.of("Test for getInfoText is not empty or null", "null", rp, false),
Arguments.of("Test for getInfoText contains played station", "station", rp1, true),
Arguments.of("Test for getInfoText contains played station", "station", rp, true),
Arguments.of("Test for getInfoText contains regional playlist if played station is in it", "region", rp2, true),
Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp3, true),
Arguments.of("Test for getInfoText contains saved playlist if played station is in it", "saved", rp, true),
Arguments.of("Test for getInfoText contains station number in saved playlist", "savedNum", rp4, true),
Arguments.of("Test for getInfoText contains station number in regional playlist", "regionNum", rp5, true),
Arguments.of("Test for getInfoText contains station info if station has one", "stationInfo", rp6, true),
@ -444,7 +417,6 @@ class RadioPlayerTest {
static Stream<Arguments> getOptionsOptions() {
RadioPlayer rp = new RadioPlayer();
return Stream.of(
Arguments.of("returnValue of getOptions is not null", "notNull", rp),
Arguments.of("should not return an empty array", "arrayLengthGreater0", rp),

Loading…
Cancel
Save