diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 9bdf190..1575e64 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -184,7 +184,7 @@ public class UsbPlayer implements Device { @Override public String chooseItem(int itemNr) { String songName=""; - if (itemNr < this.getPlaylist().size()) { + if (itemNr < this.getPlaylist().size() && itemNr >= 0) { songName= this.getPlaylist().get(itemNr ).toString(); } return songName; diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index e641c90..93ac0c8 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -557,7 +557,8 @@ class UsbPlayerTest { UsbPlayer up1 = new UsbPlayer(USBDrive); return Stream.of( - Arguments.of("An Item from the Album was chosen ", up1.chooseItem(0), "Musik 01.mp3") + Arguments.of("An Item from the Album was chosen ", up1.chooseItem(0), "Musik 01.mp3"), + Arguments.of("Incorrect Nr of Item was given ", up1.chooseItem(-1), "") ); }