diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 57101c8..d70ffca 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -18,7 +18,7 @@ public class CDPlayer implements Device { private List supportedFormats = new ArrayList(Arrays.asList(new String[] {"Audio","MP3","WMA","AAC"})); private String actualPlayTrack=""; - private CD loadedCD; + private CD loadedCD=null; @Override public void louder() { @@ -86,6 +86,9 @@ public class CDPlayer implements Device { @Override public String chooseItem(int itemNr) { + if(this.loadedCD==null){ + throw new ReturnValueNullException(); + } return null; } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index e8d8f77..b820e8f 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -327,4 +327,17 @@ class CDPlayerTest { ); } -} \ No newline at end of file + @ParameterizedTest + @MethodSource("chooseItemTestData") + void chooseItemTest(String testName,String cases, CDPlayer _cdPlayer,Exception exception , String expectedResult) { + Exception newException = assertThrows(exception.getClass(), () -> _cdPlayer.chooseItem(1)); + assertEquals(ReturnValueNullException.class, newException.getClass()); + } + static Stream chooseItemTestData () { + CDPlayer cdPlayer1 = new CDPlayer(); + return Stream.of( + Arguments.of("[chooseItem() by notSetCD ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),"") + ); + } + + } \ No newline at end of file