Browse Source

Merge commit 'dff29bea43d8fa550cb061fe11dbc1d095eecd6d' into HEAD

feature-pr-RadioPlayer-getOptions
Jenkins 3 years ago
parent
commit
1b557c8ad3
  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. 55
      src/test/java/device/cdPlayer/CDPlayerTest.java

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

@ -2,6 +2,7 @@ package device.cdPlayer;
public class CD {
private String format;
private String albumName;
private String[] playList;
public CD() {}
@ -30,4 +31,12 @@ public class CD {
public void setPlayList(String[] 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 CdFlap=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 String actualPlayTrack="";
@ -66,7 +67,10 @@ public class CDPlayer implements Device {
@Override
public String getInfoText() {
return null;
if(infoText==null){
throw new ReturnValueNullException();
}
return infoText;
}
@Override
@ -157,4 +161,12 @@ public class CDPlayer implements Device {
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.");
}
}

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.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
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.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class CDPlayerTest {
@ -272,4 +275,56 @@ class CDPlayerTest {
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,"")
);
}
}
Loading…
Cancel
Save