22 Commits

Author SHA1 Message Date
JPANZO dff29bea43 Merge branch 'master' into feature-pr-jacksonsNewFeature 3 years ago
JPANZO f51c6d783c Method getInfoText of CDPlayer tested on MessageShouldContainInfoAboutDevice. 3 years ago
JPANZO c5c7ea8c95 Method getInfoText of CDPlayer tested on MessageShouldContainInfoAboutAlbum. 3 years ago
Jenkins 9830ace3fd Merge commit 'de82f475dd2f7f7453406f886519043de7ea7998' into HEAD 3 years ago
Jan Ortner de82f475dd added test case for unmute() & and added productive code for RadioPlayer 3 years ago
JPANZO 1f11a8366c Method getInfoText of CDPlayer tested on MessageShouldContainInfoOfActualPlayTrack. 3 years ago
Jan Ortner 8b23b50442 added second test case for mute() & and added productive code for RadioPlayer 3 years ago
Jan Ortner f8bcf0c62b added first test case for mute() & and added productive code for RadioPlayer 3 years ago
Jenkins 75f23114b2 Merge commit 'b7b79badda3d9c14f0fa7360b8256ec51fe3cde0' into HEAD 3 years ago
Jan Ortner b7b79badda added second test case for getItemList() & and added productive code for RadioPlayer 3 years ago
JPANZO d606a41ef7 Method getInfoText of CDPlayer tested on ExceptionShouldReturnAMessage. 3 years ago
Jan Ortner d61ea26007 added first test case for getItemList() & and added productive code for RadioPlayer 3 years ago
JPANZO 007aa5d415 Method getInfoText of CDPlayer tested on shouldThrowReturnValueNullException. 3 years ago
Jenkins 2ad8951143 Merge commit 'd6dbffa4855f3d4ba2e98c5523719806b312c8c3' into HEAD 3 years ago
Jan Ortner d6dbffa485 Merge branch 'master' into feature-pr-RadioPlayer-chooseItem 3 years ago
Jan Ortner 419699e4bc added six test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
Jan Ortner acfc2fef2b added fifth test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
Jan Ortner a5c936d270 added fourth test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
Jan Ortner cd09cb8775 added third test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
Jan Ortner 820d148f30 added second test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
Jenkins ec66817f43 Merge commit '0e9662561a8188138ec8e83fbac713782c5d980b' into HEAD 3 years ago
Jan Ortner e5b9f46ce7 added first test case for chooseItem() & and added productive code for RadioPlayer 3 years ago
  1. 9
      src/main/java/device/cdPlayer/CD.java
  2. 14
      src/main/java/device/cdPlayer/CDPlayer.java
  3. 9
      src/main/java/device/cdPlayer/exceptions/ReturnValueNullException.java
  4. 54
      src/main/java/device/radioPlayer/RadioPlayer.java
  5. 55
      src/test/java/device/cdPlayer/CDPlayerTest.java
  6. 90
      src/test/java/device/radioPlayer/RadioPlayerTest.java

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

