From d5b13dadc8b57b1d4ebb73dce23c7b406e771cf9 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Tue, 15 Feb 2022 18:15:45 +0100 Subject: [PATCH] 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