From b4583eece1c40995c3485dffb099c90992aa0f03 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 15 Feb 2022 17:23:05 +0100 Subject: [PATCH 1/5] test+productive code for case:1 of method prev in CDPlayer created. --- src/main/java/device/cdPlayer/CDPlayer.java | 2 ++ .../java/device/cdPlayer/CDPlayerTest.java | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 5a55a91..7eea012 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -52,6 +52,8 @@ public class CDPlayer implements Device { @Override public void prev() { + List playList = Arrays.asList(loadedCD.getPlayList()); + this.actualPlayTrack=playList.get(playList.indexOf(actualPlayTrack) -1); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 17bb3c0..702a3af 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -197,4 +197,29 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("prevTestData") + void prevTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, String expectedResult){ + for (int i = 0; i < anzClicks; i++) { + _cdPlayer.prev(); + } + assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult); + } + static Stream prevTestData () { + + String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; + CD audioCD=new CD("Audio",audioPlayList); + + CDPlayer cdPlayer1=new CDPlayer(); + cdPlayer1.tapOnCdFlap(); + cdPlayer1.setCD(audioCD); + cdPlayer1.tapOnCdFlap(); + cdPlayer1.next();//1x nach Vorne + + return Stream.of( + Arguments.of("[getActualPlayTrack() after 1x prev() starting by firstSong] => FirstSongSelected","FirstSongSelected", cdPlayer1, 1, cdPlayer1.getSongByNumber(0)) + ); + + } + } \ No newline at end of file From e7972264ded1662689a3ef9cc043888de75abbc3 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 15 Feb 2022 17:28:00 +0100 Subject: [PATCH 2/5] Revert "test+productive code for case:1 of method prev in CDPlayer created." This reverts commit b4583eece1c40995c3485dffb099c90992aa0f03. --- src/main/java/device/cdPlayer/CDPlayer.java | 2 -- .../java/device/cdPlayer/CDPlayerTest.java | 25 ------------------- 2 files changed, 27 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 7eea012..5a55a91 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -52,8 +52,6 @@ public class CDPlayer implements Device { @Override public void prev() { - List playList = Arrays.asList(loadedCD.getPlayList()); - this.actualPlayTrack=playList.get(playList.indexOf(actualPlayTrack) -1); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 702a3af..17bb3c0 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -197,29 +197,4 @@ class CDPlayerTest { ); } - @ParameterizedTest - @MethodSource("prevTestData") - void prevTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, String expectedResult){ - for (int i = 0; i < anzClicks; i++) { - _cdPlayer.prev(); - } - assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult); - } - static Stream prevTestData () { - - String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; - CD audioCD=new CD("Audio",audioPlayList); - - CDPlayer cdPlayer1=new CDPlayer(); - cdPlayer1.tapOnCdFlap(); - cdPlayer1.setCD(audioCD); - cdPlayer1.tapOnCdFlap(); - cdPlayer1.next();//1x nach Vorne - - return Stream.of( - Arguments.of("[getActualPlayTrack() after 1x prev() starting by firstSong] => FirstSongSelected","FirstSongSelected", cdPlayer1, 1, cdPlayer1.getSongByNumber(0)) - ); - - } - } \ No newline at end of file From fc6f610b6a2aa6a8844a03773bbe467f4324b797 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 15 Feb 2022 17:35:57 +0100 Subject: [PATCH 3/5] test+productive code for case:1 of method prev in CDPlayer created. --- src/main/java/device/cdPlayer/CDPlayer.java | 3 ++- .../java/device/cdPlayer/CDPlayerTest.java | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 5a55a91..9a55f4c 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -52,7 +52,8 @@ public class CDPlayer implements Device { @Override public void prev() { - + List playList = Arrays.asList(loadedCD.getPlayList()); + this.actualPlayTrack=playList.get(playList.indexOf(actualPlayTrack)-1); } @Override diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 17bb3c0..fdd833a 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -197,4 +197,27 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("prevTestData") + void prevTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, String expectedResult){ + for (int i = 0; i prevTestData () { + + String[] audioPlayList = new String[]{"Audio 01", "Audio 02", "Audio 03", "Audio 04", "Audio 05"}; + CD audioCD = new CD("Audio", audioPlayList); + + CDPlayer cdPlayer1 = new CDPlayer(); + cdPlayer1.tapOnCdFlap(); + cdPlayer1.setCD(audioCD); + cdPlayer1.tapOnCdFlap(); + cdPlayer1.next(); + + return Stream.of( + Arguments.of("[getActualPlayTrack() after 1x prev() starting by secondSong] => FirstSongSelected", "FirstSongSelected", cdPlayer1, 1, cdPlayer1.getSongByNumber(0)) + ); + } } \ No newline at end of file From ffd65cc96f5b00e8e12f4509fa0ea1eb9b6962d1 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 15 Feb 2022 17:49:29 +0100 Subject: [PATCH 4/5] test+productive code for case:2 of method prev in CDPlayer created. --- .../java/device/cdPlayer/CDPlayerTest.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index fdd833a..a11ff58 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -200,8 +200,18 @@ class CDPlayerTest { @ParameterizedTest @MethodSource("prevTestData") void prevTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, String expectedResult){ - for (int i = 0; i FirstSongSelected", "FirstSongSelected", cdPlayer1, 1, cdPlayer1.getSongByNumber(0)) + Arguments.of("[getActualPlayTrack() after 1x prev() starting by secondSong] => FirstSongSelected", "StartingBySecondSong", cdPlayer1, 1, cdPlayer1.getSongByNumber(0)), + Arguments.of("[getActualPlayTrack() after 2x prev() starting by thirdSong] => FirstSongSelected", "StartingByThirdSong", cdPlayer1, 2, cdPlayer1.getSongByNumber(0)) ); } } \ No newline at end of file From d5b13dadc8b57b1d4ebb73dce23c7b406e771cf9 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 15 Feb 2022 18:15:45 +0100 Subject: [PATCH 5/5] test+productive code for case:3 of method prev in CDPlayer created. --- src/main/java/device/cdPlayer/CDPlayer.java | 8 +++++++- src/test/java/device/cdPlayer/CDPlayerTest.java | 13 +++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 9a55f4c..618159d 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -53,7 +53,13 @@ public class CDPlayer implements Device { @Override public void prev() { List playList = Arrays.asList(loadedCD.getPlayList()); - this.actualPlayTrack=playList.get(playList.indexOf(actualPlayTrack)-1); + int actualIndex=playList.indexOf(actualPlayTrack); + if(actualIndex>0){ + actualIndex-=1; + }else{ + actualIndex=0; + } + this.actualPlayTrack=playList.get(actualIndex); } @Override diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index a11ff58..d26aa95 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -202,16 +202,13 @@ class CDPlayerTest { void prevTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, String expectedResult){ if(testDirection.equals("StartingBySecondSong")) { _cdPlayer.next(); - for (int i = 0; i < anzClicks; i++) { - _cdPlayer.prev(); - } } if(testDirection.equals("StartingByThirdSong")) { _cdPlayer.next(); _cdPlayer.next(); - for (int i = 0; i < anzClicks; i++) { - _cdPlayer.prev(); - } + } + for (int i = 0; i < anzClicks; i++) { + _cdPlayer.prev(); } assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult); } @@ -225,10 +222,10 @@ class CDPlayerTest { cdPlayer1.setCD(audioCD); cdPlayer1.tapOnCdFlap(); - return Stream.of( Arguments.of("[getActualPlayTrack() after 1x prev() starting by secondSong] => FirstSongSelected", "StartingBySecondSong", cdPlayer1, 1, cdPlayer1.getSongByNumber(0)), - Arguments.of("[getActualPlayTrack() after 2x prev() starting by thirdSong] => FirstSongSelected", "StartingByThirdSong", cdPlayer1, 2, cdPlayer1.getSongByNumber(0)) + Arguments.of("[getActualPlayTrack() after 2x prev() starting by thirdSong] => FirstSongSelected", "StartingByThirdSong", cdPlayer1, 2, cdPlayer1.getSongByNumber(0)), + Arguments.of("[getActualPlayTrack() after 1x prev() starting by firstSong] => FirstSongSelected", "StartingByFirstSong", cdPlayer1, 1, cdPlayer1.getSongByNumber(0)) ); } } \ No newline at end of file