24 Commits

Author SHA1 Message Date
JPANZO 2e2be94402 Method changeToNextCD of CDPlayer tested changing_from_last_to_first CD -> FirstCDShouldBeTaken. 3 years ago
JPANZO b307012590 Method changeToNextCD of CDPlayer tested checking the effect2 -> loadedCDShouldNotHaveTheSameIdAsPrev. 3 years ago
JPANZO f77ed10d41 Method changeToNextCD of CDPlayer tested checking the effect -> loadedCDShouldNotReturnNull. 3 years ago
JPANZO 3d0f3997f2 Method changeToNextCD of CDPlayer tested on CDWechselerNotSelected -> shouldThrowAnException. 3 years ago
Jenkins ec60931dab Merge commit '7c7ae70a2b179b0cce12df32f2f06dd9664d16e4' into HEAD 3 years ago
Jenkins 2148801828 Merge commit '5885370fe321bede908b3baf3990fc0e9282dca3' into HEAD 3 years ago
Jan Ortner 5885370fe3 revised test for RadioPlayer getAntenneBYInfoByTime() 3 years ago
Jan Ortner 089fa0144f revised test for RadioPlayer getBR3InfoByTime() 3 years ago
Jan Ortner fc98df250d revised test for RadioPlayer getYouFMInfoByTime() 3 years ago
Jenkins c78b7dd6f4 Merge commit '32b80ec46d26c94ee1fc05658214d1b2b1874de4' into HEAD 3 years ago
Jan Ortner 32b80ec46d cleaned up RadioPlayer & RadioPlayerTest 3 years ago
Jenkins af8d3066c4 Merge commit '9ca1d2a492283b9860b6d2a40adeb4596db5d13c' into HEAD 3 years ago
Jan Ortner 9ca1d2a492 added third test case for RadioPlayer getOptions() 3 years ago
Jan Ortner f6361c27b8 added second test case for RadioPlayer getOptions() & added productive code 3 years ago
Jan Ortner 96c9e5c3b6 added first test case for RadioPlayer getOptions() 3 years ago
Jenkins e9946609b5 Merge commit '561d5f6bc27a64088b1bc2d52587508230337ab3' into HEAD 3 years ago
Jan Ortner 561d5f6bc2 added eighth test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jan Ortner 0ff584dc0a added sevens test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jan Ortner e6541cf2b9 added six test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jan Ortner dd88b2967c added fifth test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jan Ortner f754c0a5ce added fourth test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jan Ortner 9d20decf08 added third test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jan Ortner bc0ecd2675 added second test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
Jan Ortner 57114df69a added first test case for getInfoText() & and added productive code for RadioPlayer 3 years ago
  1. 16
      src/main/java/device/cdPlayer/CD.java
  2. 12
      src/main/java/device/cdPlayer/CDPlayer.java
  3. 6
      src/main/java/device/cdPlayer/CDWechseler.java
  4. 7
      src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java
  5. 53
      src/main/java/device/radioPlayer/RadioPlayer.java
  6. 66
      src/test/java/device/cdPlayer/CDPlayerTest.java
  7. 174
      src/test/java/device/radioPlayer/RadioPlayerTest.java

16
src/main/java/device/cdPlayer/CD.java

@ -4,6 +4,7 @@ public class CD {
private String format; private String format;
private String albumName; private String albumName;
private String[] playList; private String[] playList;
private String id;
public CD() {} public CD() {}
@ -16,6 +17,13 @@ public class CD {
this.playList = playList; this.playList = playList;
} }
public CD(String format, String albumName, String[] playList, String id) {
this.format = format;
this.albumName = albumName;
this.playList = playList;
this.id = id;
}
public String getFormat() { public String getFormat() {
return format; return format;
} }
@ -39,4 +47,12 @@ public class CD {
public void setAlbumName(String albumName) { public void setAlbumName(String albumName) {
this.albumName = albumName; this.albumName = albumName;
} }
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
} }

12
src/main/java/device/cdPlayer/CDPlayer.java

