From 1f04f62a72712fb1f2d4b09b5fe9a5cb75a1b74e Mon Sep 17 00:00:00 2001 From: Jan Ortner Date: Sat, 5 Feb 2022 15:51:22 +0100 Subject: [PATCH] PullRequest for RadioPlayer function prev --- src/main/java/device/RadioPlayer.java | 5 ++++- src/test/java/device/RadioPlayerTest.java | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/RadioPlayer.java b/src/main/java/device/RadioPlayer.java index 5ca1848..4fe0a05 100644 --- a/src/main/java/device/RadioPlayer.java +++ b/src/main/java/device/RadioPlayer.java @@ -56,7 +56,10 @@ public class RadioPlayer implements Device { @Override public void prev() { - + int currentIndex=Playlist.indexOf(playTrack); + int nextIndex=Playlist.size()-1; + if(currentIndex!=0){nextIndex=(currentIndex-1);} + playTrack=Playlist.get(nextIndex); } @Override diff --git a/src/test/java/device/RadioPlayerTest.java b/src/test/java/device/RadioPlayerTest.java index d206e28..edb8bd3 100644 --- a/src/test/java/device/RadioPlayerTest.java +++ b/src/test/java/device/RadioPlayerTest.java @@ -47,12 +47,16 @@ class RadioPlayerTest { int currentIndex=rp.Playlist.indexOf(rp.playTrack); assertThat(rp.playTrack).isEqualTo(rp.Playlist.get((currentIndex)%rp.Playlist.size())); } -/* + @Test void prev() { - } + rp.prev(); + int currentIndex=rp.Playlist.indexOf(rp.playTrack); + assertThat(rp.playTrack).isEqualTo(rp.Playlist.get((currentIndex)%rp.Playlist.size())); + } +/* @Test void getInfoText() { }