diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index ff1caf2..5a55a91 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -44,8 +44,10 @@ public class CDPlayer implements Device { public void next() { List playList = Arrays.asList(loadedCD.getPlayList()); int indexOfActualPlayTrack=playList.indexOf(actualPlayTrack); - - this.actualPlayTrack=playList.get(indexOfActualPlayTrack +1); + int indexOfNextPlayTrack=(indexOfActualPlayTrack+1)%loadedCD.getPlayList().length; + //System.out.println("actualIndex= "+indexOfActualPlayTrack); + this.actualPlayTrack=playList.get(indexOfNextPlayTrack ); + //System.out.println("nextSong= "+actualPlayTrack); } @Override @@ -65,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 694460a..17bb3c0 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -156,10 +156,17 @@ 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 SecondSongSelected","SecondSongSelected", cdPlayer, 1, cdPlayer.getSongByNumber(1)) + 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)) ); }