@ -152,7 +152,17 @@ public class CDPlayer implements Device {
throw new MaxCapacityExceededException(); throw new MaxCapacityExceededException();
} }
cdWechseler.loadOneCD(cd,index); cdWechseler.loadOneCD(cd,index);
System.out.println(index);
this.loadedCD=cdWechseler.getCDList().get(0);
}
public void changeToNextCD(){
if(activeSource.equals("CDDrive")){
throw new ChangeCDOnlyOnCDWechselerException();
}
List<CD> CDList = cdWechseler.getCDList();
int indexOfLoadedCD=CDList.indexOf(loadedCD);
int nextIndex=(indexOfLoadedCD+1)%CDList.size();
this.loadedCD=CDList.get(nextIndex);
} }
//Getters, Setters und SupportMethods //Getters, Setters und SupportMethods

6
src/main/java/device/cdPlayer/CDWechseler.java

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CDWechseler { public class CDWechseler {
private CD[]CDList=new CD[10];
private List<CD> CDList=new ArrayList<>();
private boolean running=false; private boolean running=false;
@ -16,11 +16,11 @@ public class CDWechseler {
this.running = true; this.running = true;
} }
public CD[] getCDList() {
public List<CD> getCDList() {
return CDList; return CDList;
} }
public void loadOneCD(CD cd, int index){ public void loadOneCD(CD cd, int index){
CDList[index]=cd;
CDList.add(cd);
} }
} }

7
src/main/java/device/cdPlayer/exceptions/ChangeCDOnlyOnCDWechselerException.java

@ -0,0 +1,7 @@
package device.cdPlayer.exceptions;
public class ChangeCDOnlyOnCDWechselerException extends RuntimeException{
public ChangeCDOnlyOnCDWechselerException(){
super("Change to next CD olny when CDWechseler is selected");
}
}

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