@ -2,6 +2,7 @@ package device.cdPlayer;
public class CD { public class CD {
private String format; private String format;
private String albumName;
private String[] playList; private String[] playList;
public CD() {} public CD() {}
@ -30,4 +31,12 @@ public class CD {
public void setPlayList(String[] playList) { public void setPlayList(String[] playList) {
this.playList = playList; this.playList = playList;
} }
public String getAlbumName() {
return albumName;
}
public void setAlbumName(String albumName) {
this.albumName = albumName;
}
} }

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

@ -14,6 +14,7 @@ public class CDPlayer implements Device {
private int CdDriveContent=0; private int CdDriveContent=0;
private int CdFlap=0; private int CdFlap=0;
private int volume = 0; private int volume = 0;
private String infoText=null;
private List<String> supportedFormats = new ArrayList<String>(Arrays.asList(new String[] {"Audio","MP3","WMA","AAC"})); private List<String> supportedFormats = new ArrayList<String>(Arrays.asList(new String[] {"Audio","MP3","WMA","AAC"}));
private String actualPlayTrack=""; private String actualPlayTrack="";
@ -66,7 +67,10 @@ public class CDPlayer implements Device {
@Override @Override
public String getInfoText() { public String getInfoText() {
return null;
if(infoText==null){
throw new ReturnValueNullException();
}
return infoText;
} }
@Override @Override
@ -157,4 +161,12 @@ public class CDPlayer implements Device {
return actualPlayTrack; return actualPlayTrack;
} }
public void setInfoText() {
this.infoText=this.getClass().getSimpleName()+": Item->"+actualPlayTrack+" from Album->"+this.loadedCD.getAlbumName()+" running.";
}
public CD getCD() {
return this.loadedCD;
}
} }

9
src/main/java/device/cdPlayer/exceptions/ReturnValueNullException.java

@ -0,0 +1,9 @@
package device.cdPlayer.exceptions;
public class ReturnValueNullException extends RuntimeException{
public ReturnValueNullException() {
super("Method should not return a Null-Value.");
}
}

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

