From 2b0475f00c827b0ee6d0e3495c0a49f8a1bd1e4e Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 18 Feb 2022 00:30:46 +0100 Subject: [PATCH] UsbPlayerTest.chooseItemTest First Case --- src/main/java/device/usbPlayer/UsbPlayer.java | 29 +++++++++++-------- .../java/device/usbPlayer/UsbPlayerTest.java | 17 +++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 034c19d..9bdf190 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -12,7 +12,7 @@ public class UsbPlayer implements Device { private Boolean isConnected; private Boolean isDefect; int Lautstaerke = 0; - int soundWas =-1; + int soundWas = -1; public USB_Stick USBDrive = new USB_Stick(); @@ -104,8 +104,8 @@ public class UsbPlayer implements Device { //**********search method************* @Override public void quieter() { - if(this.soundWas == -1){ - if (Lautstaerke > 0 ) { + if (this.soundWas == -1) { + if (Lautstaerke > 0) { Lautstaerke -= 1; } else { Lautstaerke = 0; @@ -116,7 +116,7 @@ public class UsbPlayer implements Device { @Override public void louder() { - if(this.soundWas == -1) { + if (this.soundWas == -1) { if (Lautstaerke < 100) { Lautstaerke += 1; } else { @@ -126,7 +126,7 @@ public class UsbPlayer implements Device { } public void Louder_10() { - if(this.soundWas == -1) { + if (this.soundWas == -1) { Lautstaerke += 10; if (Lautstaerke > 100) { Lautstaerke = 100; @@ -136,7 +136,7 @@ public class UsbPlayer implements Device { } public void quieter_10() { - if(this.soundWas == -1) { + if (this.soundWas == -1) { Lautstaerke -= 10; if (Lautstaerke < 0) { Lautstaerke = 0; @@ -168,12 +168,11 @@ public class UsbPlayer implements Device { @Override public String getInfoText() { - String InfoText=""; + String InfoText = ""; if (isAllAudio()) { - InfoText="USB Player is on : "+this.getPlayTrack(); - } - else - InfoText="USB Player with no Albums"; + InfoText = "USB Player is on : " + this.getPlayTrack(); + } else + InfoText = "USB Player with no Albums"; return InfoText; } @@ -184,9 +183,15 @@ public class UsbPlayer implements Device { @Override public String chooseItem(int itemNr) { - return null; + String songName=""; + if (itemNr < this.getPlaylist().size()) { + songName= this.getPlaylist().get(itemNr ).toString(); + } + return songName; } + + @Override public String[] getItemList() { return null; diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index c22f806..e641c90 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -542,6 +542,23 @@ class UsbPlayerTest { Arguments.of("The Sound is unmuted ", up1,"unmuted","Sound level has changed","previous sound level is 0") ); + }//chooseItem + + @ParameterizedTest + @MethodSource("chooseItem") + void chooseItemTest(String testName, String inputSong, String expectedResult) { + //int volumeNum = inputPlay.getLautstaerke(); + assertThat(inputSong).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream chooseItem() { + USB_Stick USBDrive = new USB_Stick(); + //first case + UsbPlayer up1 = new UsbPlayer(USBDrive); + + return Stream.of( + Arguments.of("An Item from the Album was chosen ", up1.chooseItem(0), "Musik 01.mp3") + ); } } \ No newline at end of file