diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index f5f93cc..c3d0ce1 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/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 supportedFormats = new ArrayList(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; + } } diff --git a/src/main/java/device/cdPlayer/exceptions/ReturnValueNullException.java b/src/main/java/device/cdPlayer/exceptions/ReturnValueNullException.java new file mode 100644 index 0000000..15f8ca0 --- /dev/null +++ b/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."); + } + +} diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 3bcc1db..eee04af 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/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 getInfoTestData () { + + CDPlayer cdPlayer1 = new CDPlayer(); + + return Stream.of( + Arguments.of("[getInfoText() by infoText=null ] => shouldThrowReturnValueNullException", cdPlayer1,new ReturnValueNullException(),"") + ); + } + } \ No newline at end of file