@ -22,6 +22,7 @@ public class RadioPlayer implements Device {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
int hour = now.getHour(); int hour = now.getHour();
int Lautstaerke = 0; int Lautstaerke = 0;
int savedVolume;
String playedStation = ""; String playedStation = "";
public String getYouFMInfoByTime(int x) { public String getYouFMInfoByTime(int x) {
@ -158,22 +159,50 @@ public class RadioPlayer implements Device {
@Override @Override
public String chooseItem(int itemNr) { public String chooseItem(int itemNr) {
return null;
if (regionPlaylist.contains(playedStation)) {
if (itemNr > regionPlaylist.size()) {
playedStation = regionPlaylist.get(regionPlaylist.size() - 1);
return ("Radio is playing station: 0" + regionPlaylist.size() + " " + this.playedStation + " from regional playlist");
} else if (itemNr < 1) {
playedStation = regionPlaylist.get(0);
return ("Radio is playing station: 01 " + this.playedStation + " from regional playlist");
} else {
playedStation = regionPlaylist.get(itemNr - 1);
return ("Radio is playing station: 0" + (regionPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from regional playlist");
}
} else {
if (itemNr > savedPlaylist.size()) {
playedStation = savedPlaylist.get(savedPlaylist.size() - 1);
return ("Radio is playing station: 0" + savedPlaylist.size() + " " + this.playedStation + " from saved playlist");
} else if (itemNr < 1) {
playedStation = savedPlaylist.get(0);
return ("Radio is playing station: 01 " + this.playedStation + " from saved playlist");
} else {
playedStation = savedPlaylist.get(itemNr - 1);
return ("Radio is playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist");
}
}
} }
@Override @Override
public String[] getItemList() { public String[] getItemList() {
return null;
if (regionPlaylist.contains(playedStation))
return regionPlaylist.toArray(new String[0]);
else
return savedPlaylist.toArray(new String[0]);
} }
@Override @Override
public String mute() { public String mute() {
return null;
savedVolume = getVolume();
setLautstaerke(0);
return "RadioPlayer is muted now";
} }
@Override @Override
public String unmute() { public String unmute() {
return null;
setLautstaerke(savedVolume);
return ("RadioPlayer is unmuted Volume is set to " + getVolume());
} }
@ -218,7 +247,7 @@ public class RadioPlayer implements Device {
} }
public String changeToSavedPlaylist() { public String changeToSavedPlaylist() {
if(regionPlaylist.contains(playedStation)) {
if (regionPlaylist.contains(playedStation)) {
playedStation = savedPlaylist.get(0); playedStation = savedPlaylist.get(0);
regionPlaylist.clear(); regionPlaylist.clear();
return "Playlist switched now playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist"; return "Playlist switched now playing station: 0" + (savedPlaylist.indexOf(playedStation) + 1) + " " + this.playedStation + " from saved playlist";
@ -228,16 +257,15 @@ public class RadioPlayer implements Device {
public String changeOrderInSavedPlaylist(int nr) { public String changeOrderInSavedPlaylist(int nr) {
String station = playedStation; String station = playedStation;
if((nr-1) > savedPlaylist.size()) {
if ((nr - 1) > savedPlaylist.size()) {
savedPlaylist.remove(playedStation); savedPlaylist.remove(playedStation);
savedPlaylist.add(savedPlaylist.size(),station);
return"Station " + playedStation + " is now on place 0" + (savedPlaylist.size()+1) + "in saved playlist";
}else if(nr < 0) {
savedPlaylist.add(savedPlaylist.size(), station);
return "Station " + playedStation + " is now on place 0" + (savedPlaylist.size() + 1) + "in saved playlist";
} else if (nr < 0) {
savedPlaylist.remove(playedStation); savedPlaylist.remove(playedStation);
savedPlaylist.add(0,station);
return"Station " + playedStation + " is now on place 01 in saved playlist";
}
else {
savedPlaylist.add(0, station);
return "Station " + playedStation + " is now on place 01 in saved playlist";
} else {
savedPlaylist.remove(playedStation); savedPlaylist.remove(playedStation);
savedPlaylist.add(nr - 1, station); savedPlaylist.add(nr - 1, station);
return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist"; return "Station " + playedStation + " is now on place 0" + nr + "in saved playlist";

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

@ -7,6 +7,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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 org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -17,6 +18,8 @@ import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class CDPlayerTest { class CDPlayerTest {
@ -272,4 +275,56 @@ class CDPlayerTest {
assertThat(volumeIstInValueRange).isEqualTo(true); assertThat(volumeIstInValueRange).isEqualTo(true);
} }
@ParameterizedTest
@MethodSource("getInfoTestData")
void getInfoTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception , String expectedResult){
if(cases.equals("Case1")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.getInfoText());
assertEquals(ReturnValueNullException.class, newException.getClass());
}
if(cases.equals("Case2")) {
Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.getInfoText());
assertThat(newException.getMessage()).describedAs(testName).isEqualTo(expectedResult);
}
if(cases.equals("Case3")) {
String[] album= _cdPlayer.getItemList();
boolean containsInfoOfActualPlayTrack=false;
for (int i = 0; i < album.length; i++) {
if(_cdPlayer.getInfoText().contains(expectedResult))
containsInfoOfActualPlayTrack=true;
}
assertThat(containsInfoOfActualPlayTrack).describedAs(testName).isEqualTo(true);
}
if(cases.equals("Case4")) {
String albumName= _cdPlayer.getCD().getAlbumName();
assertThat(_cdPlayer.getInfoText().contains(albumName)).describedAs(testName).isEqualTo(true);
}
if(cases.equals("Case5")) {
assertThat(_cdPlayer.getInfoText().contains("CDPlayer")).describedAs(testName).isEqualTo(true);
}
}
static Stream<Arguments> getInfoTestData () {
CDPlayer cdPlayer1 = new CDPlayer();
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"};
//some CDs
CD audioCD1=new CD("Audio",audioPlayList);
audioCD1.setAlbumName("Love Songs");
CDPlayer cdPlayer2 = new CDPlayer();
cdPlayer2.tapOnCdFlap();
cdPlayer2.setCD(audioCD1);
cdPlayer2.tapOnCdFlap();
cdPlayer2.setInfoText();
return Stream.of(
Arguments.of("[getInfoText() by infoText=null ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),""),
Arguments.of("[getInfoText() by infoText=null ] => ExceptionShouldReturnAMessage","Case2",cdPlayer1,new ReturnValueNullException(),"Method should not return a Null-Value."),
Arguments.of("[getInfoText() by infoText=Message ] => MessageShouldContainInfoOfActualPlayTrack","Case3",cdPlayer2,null,""),
Arguments.of("[getInfoText() by infoText=Message ] => MessageShouldContainInfoAboutAlbum","Case4",cdPlayer2,null,""),
Arguments.of("[getInfoText() by infoText=Message ] => MessageShouldContainInfoAboutDevice","Case5",cdPlayer2,null,"")
);
}
} }

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

@ -171,11 +171,42 @@ class RadioPlayerTest {
@Test @Test
void getOptions() { void getOptions() {
} }
*/
@Test
void chooseOption() {
@ParameterizedTest
@MethodSource("chooseItemOptions")
void testChooseItem(String testName, RadioPlayer testRp, String expectedResult) {
String playedStation = testRp.playedStation;
assertThat(playedStation).describedAs(testName).isEqualTo(expectedResult);
} }
*/
static Stream<Arguments> chooseItemOptions() {
RadioPlayer rp = new RadioPlayer();
rp.chooseItem(2);
RadioPlayer rp1 = new RadioPlayer();
rp1.chooseItem(5);
RadioPlayer rp2 = new RadioPlayer();
rp2.chooseItem(-1);
RadioPlayer rp3 = new RadioPlayer();
rp3.changeRegion("BY");
rp3.chooseItem(2);
RadioPlayer rp4 = new RadioPlayer();
rp4.changeRegion("BY");
rp4.chooseItem(5);
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"),
Arguments.of("Test select station in saved playlist to play with nr is lower than 0. First station in playlist gets played", rp2, "YouFM"),
Arguments.of("Test select station in regional playlist to play with nr isn`t bigger than playlist size", rp3, "Bayern 1"),
Arguments.of("Test select station in regional playlist to play with nr is bigger than playlist size. Last station in playlist gets played", rp4, "Hit Radio N1"),
Arguments.of("Test select station in regional playlist to play with nr is lower than 0. Last station in playlist gets played", rp5, "Antenne Bayern")
);
}
@ParameterizedTest @ParameterizedTest
@MethodSource("testPlayOptions") @MethodSource("testPlayOptions")
void testPlay(String testName, RadioPlayer testRp, String expectedResult) { void testPlay(String testName, RadioPlayer testRp, String expectedResult) {
@ -289,4 +320,57 @@ class RadioPlayerTest {
Arguments.of("Test for change order in saved playlist with nr is than smaller than 0 at front of playlist", rp2, 0, "Teddy") Arguments.of("Test for change order in saved playlist with nr is than smaller than 0 at front of playlist", rp2, 0, "Teddy")
); );
} }
@ParameterizedTest
@MethodSource("getItemListOptions")
void testGetItemList(String testName, RadioPlayer testRp, String testTyp, String[] expectedResult) {
if (testTyp.equals("region")) {
testRp.changeRegion("BY");
}
String[] playList = testRp.getItemList();
assertThat(playList).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> getItemListOptions() {
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]))
);
}
@ParameterizedTest
@MethodSource("muteOptions")
void testMute(String testName, String testTyp, RadioPlayer testRp, int expectedResult) {
int volume;
if (testTyp.equals("actual")) volume = testRp.getVolume();
else volume = testRp.savedVolume;
assertThat(volume).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> muteOptions() {
RadioPlayer rp = new RadioPlayer();
rp.setLautstaerke(25);
rp.mute();
RadioPlayer rp1 = new RadioPlayer();
rp1.setLautstaerke(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)
);
}
@Test
void TestUnmute() {
RadioPlayer rp = new RadioPlayer();
rp.setLautstaerke(40);
rp.mute();
rp.unmute();
assertThat(rp.getVolume()).describedAs("Test if unmute is setting the saved volume").isEqualTo(rp.savedVolume);
}
} }
Loading…
Cancel
Save