From 43f556fa6f01e1104ae72e6e8cc9eabaa27649f2 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Thu, 17 Feb 2022 13:50:38 +0100 Subject: [PATCH] Method changePlaySource of CDPlayer tested on activeSource=CDDrive -> shouldReturnCDWechseler. --- src/main/java/device/cdPlayer/CDPlayer.java | 13 ++++++++++--- .../java/device/cdPlayer/CDWechseler.java | 19 +++++++++++++++++++ .../java/device/cdPlayer/CDPlayerTest.java | 16 ++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/main/java/device/cdPlayer/CDWechseler.java diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 99b3b81..827d104 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -20,6 +20,9 @@ public class CDPlayer implements Device { private String actualPlayTrack=""; private CD loadedCD=null; + private CDWechseler cdWechseler; + private String activeSource="CDDrive";//or CDWechseler + @Override public void louder() { if(volume < 100) { @@ -48,9 +51,7 @@ public class CDPlayer implements Device { List playList = Arrays.asList(loadedCD.getPlayList()); int indexOfActualPlayTrack=playList.indexOf(actualPlayTrack); int indexOfNextPlayTrack=(indexOfActualPlayTrack+1)%loadedCD.getPlayList().length; - //System.out.println("actualIndex= "+indexOfActualPlayTrack); this.actualPlayTrack=playList.get(indexOfNextPlayTrack ); - //System.out.println("nextSong= "+actualPlayTrack); } @Override @@ -131,6 +132,10 @@ public class CDPlayer implements Device { } return null; } + public String changePlaySource(){ + this.activeSource="CDWechseler"; + return activeSource; + } //Getters, Setters und SupportMethods public void setCD(CD _loadedCD) { @@ -175,8 +180,10 @@ public class CDPlayer implements Device { this.infoText=this.getClass().getSimpleName()+": Item->"+actualPlayTrack+" from Album->"+this.loadedCD.getAlbumName()+" running."; } - public CD getCD() { return this.loadedCD; } + + + } diff --git a/src/main/java/device/cdPlayer/CDWechseler.java b/src/main/java/device/cdPlayer/CDWechseler.java new file mode 100644 index 0000000..1f408b1 --- /dev/null +++ b/src/main/java/device/cdPlayer/CDWechseler.java @@ -0,0 +1,19 @@ +package device.cdPlayer; + +import java.util.List; + +public class CDWechseler { + private ListCDList; + private boolean running=false; + + + public boolean isRunning() { + return running; + } + + public void activate() { + this.running = true; + } + + +} diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index 3e68055..64ea048 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -364,4 +364,20 @@ class CDPlayerTest { ); } + @ParameterizedTest + @MethodSource("changePlaySourceData") + void changePlaySourceTest(String testName,String cases, CDPlayer _cdPlayer) { + String returnVal=_cdPlayer.changePlaySource(); + assertThat(returnVal).describedAs(testName).isEqualTo("CDWechseler"); + } + static Stream changePlaySourceData () { + CDPlayer cdPlayer1 = new CDPlayer(); + + return Stream.of( + Arguments.of("[changePlaySource() by activeSource=CDDrive ] => shouldReturnCDWechseler","Case1", cdPlayer1) + ); + } + + + } \ No newline at end of file