From ce4ab1fbd47755d378f5e318eeb29db6f69d81af Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 17:25:00 +0100 Subject: [PATCH 01/19] Tests for CDPlayer-Method [Play] created. --- src/main/java/device/cdPlayer/CDPlayer.java | 6 +- .../java/device/cdPlayer/CDPlayerTest.java | 110 +++++++++++++----- 2 files changed, 87 insertions(+), 29 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 6cc7b77..ace5b17 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -65,7 +65,7 @@ public class CDPlayer implements Device { return null; } - //Getters und Setters + //Getters, Setters und SupportMethods public void setCD(CD _loadedCD) { loadedCD=_loadedCD; this.setCdDriveContent(); @@ -76,4 +76,8 @@ public class CDPlayer implements Device { CdDriveContent = 1; } + public void tapOnCdFlap(){ + this.CdFlap+=1; + } + } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index eb63e35..3d651ac 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -1,47 +1,101 @@ package device.cdPlayer; +import device.cdPlayer.exceptions.*; import org.junit.jupiter.api.Test; +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.junit.jupiter.MockitoExtension; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; +@ExtendWith(MockitoExtension.class) class CDPlayerTest { -/* - @Test - void louder() { - } - @Test - void quieter() { + @ParameterizedTest + @MethodSource("playTestData") + void play(String testName, CDPlayer _cdPlayer,Exception exception , String expectedResult) { + if(exception!=null){ + Exception newException=assertThrows(exception.getClass(),()->_cdPlayer.play()); + assertEquals(expectedResult, newException.getMessage()); + }else{ + assertThat(_cdPlayer.play()).describedAs(testName).isEqualTo(expectedResult); + } } + static Stream playTestData () { + //some PlayLists + String[] videoPlayList=new String[]{"Video 01","Video 02","Video 03","Video 04","Video 05"}; + String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; + //some CDs + CD videoCD1=new CD("DVD",videoPlayList); + CD videoCD2=new CD("Blue-ray",videoPlayList); + CD audioCD1=new CD("Audio",audioPlayList); + CD audioCD2=new CD("MP3",audioPlayList); + CD audioCD3=new CD("WMA",audioPlayList); + CD audioCD4=new CD("AAC",audioPlayList); - @Test - void getVolume() { - } + //some CDPlayers + CDPlayer cdPlayer1=new CDPlayer(); - @Test - void next() { - } + CDPlayer cdPlayer2=new CDPlayer(); + cdPlayer2.tapOnCdFlap(); + cdPlayer2.tapOnCdFlap(); - @Test - void prev() { - } + CDPlayer cdPlayer3=new CDPlayer(); + cdPlayer3.tapOnCdFlap(); - @Test - void getInfoText() { - } + CDPlayer cdPlayer4=new CDPlayer(); + cdPlayer4.tapOnCdFlap(); + cdPlayer4.setCD(videoCD1); - @Test - void getOptions() { - } + //=================================== + CDPlayer cdPlayer5=new CDPlayer(); + cdPlayer5.tapOnCdFlap(); + cdPlayer5.setCD(videoCD1); + cdPlayer5.tapOnCdFlap(); - @Test - void chooseOption() { - } + CDPlayer cdPlayer6=new CDPlayer(); + cdPlayer6.tapOnCdFlap(); + cdPlayer6.setCD(videoCD2); + cdPlayer6.tapOnCdFlap(); + //=================================== - @Test - void play() { - } + CDPlayer cdPlayer7=new CDPlayer(); + cdPlayer7.tapOnCdFlap(); + cdPlayer7.setCD(audioCD1); + cdPlayer7.tapOnCdFlap(); + + CDPlayer cdPlayer8=new CDPlayer(); + cdPlayer8.tapOnCdFlap(); + cdPlayer8.setCD(audioCD2); + cdPlayer8.tapOnCdFlap(); - */ + CDPlayer cdPlayer9=new CDPlayer(); + cdPlayer9.tapOnCdFlap(); + cdPlayer9.setCD(audioCD3); + cdPlayer9.tapOnCdFlap(); + + CDPlayer cdPlayer10=new CDPlayer(); + cdPlayer10.tapOnCdFlap(); + cdPlayer10.setCD(audioCD4); + cdPlayer10.tapOnCdFlap(); + + return Stream.of( + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isEmpty] => NoCD", cdPlayer1, new NoCDException(), "CD must be set."), + Arguments.of("[CdFlap has been Opened and Closed, CdDriveContent=>isEmpty] => NoCD", cdPlayer2,new NoCDException(),"CD must be set."), + Arguments.of("[CdFlap=isOpen , CdDriveContent=>isEmpty] => CdFlapIsOpen", cdPlayer3,new CdFlapIsOpenException(),"Cd Flap must be closed."), + Arguments.of("[CdFlap=isOpen , CdDriveContent=>isSet] => CdFlapIsOpen", cdPlayer4,new CdFlapIsOpenException(),"Cd Flap must be closed."), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>DVD] => FormatNotSupported",cdPlayer5,new FormatNotSupportedException(),"Cd-Format not supported."), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>Blue-ray] => FormatNotSupported",cdPlayer6, new FormatNotSupportedException(),"Cd-Format not supported."), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>Audio] => AllConditionsForPlayMet", cdPlayer7,null,"AllConditionsForPlayMet"), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>MP3] => AllConditionsForPlayMet", cdPlayer8,null,"AllConditionsForPlayMet"), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>WMA] => AllConditionsForPlayMet", cdPlayer9,null,"AllConditionsForPlayMet"), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>AAC] => AllConditionsForPlayMet", cdPlayer10,null,"AllConditionsForPlayMet") + ); + } } \ No newline at end of file From dfd37cdade81f22ab7a54ce68077428bef723739 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 17:51:00 +0100 Subject: [PATCH 02/19] Productive-Code for CDPlayer-Method [Play] produced. --- src/main/java/device/cdPlayer/CDPlayer.java | 32 +++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index ace5b17..12b241a 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -1,7 +1,7 @@ package device.cdPlayer; import device.Device; - +import device.cdPlayer.exceptions.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -16,8 +16,6 @@ public class CDPlayer implements Device { private String actualPlayTrack=""; private CD loadedCD; - private String[] cdAlbum=new String[]{}; - @Override public void louder() { @@ -62,6 +60,19 @@ public class CDPlayer implements Device { @Override public String play() { + if(isCdFlapOpen()){ + throw new CdFlapIsOpenException(); + } + else if(!isCdFlapOpen()&&getCdDriveContent()==0){ + throw new NoCDException(); + } + else if(!isCdFlapOpen()&&getCdDriveContent()==1&&!checkFormat(loadedCD.getFormat())){ + throw new FormatNotSupportedException(); + } + else if(!isCdFlapOpen()&&getCdDriveContent()==1&&checkFormat(loadedCD.getFormat())){ + System.out.println(loadedCD.getFormat()+" "+this.actualPlayTrack+" is playing."); + return "AllConditionsForPlayMet"; + } return null; } @@ -79,5 +90,20 @@ public class CDPlayer implements Device { public void tapOnCdFlap(){ this.CdFlap+=1; } + private boolean checkFormat(String format){ + if(this.supportedFormats.contains(format)) + return true; + else return false; + } + private int getCdDriveContent() { + return CdDriveContent; + } + private boolean isCdFlapOpen() { + if(CdFlap==1) { + return true; + } + else + return false; + } } From 1d5a72debbfe8d1a9b7d9df27eb3e378309e18b4 Mon Sep 17 00:00:00 2001 From: sahar Date: Mon, 7 Feb 2022 19:45:23 +0100 Subject: [PATCH 03/19] 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 04/19] 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 05/19] 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 86b5cca88c10fce0fa5a920c5dd2d48874bc4e9c Mon Sep 17 00:00:00 2001 From: sahar Date: Mon, 7 Feb 2022 20:26:29 +0100 Subject: [PATCH 06/19] LouderTest implemented --- .../java/device/usbPlayer/UsbPlayerTest.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index bf170fe..25eaef1 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; @@ -47,9 +53,23 @@ class UsbPlayerTest { @Test void chooseOption() { } +*/ +@ParameterizedTest +@MethodSource("louderOptions") +void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) { + int volumeNum = inputPlay.getLautstaerke(); + assertThat(volumeNum).describedAs(testName).isEqualTo(expectedResult); +} - @Test - void play() { + static Stream louderOptions() { + UsbPlayer up1 = new UsbPlayer(); + up1.louder(); + UsbPlayer up2 = new UsbPlayer(); + up2.setLautstaerke(100); + up2.louder(); + return Stream.of( + Arguments.of("Volume is : 1 ", up1, 1), + Arguments.of("Volume is : 100 ", up2, 100) + ); } - */ } \ No newline at end of file From 3d790aeddeb65691a3680c2f473cdff7d7b3a553 Mon Sep 17 00:00:00 2001 From: sahar Date: Mon, 7 Feb 2022 20:32:24 +0100 Subject: [PATCH 07/19] changes in the class --- src/test/java/device/usbPlayer/UsbPlayerTest.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index bf170fe..2768e73 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -10,19 +10,7 @@ class UsbPlayerTest { UsbPlayer up = new UsbPlayer(); - @Test - void louder_test() { - up.setLautstaerke(40); - up.louder(); - assertThat(up.getLautstaerke()).isEqualTo(41); - } - @Test - void quieter_test() { - up.setLautstaerke(40); - up.quieter(); - assertThat(up.getLautstaerke()).isEqualTo(39); - } /* @Test void getVolume() { From d84f750766499fb99ebbaabc3df13018ba38ca5b Mon Sep 17 00:00:00 2001 From: sahar Date: Mon, 7 Feb 2022 20:33:22 +0100 Subject: [PATCH 08/19] changes in the class --- src/test/java/device/usbPlayer/UsbPlayerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 25eaef1..4aa0e56 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -66,7 +66,7 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) { up1.louder(); UsbPlayer up2 = new UsbPlayer(); up2.setLautstaerke(100); - up2.louder(); + up2.louder(); return Stream.of( Arguments.of("Volume is : 1 ", up1, 1), Arguments.of("Volume is : 100 ", up2, 100) From 0d4825e2d1961bb8ce71cef89a07d5ad259b3343 Mon Sep 17 00:00:00 2001 From: sahar Date: Mon, 7 Feb 2022 20:43:27 +0100 Subject: [PATCH 09/19] QuieterTest is implemented --- .../java/device/usbPlayer/UsbPlayerTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 2768e73..b0dcdc7 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -1,6 +1,11 @@ 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.stream.Stream; import static org.junit.jupiter.api.Assertions.*; import static org.assertj.core.api.Assertions.assertThat; @@ -9,7 +14,24 @@ class UsbPlayerTest { UsbPlayer up = new UsbPlayer(); + @ParameterizedTest + @MethodSource("quieterOptions") + void quieterTest(String testName, UsbPlayer inputPlay, int expectedResult) { + int volumeNum = inputPlay.getLautstaerke(); + assertThat(volumeNum).describedAs(testName).isEqualTo(expectedResult); + } + static Stream quieterOptions() { + UsbPlayer up1 = new UsbPlayer(); + up1.quieter(); + UsbPlayer up2 = new UsbPlayer(); + up2.setLautstaerke(10); + up2.quieter(); + return Stream.of( + Arguments.of("Volume must stay 0 ", up1, 0), + Arguments.of("Volume must be 9 ", up2, 9) + ); + } /* @Test From 192dbd4fc3b0869c3d12ba42d04509ca6e445ed1 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 21:24:47 +0100 Subject: [PATCH 10/19] Test-Code for CDPlayer-Method [Louder] produced. --- .../java/device/cdPlayer/CDPlayerTest.java | 68 +++++++++---------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index eb63e35..1248004 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -1,47 +1,43 @@ package device.cdPlayer; import org.junit.jupiter.api.Test; +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.junit.jupiter.MockitoExtension; -import static org.junit.jupiter.api.Assertions.*; +import java.util.stream.Stream; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; +@ExtendWith(MockitoExtension.class) class CDPlayerTest { -/* - @Test - void louder() { - } - - @Test - void quieter() { - } - - @Test - void getVolume() { - } - - @Test - void next() { - } - - @Test - void prev() { - } - - @Test - void getInfoText() { - } - - @Test - void getOptions() { - } - - @Test - void chooseOption() { - } - @Test - void play() { + @ParameterizedTest + @MethodSource("louderTestData") + void louderTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, int expectedResult) { + for (int i = 0; i < anzClicks; i++) { + _cdPlayer.louder(); + } + if(testDirection.equals("VolumeIncreased")){ + assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(expectedResult); + } + if(testDirection.equals("VolumeHasChanged")){ + assertThat(_cdPlayer.getVolume()).describedAs(testName).isNotEqualTo(expectedResult); + }if(testDirection.equals("VolumeNotDecreased")){ + assertThat(_cdPlayer.getVolume()).describedAs(testName).isNotEqualTo(expectedResult); + } + } + + static Stream louderTestData () { + CDPlayer cdPlayer=new CDPlayer(); + return Stream.of( + Arguments.of("[getVolume() after 20x louder() ] => VolumeIncreased","VolumeIncreased", cdPlayer, 20, 20), + Arguments.of("[getVolume() after 2x louder() ] => VolumeHasChanged","VolumeHasChanged" ,cdPlayer,2,0), + Arguments.of("[getVolume() after 5x louder() ] => VolumeDecreased","VolumeNotDecreased", cdPlayer,5,-5) + ); } - */ } \ No newline at end of file From a1d31ab7fc5899ab396f296a5b10c0a3210b3fde Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 21:30:53 +0100 Subject: [PATCH 11/19] Production-Code for CDPlayer-Method [Louder] produced. --- src/main/java/device/cdPlayer/CDPlayer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 6cc7b77..f66c9d1 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -21,7 +21,11 @@ public class CDPlayer implements Device { @Override public void louder() { - + if(volume < 100) { + volume += 1; + } else { + volume = 100; + } } @Override @@ -31,7 +35,7 @@ public class CDPlayer implements Device { @Override public int getVolume() { - return 0; + return this.volume; } @Override From 35b7f476577e284b45160f592886732c83151997 Mon Sep 17 00:00:00 2001 From: sahar Date: Mon, 7 Feb 2022 21:40:08 +0100 Subject: [PATCH 12/19] UsbPlayerTest changes --- src/test/java/device/usbPlayer/UsbPlayerTest.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 4aa0e56..f90fc54 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -16,19 +16,6 @@ class UsbPlayerTest { UsbPlayer up = new UsbPlayer(); - @Test - void louder_test() { - up.setLautstaerke(40); - up.louder(); - assertThat(up.getLautstaerke()).isEqualTo(41); - } - - @Test - void quieter_test() { - up.setLautstaerke(40); - up.quieter(); - assertThat(up.getLautstaerke()).isEqualTo(39); - } /* @Test void getVolume() { From d87cc79bd02c9e53f54571ee997160800d3bf251 Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Mon, 7 Feb 2022 22:52:15 +0100 Subject: [PATCH 13/19] 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 14/19] 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) { From ec0d64d1ea5f3941f80821d0e67cf7c8fcb0c9c2 Mon Sep 17 00:00:00 2001 From: sahar Date: Tue, 8 Feb 2022 21:01:07 +0100 Subject: [PATCH 15/19] playTest update --- .../java/device/usbPlayer/UsbPlayerTest.java | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 9671e73..12f199d 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -21,19 +21,7 @@ class UsbPlayerTest { UsbPlayer up = new UsbPlayer(); - @Test - void louder_test() { - up.setLautstaerke(40); - up.louder(); - assertThat(up.getLautstaerke()).isEqualTo(41); - } - @Test - void quieter_test() { - up.setLautstaerke(40); - up.quieter(); - assertThat(up.getLautstaerke()).isEqualTo(39); - } /* @Test void getVolume() { @@ -92,7 +80,8 @@ class UsbPlayerTest { 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.") + Arguments.of("not connected : ", up7, "not connected.")); + } @ParameterizedTest @@ -103,15 +92,15 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) { } static Stream louderOptions() { - UsbPlayer up1 = new UsbPlayer(); - up1.louder(); - UsbPlayer up2 = new UsbPlayer(); - up2.setLautstaerke(100); - up2.louder(); + UsbPlayer up11 = new UsbPlayer(); + up11.louder(); + UsbPlayer up22 = new UsbPlayer(); + up22.setLautstaerke(100); + up22.louder(); return Stream.of( - Arguments.of("Volume is : 1 ", up1, 1), - Arguments.of("Volume is : 100 ", up2, 100) + Arguments.of("Volume is : 1 ", up11, 1), + Arguments.of("Volume is : 100 ", up22, 100) ); } - */ + } \ No newline at end of file From 1e4cf020e4134ff70b48f51a2991e0e5caa80758 Mon Sep 17 00:00:00 2001 From: sahar Date: Tue, 8 Feb 2022 21:07:55 +0100 Subject: [PATCH 16/19] playTest , louderTest and quieterTest update --- .../java/device/usbPlayer/UsbPlayerTest.java | 55 +++++++------------ 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index 12f199d..bd85948 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -1,52 +1,17 @@ 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.stream.Stream; -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; class UsbPlayerTest { UsbPlayer up = new UsbPlayer(); - - -/* - @Test - void getVolume() { - } - - @Test - void next() { - } - - @Test - void prev() { - } - - @Test - void getInfoText() { - } - - @Test - void getOptions() { - } - - @Test - void chooseOption() { - }*/ - @ParameterizedTest @MethodSource("PlayOptions") void playTest(String testName, UsbPlayer inputPlay, String expectedResult) { @@ -54,7 +19,6 @@ class UsbPlayerTest { assertThat(playState).describedAs(testName).isEqualTo(expectedResult); } - static Stream PlayOptions() { UsbPlayer up1 = new UsbPlayer(); UsbPlayer up8 = new UsbPlayer(); @@ -103,4 +67,23 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) { ); } + @ParameterizedTest + @MethodSource("quieterOptions") + void quieterTest(String testName, UsbPlayer inputPlay, int expectedResult) { + int volumeNum = inputPlay.getLautstaerke(); + assertThat(volumeNum).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream quieterOptions() { + UsbPlayer up1 = new UsbPlayer(); + up1.quieter(); + UsbPlayer up2 = new UsbPlayer(); + up2.setLautstaerke(10); + up2.quieter(); + return Stream.of( + Arguments.of("Volume must stay 0 ", up1, 0), + Arguments.of("Volume must be 9 ", up2, 9) + ); + } + } \ No newline at end of file From 9366de1be110b6cc6e8ca26f3c44e497742f01eb Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 8 Feb 2022 21:28:01 +0100 Subject: [PATCH 17/19] CDPlayer-Methods[play,louder] update. --- .../java/device/cdPlayer/CDPlayerTest.java | 38 ++++++++++--------- .../java/device/usbPlayer/UsbPlayerTest.java | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 43358dd..7126d3e 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -77,6 +77,26 @@ class CDPlayerTest { cdPlayer9.tapOnCdFlap(); cdPlayer9.setCD(audioCD3); cdPlayer9.tapOnCdFlap(); + + CDPlayer cdPlayer10=new CDPlayer(); + cdPlayer10.tapOnCdFlap(); + cdPlayer10.setCD(audioCD4); + cdPlayer10.tapOnCdFlap(); + + return Stream.of( + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isEmpty] => NoCD", cdPlayer1, new NoCDException(), "CD must be set."), + Arguments.of("[CdFlap has been Opened and Closed, CdDriveContent=>isEmpty] => NoCD", cdPlayer2,new NoCDException(),"CD must be set."), + Arguments.of("[CdFlap=isOpen , CdDriveContent=>isEmpty] => CdFlapIsOpen", cdPlayer3,new CdFlapIsOpenException(),"Cd Flap must be closed."), + Arguments.of("[CdFlap=isOpen , CdDriveContent=>isSet] => CdFlapIsOpen", cdPlayer4,new CdFlapIsOpenException(),"Cd Flap must be closed."), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>DVD] => FormatNotSupported",cdPlayer5,new FormatNotSupportedException(),"Cd-Format not supported."), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>Blue-ray] => FormatNotSupported",cdPlayer6, new FormatNotSupportedException(),"Cd-Format not supported."), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>Audio] => AllConditionsForPlayMet", cdPlayer7,null,"AllConditionsForPlayMet"), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>MP3] => AllConditionsForPlayMet", cdPlayer8,null,"AllConditionsForPlayMet"), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>WMA] => AllConditionsForPlayMet", cdPlayer9,null,"AllConditionsForPlayMet"), + Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>AAC] => AllConditionsForPlayMet", cdPlayer10,null,"AllConditionsForPlayMet") + ); + } + @ParameterizedTest @MethodSource("louderTestData") void louderTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, int expectedResult) { @@ -92,11 +112,6 @@ class CDPlayerTest { assertThat(_cdPlayer.getVolume()).describedAs(testName).isNotEqualTo(expectedResult); } } - - CDPlayer cdPlayer10=new CDPlayer(); - cdPlayer10.tapOnCdFlap(); - cdPlayer10.setCD(audioCD4); - cdPlayer10.tapOnCdFlap(); static Stream louderTestData () { CDPlayer cdPlayer=new CDPlayer(); return Stream.of( @@ -106,18 +121,5 @@ class CDPlayerTest { ); } - return Stream.of( - Arguments.of("[CdFlap=isClosed , CdDriveContent=>isEmpty] => NoCD", cdPlayer1, new NoCDException(), "CD must be set."), - Arguments.of("[CdFlap has been Opened and Closed, CdDriveContent=>isEmpty] => NoCD", cdPlayer2,new NoCDException(),"CD must be set."), - Arguments.of("[CdFlap=isOpen , CdDriveContent=>isEmpty] => CdFlapIsOpen", cdPlayer3,new CdFlapIsOpenException(),"Cd Flap must be closed."), - Arguments.of("[CdFlap=isOpen , CdDriveContent=>isSet] => CdFlapIsOpen", cdPlayer4,new CdFlapIsOpenException(),"Cd Flap must be closed."), - Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>DVD] => FormatNotSupported",cdPlayer5,new FormatNotSupportedException(),"Cd-Format not supported."), - Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>Blue-ray] => FormatNotSupported",cdPlayer6, new FormatNotSupportedException(),"Cd-Format not supported."), - Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>Audio] => AllConditionsForPlayMet", cdPlayer7,null,"AllConditionsForPlayMet"), - Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>MP3] => AllConditionsForPlayMet", cdPlayer8,null,"AllConditionsForPlayMet"), - Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>WMA] => AllConditionsForPlayMet", cdPlayer9,null,"AllConditionsForPlayMet"), - Arguments.of("[CdFlap=isClosed , CdDriveContent=>isSet, CdFormat=>AAC] => AllConditionsForPlayMet", cdPlayer10,null,"AllConditionsForPlayMet") - ); - } } \ No newline at end of file diff --git a/src/test/java/device/usbPlayer/UsbPlayerTest.java b/src/test/java/device/usbPlayer/UsbPlayerTest.java index ae3bc85..f5c1962 100644 --- a/src/test/java/device/usbPlayer/UsbPlayerTest.java +++ b/src/test/java/device/usbPlayer/UsbPlayerTest.java @@ -76,5 +76,5 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) { Arguments.of("Volume is : 100 ", up2, 100) ); } - */ + } \ No newline at end of file From 35663bd953cea50d16555ec7ebbad30ad326545a Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 8 Feb 2022 21:31:37 +0100 Subject: [PATCH 18/19] CDPlayer-Methods[play,louder,quieter] update. --- .../java/device/cdPlayer/CDPlayerTest.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 7126d3e..91ef68a 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -1,7 +1,6 @@ package device.cdPlayer; import device.cdPlayer.exceptions.*; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -121,5 +120,37 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("quieterTestData") + void quieterTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, int expectedResult) { + for (int i = 0; i < anzClicks; i++) { + _cdPlayer.quieter(); + } + + if(testDirection.equals("VolumeDecreased")){ + for (int i = 0; i < 20; i++) { + _cdPlayer.louder(); + } + for (int i = 0; i < anzClicks; i++) { + _cdPlayer.quieter(); + } + assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(expectedResult); + } + if(testDirection.equals("VolumeHasNotChanged")){ + assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(expectedResult); + }if(testDirection.equals("VolumeNotIncreased")){ + + assertThat(_cdPlayer.getVolume()).describedAs(testName).isNotEqualTo(expectedResult); + } + } + + static Stream quieterTestData () { + CDPlayer cdPlayer=new CDPlayer(); + return Stream.of( + Arguments.of("[getVolume() after 20x quieter() starting by 20] => VolumeHasDecreased","VolumeDecreased", cdPlayer, 19, 1), + Arguments.of("[getVolume() after 20x quieter() starting by 0] => VolumeHasNotChanged","VolumeHasNotChanged" ,cdPlayer,20,0), + Arguments.of("[getVolume() after 5x quieter() starting by 0] => VolumeNotIncreased","VolumeNotIncreased", cdPlayer,5,5) + ); + } } \ No newline at end of file From 8ec4565ee8cea9c35be30004b85fdf5669f3a6fa Mon Sep 17 00:00:00 2001 From: alpina0707 Date: Wed, 9 Feb 2022 10:13:16 +0100 Subject: [PATCH 19/19] Test new Jenkins config --- src/test/java/device/radioPlayer/RadioPlayerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/device/radioPlayer/RadioPlayerTest.java b/src/test/java/device/radioPlayer/RadioPlayerTest.java index d45590c..3f2c716 100644 --- a/src/test/java/device/radioPlayer/RadioPlayerTest.java +++ b/src/test/java/device/radioPlayer/RadioPlayerTest.java @@ -44,7 +44,7 @@ class RadioPlayerTest { assertThat(rp.getLautstaerke()).isEqualTo(0); } /* - + Jenkins config test @Test void getVolume() { }