@ -1,14 +1,13 @@
package device.radioPlayer; package device.radioPlayer;
import device.Device; import device.Device;
import java.lang.reflect.Method;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
public class RadioPlayer implements Device { public class RadioPlayer implements Device {
private int x;
public RadioPlayer() { public RadioPlayer() {
super(); super();
savedPlaylist.add("YouFM"); savedPlaylist.add("YouFM");
@ -17,13 +16,13 @@ public class RadioPlayer implements Device {
playedStation = savedPlaylist.get(0); 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(); LocalDateTime now = LocalDateTime.now();
int hour = now.getHour(); int hour = now.getHour();
int Lautstaerke = 0;
int volume = 0;
int savedVolume; int savedVolume;
String playedStation = "";
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];
@ -61,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"}; 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) { public void changeRegion(String region) {
@ -96,21 +95,21 @@ public class RadioPlayer implements Device {
@Override @Override
public void louder() { public void louder() {
if (Lautstaerke < 100) {
Lautstaerke += 1;
} else Lautstaerke = 100;
if (volume < 100) {
volume += 1;
} else volume = 100;
} }
@Override @Override
public void quieter() { public void quieter() {
if (Lautstaerke > 0) {
Lautstaerke -= 1;
} else Lautstaerke = 0;
if (volume > 0) {
volume -= 1;
} else volume = 0;
} }
@Override @Override
public int getVolume() { public int getVolume() {
return Lautstaerke;
return volume;
} }
@Override @Override
@ -149,12 +148,22 @@ public class RadioPlayer implements Device {
@Override @Override
public String getInfoText() { public String getInfoText() {
return null;
if (showStationInfo().equals("")) return buildInfoText();
return (buildInfoText() + "\n Now playing: " + showStationInfo());
}
private String buildInfoText() {
String infoText = playedStation;
if (regionPlaylist.contains(playedStation))
return ("Regional playlist: " + (regionPlaylist.indexOf(playedStation) + 1) + infoText);
else return ("Saved playlist: " + (savedPlaylist.indexOf(playedStation) + 1) + infoText);
} }
@Override @Override
public String[] getOptions() { public String[] getOptions() {
return new String[0];
Method[] methods = this.getClass().getDeclaredMethods();
return Arrays.stream(methods).map(Method::getName).toArray(String[]::new);
} }
@Override @Override
@ -195,17 +204,16 @@ public class RadioPlayer implements Device {
@Override @Override
public String mute() { public String mute() {
savedVolume = getVolume(); savedVolume = getVolume();
setLautstaerke(0);
setVolume(0);
return "RadioPlayer is muted now"; return "RadioPlayer is muted now";
} }
@Override @Override
public String unmute() { public String unmute() {
setLautstaerke(savedVolume);
setVolume(savedVolume);
return ("RadioPlayer is unmuted Volume is set to " + getVolume()); return ("RadioPlayer is unmuted Volume is set to " + getVolume());
} }
@Override @Override
public String play() { public String play() {
if (regionPlaylist.contains(playedStation)) if (regionPlaylist.contains(playedStation))
@ -225,8 +233,6 @@ public class RadioPlayer implements Device {
default: default:
return ""; return "";
} }
} }
public String saveStation() { public String saveStation() {
@ -236,7 +242,6 @@ public class RadioPlayer implements Device {
return "Station " + playedStation + " is saved in your Station list"; return "Station " + playedStation + " is saved in your Station list";
} }
public String deleteStation() { public String deleteStation() {
String station = playedStation; String station = playedStation;
if ((savedPlaylist.size()) > 1) { if ((savedPlaylist.size()) > 1) {

66
src/test/java/device/cdPlayer/CDPlayerTest.java

@ -404,7 +404,7 @@ class CDPlayerTest {
if(cases.equals("Case3")) { if(cases.equals("Case3")) {
_cdPlayer.changePlaySource(); _cdPlayer.changePlaySource();
_cdPlayer.loadCDWechseler(cd,0); _cdPlayer.loadCDWechseler(cd,0);
CD firstCD=_cdPlayer.getCdWechseler().getCDList()[0];
CD firstCD=_cdPlayer.getCdWechseler().getCDList().get(0);
assertThat(firstCD).describedAs(testName).isNotEqualTo(null); assertThat(firstCD).describedAs(testName).isNotEqualTo(null);
} }
if(cases.equals("Case4")) { if(cases.equals("Case4")) {
@ -428,5 +428,69 @@ class CDPlayerTest {
); );
} }
@ParameterizedTest
@MethodSource("changeToNextCDData")
void changeToNextCDTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception) {
if(cases.equals("Case1")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.changeToNextCD());
assertEquals(ChangeCDOnlyOnCDWechselerException.class, newException.getClass());
}
if(cases.equals("Case2")) {
CD actualCD=_cdPlayer.getCD();
_cdPlayer.changeToNextCD();
CD nextCD=_cdPlayer.getCD();
assertThat(nextCD).describedAs(testName).isNotEqualTo(null);
}
if(cases.equals("Case3")) {
CD actualCD=_cdPlayer.getCD();
_cdPlayer.changeToNextCD();
CD nextCD=_cdPlayer.getCD();
assertThat(nextCD.getId()==actualCD.getId()).describedAs(testName).isNotEqualTo(true);
}
if(cases.equals("Case4")) {
CD actualCdBefore=_cdPlayer.getCD();
for (int i = 0; i <3 ; i++) {
_cdPlayer.changeToNextCD();
}
CD actualCdAfter=_cdPlayer.getCD();
assertThat(actualCdBefore.getId()==actualCdAfter.getId()).describedAs(testName).isEqualTo(true);
}
}
static Stream<Arguments> changeToNextCDData () {
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"};
CD audioCD1=new CD("Audio","PopMusic",audioPlayList,"XAc20044");
CD audioCD2=new CD("Audio","RockMusic",audioPlayList,"BLXPP78");
CD audioCD3=new CD("Audio","SalsaMusic",audioPlayList,"KKRP118");
CDPlayer cdPlayer1 = new CDPlayer();
CDPlayer cdPlayer2 = new CDPlayer();
cdPlayer2.changePlaySource();
cdPlayer2.loadCDWechseler(audioCD1,0);
cdPlayer2.loadCDWechseler(audioCD2,1);
cdPlayer2.loadCDWechseler(audioCD3,2);
CDPlayer cdPlayer3 = new CDPlayer();
cdPlayer3.changePlaySource();
cdPlayer3.loadCDWechseler(audioCD1,0);
cdPlayer3.loadCDWechseler(audioCD2,1);
cdPlayer3.loadCDWechseler(audioCD3,2);
CDPlayer cdPlayer4 = new CDPlayer();
cdPlayer4.changePlaySource();
cdPlayer4.loadCDWechseler(audioCD1,0);
cdPlayer4.loadCDWechseler(audioCD2,1);
cdPlayer4.loadCDWechseler(audioCD3,2);
return Stream.of(
Arguments.of("[changeToNextCD() by CDWechselerNotSelected ] => shouldThrowAnException", "Case1", cdPlayer1,new ChangeCDOnlyOnCDWechselerException()),
Arguments.of("[changeToNextCD() checking the effect ] => loadedCDShouldNotReturnNull", "Case2", cdPlayer2,null),
Arguments.of("[changeToNextCD() checking the effect 2 ] => loadedCDShouldNotHaveTheSameIdAsPrev", "Case3", cdPlayer3,null),
Arguments.of("[3x changeToNextCD() changing from last to first CD] => FirstCDShouldBeTaken", "Case4", cdPlayer4,null)
);
}
} }

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

@ -1,18 +1,22 @@
package device.radioPlayer; package device.radioPlayer;
import device.Device;
import org.assertj.core.util.Strings;
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;
import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.MethodSource;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat; 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) {
@ -25,13 +29,13 @@ class RadioPlayerTest {
RadioPlayer rp2 = new RadioPlayer(); RadioPlayer rp2 = new RadioPlayer();
RadioPlayer rp3 = new RadioPlayer(); RadioPlayer rp3 = new RadioPlayer();
RadioPlayer rp4 = new RadioPlayer(); RadioPlayer rp4 = new RadioPlayer();
rp1.setLautstaerke(0);
rp1.setVolume(0);
rp1.louder(); rp1.louder();
rp2.setLautstaerke(100);
rp2.setVolume(100);
rp2.louder(); rp2.louder();
rp3.setLautstaerke(1);
rp3.setVolume(1);
rp3.quieter(); rp3.quieter();
rp4.setLautstaerke(0);
rp4.setVolume(0);
rp4.quieter(); rp4.quieter();
return Stream.of( return Stream.of(
Arguments.of("Test for one step louder", rp1, 1), Arguments.of("Test for one step louder", rp1, 1),
@ -55,7 +59,6 @@ class RadioPlayerTest {
rp1.changeRegion("BY"); rp1.changeRegion("BY");
rp2.changeRegion("HE"); rp2.changeRegion("HE");
rp3.changeRegion("BW"); rp3.changeRegion("BW");
return Stream.of( return Stream.of(
Arguments.of("Test change Region to Bayern", rp1, "Antenne Bayern"), Arguments.of("Test change Region to Bayern", rp1, "Antenne Bayern"),
Arguments.of("Test change Region to Hessen", rp2, "Hit Radio FFH"), Arguments.of("Test change Region to Hessen", rp2, "Hit Radio FFH"),
@ -63,7 +66,6 @@ class RadioPlayerTest {
); );
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("prevNextOptions") @MethodSource("prevNextOptions")
void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) { void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) {
@ -89,7 +91,6 @@ class RadioPlayerTest {
rp6.changeRegion("BY"); rp6.changeRegion("BY");
rp6.saveStation(); rp6.saveStation();
rp6.next(); rp6.next();
return Stream.of( return Stream.of(
Arguments.of("Next Station Test for saved Stations", rp1, "Teddy"), Arguments.of("Next Station Test for saved Stations", rp1, "Teddy"),
Arguments.of("Prev Station Test for saved Stations", rp2, "YouFM"), Arguments.of("Prev Station Test for saved Stations", rp2, "YouFM"),
@ -100,40 +101,38 @@ class RadioPlayerTest {
); );
} }
@Test
void YouFMInfoByTimeTest() {
RadioPlayer rp = new RadioPlayer();
assertThat(rp.getYouFMInfoByTime(8)).describedAs("YouFM info by Time at 8.00").isEqualTo("YOUFM Good Morning Show");
}
@Test
void YouFMInfoByTime2Test() {
RadioPlayer rp = new RadioPlayer();
assertThat(rp.getYouFMInfoByTime(3)).describedAs("YouFM info by Time at 3.00").isEqualTo("YOUFM Junge Nacht der ARD");
}
@Test
void AntenneBYInfoByTimeTest() {
RadioPlayer rp = new RadioPlayer();
assertThat(rp.getAntenneBYInfoByTime(8)).describedAs("AntenneBY info by Time at 8.00").isEqualTo("ANTENNE BAYERN Guten Morgen Bayern");
}
@Test
void AntenneBYInfoByTime2Test() {
RadioPlayer rp = new RadioPlayer();
assertThat(rp.getAntenneBYInfoByTime(3)).describedAs("AntenneBY info by Time at 3.00").isEqualTo("ANTENNE BAYERN Hit-Nacht");
}
@Test
void BR3InfoByTimeTest() {
RadioPlayer rp = new RadioPlayer();
assertThat(rp.getBR3InfoByTime(5)).describedAs("BR3 info by Time at 5.00").isEqualTo("Sebastian Winkler und die Frühaufdreher");
@ParameterizedTest
@MethodSource("infoByTimeOptions")
void infoByTimeInfo(String testName, RadioPlayer testRp, String testTyp, int hour, String expectedResult) {
if(testTyp.equals("YouFM")) assertThat(testRp.getYouFMInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult);
if(testTyp.equals("BR3")) assertThat(testRp.getBR3InfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult);
if(testTyp.equals("AntenneBY")) assertThat(testRp.getAntenneBYInfoByTime(hour)).describedAs(testName).isEqualTo(expectedResult);
} }
@Test
void BR3InfoByTime2Test() {
static Stream<Arguments> infoByTimeOptions() {
RadioPlayer rp = new RadioPlayer(); RadioPlayer rp = new RadioPlayer();
assertThat(rp.getBR3InfoByTime(21)).describedAs("BR3 info by Time at 21.00").isEqualTo("Matuschke - der etwas andere Abend");
return Stream.of(
Arguments.of("Station info YouFm at 5:00 am", rp, "YouFM", 5, rp.YouFMInfo[0]),
Arguments.of("Station info YouFm at 10:00 am", rp, "YouFM", 10, rp.YouFMInfo[1]),
Arguments.of("Station info YouFm at 2:00 pm", rp, "YouFM", 14, rp.YouFMInfo[2]),
Arguments.of("Station info YouFm at 6:00 pm", rp, "YouFM", 18, rp.YouFMInfo[3]),
Arguments.of("Station info YouFm at 8:00 pm", rp, "YouFM", 20, rp.YouFMInfo[4]),
Arguments.of("Station info YouFm at 10:00 pm", rp, "YouFM", 22, rp.YouFMInfo[5]),
Arguments.of("Station info YouFm at 3:00 am", rp, "YouFM", 3, rp.YouFMInfo[6]),
Arguments.of("Station info BR3 at 5:00 am", rp, "BR3", 5, rp.BR3Info[0]),
Arguments.of("Station info BR3 at 9:00 am", rp, "BR3", 9, rp.BR3Info[1]),
Arguments.of("Station info BR3 at 12:00 am", rp, "BR3", 12, rp.BR3Info[2]),
Arguments.of("Station info BR3 at 1:00 pm", rp, "BR3", 13, rp.BR3Info[3]),
Arguments.of("Station info BR3 at 4:00 pm", rp, "BR3", 16, rp.BR3Info[4]),
Arguments.of("Station info BR3 at 7:00 pm", rp, "BR3", 19, rp.BR3Info[5]),
Arguments.of("Station info BR3 at 9:00 pm", rp, "BR3", 21, rp.BR3Info[6]),
Arguments.of("Station info BR3 at 3:00 am", rp, "BR3", 3, rp.BR3Info[7]),
Arguments.of("Station info AntenneBY at 5:00 am", rp, "AntenneBY", 5, rp.AntenneBYInfo[0]),
Arguments.of("Station info AntenneBY at 9:00 am", rp, "AntenneBY", 9, rp.AntenneBYInfo[1]),
Arguments.of("Station info AntenneBY at 12:00 am", rp, "AntenneBY", 12, rp.AntenneBYInfo[2]),
Arguments.of("Station info AntenneBY at 3:00 pm", rp, "AntenneBY", 15, rp.AntenneBYInfo[3]),
Arguments.of("Station info AntenneBY at 3:00 am", rp, "AntenneBY", 3, rp.AntenneBYInfo[4])
);
} }
@ParameterizedTest @ParameterizedTest
@ -153,7 +152,6 @@ class RadioPlayerTest {
rp3.next(); rp3.next();
RadioPlayer rp4 = new RadioPlayer(); RadioPlayer rp4 = new RadioPlayer();
rp4.next(); rp4.next();
return Stream.of( return Stream.of(
Arguments.of("Show Station Info for first saved Radio", rp1, rp1.getYouFMInfoByTime(rp1.hour)), 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)), Arguments.of("Show Station Info for regional Station", rp2, rp2.getAntenneBYInfoByTime(rp2.hour)),
@ -162,17 +160,6 @@ class RadioPlayerTest {
); );
} }
/*
@Test
void getInfoText() {
}
@Test
void getOptions() {
}
*/
@ParameterizedTest @ParameterizedTest
@MethodSource("chooseItemOptions") @MethodSource("chooseItemOptions")
void testChooseItem(String testName, RadioPlayer testRp, String expectedResult) { void testChooseItem(String testName, RadioPlayer testRp, String expectedResult) {
@ -196,7 +183,6 @@ class RadioPlayerTest {
RadioPlayer rp5 = new RadioPlayer(); RadioPlayer rp5 = new RadioPlayer();
rp5.changeRegion("BY"); rp5.changeRegion("BY");
rp5.chooseItem(-2); rp5.chooseItem(-2);
return Stream.of( 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 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"), 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"),
@ -244,7 +230,6 @@ class RadioPlayerTest {
rp2.saveStation(); rp2.saveStation();
rp3.changeRegion("BY"); rp3.changeRegion("BY");
rp3.saveStation(); rp3.saveStation();
return Stream.of( return Stream.of(
Arguments.of("Test for saving station in saved playlist", rp1, "normal", "Antenne Bayern"), 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"), Arguments.of("Test for not saving station which is already in saved playlist", rp2, "normal", "MegaHits"),
@ -269,7 +254,6 @@ class RadioPlayerTest {
rp1.deleteStation(); rp1.deleteStation();
rp1.deleteStation(); rp1.deleteStation();
rp1.deleteStation(); rp1.deleteStation();
return Stream.of( return Stream.of(
Arguments.of("Test for delete station in saved playlist", rp, "delete", false), 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) Arguments.of("Test for not delete station in saved playlist if this is the last station", rp1, "noDelete", true)
@ -289,7 +273,6 @@ class RadioPlayerTest {
RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp1 = new RadioPlayer();
rp1.changeRegion("BY"); rp1.changeRegion("BY");
rp1.changeToSavedPlaylist(); rp1.changeToSavedPlaylist();
return Stream.of( 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 you already in saved playlist", rp, "YouFM"),
Arguments.of("Test for change to saved playlist when in regional playlist", rp1, "YouFM") Arguments.of("Test for change to saved playlist when in regional playlist", rp1, "YouFM")
@ -313,7 +296,6 @@ class RadioPlayerTest {
RadioPlayer rp2 = new RadioPlayer(); RadioPlayer rp2 = new RadioPlayer();
rp2.next(); rp2.next();
rp2.changeOrderInSavedPlaylist(-1); rp2.changeOrderInSavedPlaylist(-1);
return Stream.of( 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 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"), 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"),
@ -336,7 +318,6 @@ class RadioPlayerTest {
RadioPlayer rp = new RadioPlayer(); RadioPlayer rp = new RadioPlayer();
RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp1 = new RadioPlayer();
rp1.changeRegion("BY"); rp1.changeRegion("BY");
return Stream.of( return Stream.of(
Arguments.of("Test for return saved playlist", rp, "saved", rp.savedPlaylist.toArray(new String[0])), 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])) Arguments.of("Test for return regional playlist", rp1, "region", rp1.regionPlaylist.toArray(new String[0]))
@ -354,23 +335,90 @@ class RadioPlayerTest {
static Stream<Arguments> muteOptions() { static Stream<Arguments> muteOptions() {
RadioPlayer rp = new RadioPlayer(); RadioPlayer rp = new RadioPlayer();
rp.setLautstaerke(25);
rp.setVolume(25);
rp.mute(); rp.mute();
RadioPlayer rp1 = new RadioPlayer(); RadioPlayer rp1 = new RadioPlayer();
rp1.setLautstaerke(30);
rp1.setVolume(30);
rp1.mute(); rp1.mute();
return Stream.of( 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 actually 0", "actual", rp, 0),
Arguments.of("Test for mute RadioPlayer if volume is saved before muting", "saved", rp1, 30) Arguments.of("Test for mute RadioPlayer if volume is saved before muting", "saved", rp1, 30)
); );
} }
@Test @Test
void TestUnmute() {
void testUnmute() {
RadioPlayer rp = new RadioPlayer(); RadioPlayer rp = new RadioPlayer();
rp.setLautstaerke(40);
rp.setVolume(40);
rp.mute(); rp.mute();
rp.unmute(); rp.unmute();
assertThat(rp.getVolume()).describedAs("Test if unmute is setting the saved volume").isEqualTo(rp.savedVolume); assertThat(rp.getVolume()).describedAs("Test if unmute is setting the saved volume").isEqualTo(rp.savedVolume);
} }
@ParameterizedTest
@MethodSource("getInfoTextOptions")
void testGetInfoText(String testName, String testTyp, RadioPlayer testRp, boolean expectedResult) {
Boolean bool;
if (testTyp.equals("null")) bool = Strings.isNullOrEmpty(testRp.getInfoText());
else if (testTyp.contains("station")) bool = testRp.getInfoText().contains(testRp.playedStation);
else if (testTyp.contains("region")) bool = testRp.getInfoText().contains("Regional playlist");
else if (testTyp.contains("saved")) bool = testRp.getInfoText().contains("Saved playlist");
else if (testTyp.contains("savedNum"))
bool = testRp.getInfoText().contains(("0") + testRp.savedPlaylist.indexOf(testRp.playedStation) + 1);
else if (testTyp.contains("regionNum"))
bool = testRp.getInfoText().contains(("0") + testRp.regionPlaylist.indexOf(testRp.playedStation) + 1);
else if (testTyp.contains("stationInfo")) bool = testRp.getInfoText().contains("Now playing");
else bool = testRp.getInfoText().contains("Now playing");
assertThat(bool).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> getInfoTextOptions() {
RadioPlayer rp = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
rp2.changeRegion("BY");
RadioPlayer rp4 = new RadioPlayer();
rp4.next();
RadioPlayer rp5 = new RadioPlayer();
rp5.changeRegion("HE");
rp5.next();
RadioPlayer rp6 = new RadioPlayer();
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", 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", 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),
Arguments.of("Test for getInfoText not contains station info if station not has one", "noStationInfo", rp7, false)
);
}
@ParameterizedTest
@MethodSource("getOptionsOptions")
void testGetOptions(String testName, String testTyp, RadioPlayer testRp) {
if (testTyp.equals("notNull")) assertThat(testRp.getOptions()).describedAs(testName).isNotEqualTo(null);
if (testTyp.equals("arrayLengthGreater0"))
assertThat(testRp.getOptions().length).describedAs(testName).isNotEqualTo(0);
else {
Method[] interfaceMethods = Device.class.getDeclaredMethods();
List<String> deviceMethods = new ArrayList<>(Arrays.asList(testRp.getOptions()));
for (Method interfaceMethod : interfaceMethods) {
assertThat(deviceMethods.contains(interfaceMethod.getName())).describedAs(testName).isEqualTo(true);
}
}
}
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),
Arguments.of("Test if all methods declared in interface device are available", "device", rp)
);
}
} }
Loading…
Cancel
Save