From 64d051326de6e2033428c0157b33731b154e53ab Mon Sep 17 00:00:00 2001 From: JPANZO Date: Wed, 9 Feb 2022 19:28:00 +0100 Subject: [PATCH 1/2] Base-Test for method next created. --- src/main/java/device/cdPlayer/CDPlayer.java | 8 ++++++ .../java/device/cdPlayer/CDPlayerTest.java | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index b7134fa..209e646 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -114,4 +114,12 @@ public class CDPlayer implements Device { return false; } + public String getSongByNumber(int songNr){ + return ""; + } + + public String getActualPlayTrack() { + return actualPlayTrack; + } + } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 91ef68a..694460a 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -153,4 +153,29 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("nextTestData") + void nextTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, String expectedResult){ + for (int i = 0; i < anzClicks; i++) { + _cdPlayer.next(); + } + if(testDirection.equals("SecondSongSelected")){ + assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult); + } + } + static Stream nextTestData () { + + String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; + CD audioCD=new CD("Audio",audioPlayList); + + CDPlayer cdPlayer=new CDPlayer(); + cdPlayer.tapOnCdFlap(); + cdPlayer.setCD(audioCD); + cdPlayer.tapOnCdFlap(); + + return Stream.of( + Arguments.of("[getActualPlayTrack() after 1x next() starting by firstSong] => SecondSongSelected","SecondSongSelected", cdPlayer, 1, cdPlayer.getSongByNumber(1)) + ); + } + } \ No newline at end of file From d1cb0386ba8ee77bb957c37f13dc82ccf10155fb Mon Sep 17 00:00:00 2001 From: JPANZO Date: Wed, 9 Feb 2022 20:00:48 +0100 Subject: [PATCH 2/2] Productive code for case:1 of method-test next created. --- src/main/java/device/cdPlayer/CDPlayer.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 209e646..ff1caf2 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -42,7 +42,10 @@ public class CDPlayer implements Device { @Override public void next() { + List playList = Arrays.asList(loadedCD.getPlayList()); + int indexOfActualPlayTrack=playList.indexOf(actualPlayTrack); + this.actualPlayTrack=playList.get(indexOfActualPlayTrack +1); } @Override @@ -115,7 +118,8 @@ public class CDPlayer implements Device { } public String getSongByNumber(int songNr){ - return ""; + List playList = Arrays.asList(loadedCD.getPlayList()); + return playList.get(songNr); } public String getActualPlayTrack() {