Browse Source

Method getInfoText of CDPlayer tested on shouldThrowReturnValueNullException.

feature-pr-RadioPlayer-getOptions
JPANZO 3 years ago
parent
commit
007aa5d415
  1. 9
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 9
      src/main/java/device/cdPlayer/exceptions/ReturnValueNullException.java
  3. 18
      src/test/java/device/cdPlayer/CDPlayerTest.java

9
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,7 @@ public class CDPlayer implements Device {
return actualPlayTrack;
}
public void setInfoText(String intoText) {
this.infoText=intoText;
}
}

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.");
}
}

18
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,19 @@ class CDPlayerTest {
assertThat(volumeIstInValueRange).isEqualTo(true);
}
@ParameterizedTest
@MethodSource("getInfoTestData")
void getInfoTest(String testName, CDPlayer _cdPlayer,Exception exception , String expectedResult){
Exception newException=assertThrows(exception.getClass(),()->_cdPlayer.getInfoText());
assertEquals(ReturnValueNullException.class, newException.getClass());
}
static Stream<Arguments> getInfoTestData () {
CDPlayer cdPlayer1 = new CDPlayer();
return Stream.of(
Arguments.of("[getInfoText() by infoText=null ] => shouldThrowReturnValueNullException", cdPlayer1,new ReturnValueNullException(),"")
);
}
}
Loading…
Cancel
Save