From 1d5a72debbfe8d1a9b7d9df27eb3e378309e18b4 Mon Sep 17 00:00:00 2001 From: sahar Date: Mon, 7 Feb 2022 19:45:23 +0100 Subject: [PATCH 1/5] Vars and setters and getters --- src/main/java/device/usbPlayer/UsbPlayer.java | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index 87b63ab..ad187e8 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -2,9 +2,50 @@ package device.usbPlayer; import device.Device; +import java.util.ArrayList; + public class UsbPlayer implements Device { - private int Lautstaerke = 0; + private ArrayList Playlist = new ArrayList(); + private String playTrack = ""; + private Boolean isConnected; + private Boolean isDefect; + int Lautstaerke = 0; + + //*********setters und getters******** + public ArrayList getPlaylist() { + return Playlist; + } + + public void setPlaylist(ArrayList playlist) { + Playlist = playlist; + } + + public Boolean getDefect() { + return isDefect; + } + + public void setDefect(Boolean defect) { + isDefect = defect; + } + + + public Boolean getConnected() { + return isConnected; + } + + public void setConnected(Boolean connected) { + isConnected = connected; + } + + public String getPlayTrack() { + return playTrack; + } + + public void setPlayTrack(String playTrack) { + this.playTrack = playTrack; + } + public void setLautstaerke(int ls) { if (ls <= 100) { @@ -24,7 +65,7 @@ public class UsbPlayer implements Device { Lautstaerke = 100; } } - + //*********setters und getters******** @Override public void quieter() { if(Lautstaerke > 0) { From b33efc27fd99af3424973fb9d52472c4706b962f Mon Sep 17 00:00:00 2001 From: sahar Date: Mon, 7 Feb 2022 19:47:29 +0100 Subject: [PATCH 2/5] playTest adding and committing --- .../java/device/usbPlayer/UsbPlayerTest.java | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index bf170fe..574d556 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -1,6 +1,12 @@ package device.usbPlayer; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.ArrayList; +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.*; import static org.assertj.core.api.Assertions.assertThat; @@ -46,10 +52,41 @@ class UsbPlayerTest { @Test void chooseOption() { + }*/ + + @ParameterizedTest + @MethodSource("PlayOptions") + void playTest(String testName, UsbPlayer inputPlay, String expectedResult) { + String playState = inputPlay.play(); + assertThat(playState).describedAs(testName).isEqualTo(expectedResult); } - @Test - void play() { + static Stream PlayOptions() { + UsbPlayer up1 = new UsbPlayer(); + UsbPlayer up8 = new UsbPlayer(); + up8.setPlayTrack(""); + UsbPlayer up2 = new UsbPlayer(); + ArrayList l = new ArrayList(); + l.add("a.mp3"); + l.add("b.mp3"); + l.add("c.gif"); + up2.setPlaylist(l); + UsbPlayer up3 = new UsbPlayer(); + ArrayList Pl = new ArrayList(); + up3.setPlaylist(Pl); + UsbPlayer up6 = new UsbPlayer(); + up6.setDefect(true); + UsbPlayer up7 = new UsbPlayer(); + up7.setConnected(false); + + + return Stream.of( + Arguments.of("All right : ", up1, "USB : connected,working,have a list,Audio,point to a track."), + Arguments.of("No first Track : ", up8, "USB : connected,working,have a list,Audio,doesn't point to a track."), + Arguments.of("No Audio Files : ", up2, "USB : connected,working,have a list,not Audio."), + Arguments.of("No list of tracks : ", up3, "USB : connected,working,have no list."), + Arguments.of("connected , not working : ", up6, "USB : connected,not working."), + Arguments.of("not connected : ", up7, "not connected.") + ); } - */ } \ No newline at end of file From 82124265f1e56d9992d7fdeb1380b8b0d2a0fa4b Mon Sep 17 00:00:00 2001 From: sahar Date: Mon, 7 Feb 2022 19:56:23 +0100 Subject: [PATCH 3/5] Play functions code added --- src/main/java/device/usbPlayer/UsbPlayer.java | 67 ++++++++++++++++--- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/src/main/java/device/usbPlayer/UsbPlayer.java b/src/main/java/device/usbPlayer/UsbPlayer.java index ad187e8..65a2be0 100644 --- a/src/main/java/device/usbPlayer/UsbPlayer.java +++ b/src/main/java/device/usbPlayer/UsbPlayer.java @@ -57,15 +57,35 @@ public class UsbPlayer implements Device { return Lautstaerke; } - @Override - public void louder() { - if(Lautstaerke < 100) { - Lautstaerke += 1; - } else { - Lautstaerke = 100; + //*********constructure******** + public UsbPlayer() { + super(); + isDefect = false; + isConnected = true; + Playlist.add("Musik 01.mp3"); + Playlist.add("Musik 02.mp3"); + Playlist.add("Musik 03.mp3"); + playTrack = Playlist.get(0); + + } + //**********search method************* + private boolean isAllAudio() { + + String song = ""; + boolean flag = true; + + for (int i = 0; i < Playlist.size(); i++) { + song = Playlist.get(i).substring(Playlist.get(i).length() - 4); + if (song.equals(".mp3") | song.equals(".mp4") | song.equals(".wav")) { + flag = true; + } else { + flag = false; + break; + } } + return flag; } - //*********setters und getters******** + //**********search method************* @Override public void quieter() { if(Lautstaerke > 0) { @@ -75,6 +95,15 @@ public class UsbPlayer implements Device { } } + @Override + public void louder() { + if(Lautstaerke < 100) { + Lautstaerke += 1; + } else { + Lautstaerke = 100; + } + } + @Override public int getVolume() { return 0; @@ -108,7 +137,29 @@ public class UsbPlayer implements Device { @Override public String play() { - return null; + String result = "USB : "; + if (isConnected == true) { + result += "connected,"; + if (isDefect == false) { + result += "working"; + if (this.Playlist.size() != 0) { + result += ",have a list"; + if (this.isAllAudio()) { + result += ",Audio"; + if (!playTrack.equals("")) + result += ",point to a track."; + else + result += ",doesn't point to a track."; + } else { + result += ",not Audio."; + } + } else result += ",have no list."; + } else { + result += "not working."; + } + } else result = "not connected."; + return result; + } } From d87cc79bd02c9e53f54571ee997160800d3bf251 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 7 Feb 2022 22:52:15 +0100 Subject: [PATCH 4/5] revised Test for prev and next and updated functions --- .../device/radioPlayer/RadioPlayerTest.java | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index 1d0549f..a2bd01d 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -2,7 +2,13 @@ package device.radioPlayer; import device.radioPlayer.RadioPlayer; +import device.usbPlayer.UsbPlayer; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; @@ -43,22 +49,30 @@ class RadioPlayerTest { void getVolume() { } */ - @Test - void next() { - rp.next(); - int currentIndex=rp.Playlist.indexOf(rp.playTrack); - assertThat(rp.playTrack).isEqualTo(rp.Playlist.get((currentIndex)%rp.Playlist.size())); + @ParameterizedTest + @MethodSource("prevNextOptions") + void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) { + String station = testRp.playTrack; + assertThat(station).describedAs(testName).isEqualTo(expectedResult); +} + + static Stream prevNextOptions() { + RadioPlayer rp1 = new RadioPlayer(); + RadioPlayer rp2 = new RadioPlayer(); + RadioPlayer rp3 = new RadioPlayer(); + rp1.next(); + rp2.next(); + rp2.prev(); + rp3.prev(); + return Stream.of( + Arguments.of("Next Station Test", rp1, "Radio Teddy"), + Arguments.of("Prev Station Test", rp2, "Radio YouFM"), + Arguments.of("Prev works on first Station ", rp3, "Radio MegaHits") + ); } - - @Test - void prev() { - rp.prev(); - int currentIndex=rp.Playlist.indexOf(rp.playTrack); - assertThat(rp.playTrack).isEqualTo(rp.Playlist.get((currentIndex)%rp.Playlist.size())); - - } /* + @Test void getInfoText() { } From e515cf3ce66cb9ac612aca79b41b441ad3a1810d Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 7 Feb 2022 22:58:50 +0100 Subject: [PATCH 5/5] revised Test for prev and next and updated functions --- src/test/java/device/radioPlayer/RadioPlayerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index a2bd01d..d45590c 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -49,6 +49,7 @@ class RadioPlayerTest { void getVolume() { } */ + @ParameterizedTest @MethodSource("prevNextOptions") void prevNextTest(String testName, RadioPlayer testRp, String expectedResult) {