From fce439259bcd626f61070c1e8f108d5c0e814772 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Fri, 11 Feb 2022 16:24:49 +0100 Subject: [PATCH] Test+Productive code for case:3 of method-test next created. --- src/main/java/device/cdPlayer/CDPlayer.java | 9 +++-- .../java/device/cdPlayer/CDPlayerTest.java | 39 +++++++++++++------ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 8ef629f..5a55a91 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -44,9 +44,10 @@ public class CDPlayer implements Device { public void next() { List playList = Arrays.asList(loadedCD.getPlayList()); int indexOfActualPlayTrack=playList.indexOf(actualPlayTrack); - System.out.println("indexOfActualPlayTrack="+indexOfActualPlayTrack); - this.actualPlayTrack=playList.get(indexOfActualPlayTrack +1); - System.out.println("nextSong= "+actualPlayTrack); + int indexOfNextPlayTrack=(indexOfActualPlayTrack+1)%loadedCD.getPlayList().length; + //System.out.println("actualIndex= "+indexOfActualPlayTrack); + this.actualPlayTrack=playList.get(indexOfNextPlayTrack ); + //System.out.println("nextSong= "+actualPlayTrack); } @Override @@ -66,7 +67,7 @@ public class CDPlayer implements Device { @Override public String[] getItemList() { - return new String[0]; + return loadedCD.getPlayList(); } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index a3054e9..17bb3c0 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -156,27 +156,44 @@ 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")|| testDirection.equals("ThirdSongSelected")){ + for (int i = 0; i < anzClicks; i++) { + _cdPlayer.next(); + } + assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult); } - //if(testDirection.equals("SecondSongSelected")){ + if(testDirection.equals("FirstSongSelected")){ + for (int i = 0; i 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(); - System.out.println(cdPlayer.getActualPlayTrack()); + CDPlayer cdPlayer1=new CDPlayer(); + cdPlayer1.tapOnCdFlap(); + cdPlayer1.setCD(audioCD); + cdPlayer1.tapOnCdFlap(); + + CDPlayer cdPlayer2=new CDPlayer(); + cdPlayer2.tapOnCdFlap(); + cdPlayer2.setCD(audioCD); + cdPlayer2.tapOnCdFlap(); + + CDPlayer cdPlayer3=new CDPlayer(); + cdPlayer3.tapOnCdFlap(); + cdPlayer3.setCD(audioCD); + cdPlayer3.tapOnCdFlap(); return Stream.of( - Arguments.of("[getActualPlayTrack() after 1x next() starting by firstSong] => SecondSongSelected","SecondSongSelected", cdPlayer, 1, cdPlayer.getSongByNumber(1)), - Arguments.of("[getActualPlayTrack() after 2x next() starting by firstSong] => ThirdSongSelected","ThirdSongSelected" ,cdPlayer,1,cdPlayer.getSongByNumber(2)) + Arguments.of("[getActualPlayTrack() after 1x next() starting by firstSong] => SecondSongSelected","SecondSongSelected", cdPlayer1, 1, cdPlayer1.getSongByNumber(1)), + Arguments.of("[getActualPlayTrack() after 2x next() starting by firstSong] => ThirdSongSelected","ThirdSongSelected" ,cdPlayer2,2,cdPlayer2.getSongByNumber(2)), + Arguments.of("[getActualPlayTrack() after 1x next() starting by lastSong] => FirstSongSelected","FirstSongSelected", cdPlayer3,cdPlayer3.getItemList().length,cdPlayer3.getSongByNumber(0)) ); }