From c5c7ea8c954b269d4335367ecc87594fca63efa9 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Wed, 16 Feb 2022 22:39:08 +0100 Subject: [PATCH] Method getInfoText of CDPlayer tested on MessageShouldContainInfoAboutAlbum. --- src/main/java/device/cdPlayer/CD.java | 9 +++++++++ src/main/java/device/cdPlayer/CDPlayer.java | 7 +++++-- src/test/java/device/cdPlayer/CDPlayerTest.java | 11 +++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/device/cdPlayer/CD.java b/src/main/java/device/cdPlayer/CD.java index e1f61b3..4934ac2 100644 --- a/src/main/java/device/cdPlayer/CD.java +++ b/src/main/java/device/cdPlayer/CD.java @@ -2,6 +2,7 @@ package device.cdPlayer; public class CD { private String format; + private String albumName; private String[] playList; public CD() {} @@ -30,4 +31,12 @@ public class CD { public void setPlayList(String[] playList) { this.playList = playList; } + + public String getAlbumName() { + return albumName; + } + + public void setAlbumName(String albumName) { + this.albumName = albumName; + } } diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index 14ace41..07bb170 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -161,9 +161,12 @@ public class CDPlayer implements Device { return actualPlayTrack; } - public void setInfoText(String infoText) { - this.infoText=infoText; + public void setInfoText() { + this.infoText="CDPlayer: Item->"+actualPlayTrack+" from Album->"+this.loadedCD.getAlbumName()+" running."; } + public CD getCD() { + return this.loadedCD; + } } diff --git a/src/test/java/device/cdPlayer/CDPlayerTest.java b/src/test/java/device/cdPlayer/CDPlayerTest.java index e6b26e9..8b9064e 100644 --- a/src/test/java/device/cdPlayer/CDPlayerTest.java +++ b/src/test/java/device/cdPlayer/CDPlayerTest.java @@ -296,6 +296,11 @@ class CDPlayerTest { } assertThat(containsInfoOfActualPlayTrack).describedAs(testName).isEqualTo(true); } + if(cases.equals("Case4")) { + String albumName= _cdPlayer.getCD().getAlbumName(); + assertThat(_cdPlayer.getInfoText().contains(albumName)).describedAs(testName).isEqualTo(true); + } + } static Stream getInfoTestData () { CDPlayer cdPlayer1 = new CDPlayer(); @@ -303,16 +308,18 @@ class CDPlayerTest { String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; //some CDs CD audioCD1=new CD("Audio",audioPlayList); + audioCD1.setAlbumName("Love Songs"); CDPlayer cdPlayer2 = new CDPlayer(); cdPlayer2.tapOnCdFlap(); cdPlayer2.setCD(audioCD1); cdPlayer2.tapOnCdFlap(); - cdPlayer2.setInfoText("CDPlayer: Item->"+cdPlayer2.getActualPlayTrack()+" from Album->"+"AlbumName"+" running."); + cdPlayer2.setInfoText(); return Stream.of( Arguments.of("[getInfoText() by infoText=null ] => shouldThrowReturnValueNullException","Case1", cdPlayer1,new ReturnValueNullException(),""), Arguments.of("[getInfoText() by infoText=null ] => ExceptionShouldReturnAMessage","Case2",cdPlayer1,new ReturnValueNullException(),"Method should not return a Null-Value."), - Arguments.of("[getInfoText() by infoText=Message ] => MessageShouldContainInfoOfActualPlayTrack","Case3",cdPlayer2,null,"") + Arguments.of("[getInfoText() by infoText=Message ] => MessageShouldContainInfoOfActualPlayTrack","Case3",cdPlayer2,null,""), + Arguments.of("[getInfoText() by infoText=Message ] => MessageShouldContainInfoAboutAlbum","Case4",cdPlayer2,null,"") ); }