Browse Source

Test+Productive code for case:3 of method-test next created.

feature-pr-cdPlayerNextTest
JPANZO 3 years ago
parent
commit
fce439259b
  1. 9
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 39
      src/test/java/device/cdPlayer/CDPlayerTest.java

9
src/main/java/device/cdPlayer/CDPlayer.java

@ -44,9 +44,10 @@ public class CDPlayer implements Device {
public void next() {
List<String> playList = Arrays.asList(loadedCD.getPlayList());
int indexOfActualPlayTrack=playList.indexOf(actualPlayTrack);
System.out.println("indexOfActualPlayTrack="+indexOfActualPlayTrack);
this.actualPlayTrack=playList.get(indexOfActualPlayTrack +1);
System.out.println("nextSong= "+actualPlayTrack);
int indexOfNextPlayTrack=(indexOfActualPlayTrack+1)%loadedCD.getPlayList().length;
//System.out.println("actualIndex= "+indexOfActualPlayTrack);
this.actualPlayTrack=playList.get(indexOfNextPlayTrack );
//System.out.println("nextSong= "+actualPlayTrack);
}
@Override
@ -66,7 +67,7 @@ public class CDPlayer implements Device {
@Override
public String[] getItemList() {
return new String[0];
return loadedCD.getPlayList();
}

39
src/test/java/device/cdPlayer/CDPlayerTest.java

@ -156,27 +156,44 @@ 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 <anzClicks; i++) {
_cdPlayer.next();
}
assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult);
//}
}
}
static Stream<Arguments> nextTestData () {
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"};
CD audioCD=new CD("Audio",audioPlayList);
CDPlayer cdPlayer=new CDPlayer();
cdPlayer.tapOnCdFlap();
cdPlayer.setCD(audioCD);
cdPlayer.tapOnCdFlap();
System.out.println(cdPlayer.getActualPlayTrack());
CDPlayer cdPlayer1=new CDPlayer();
cdPlayer1.tapOnCdFlap();
cdPlayer1.setCD(audioCD);
cdPlayer1.tapOnCdFlap();
CDPlayer cdPlayer2=new CDPlayer();
cdPlayer2.tapOnCdFlap();
cdPlayer2.setCD(audioCD);
cdPlayer2.tapOnCdFlap();
CDPlayer cdPlayer3=new CDPlayer();
cdPlayer3.tapOnCdFlap();
cdPlayer3.setCD(audioCD);
cdPlayer3.tapOnCdFlap();
return Stream.of(
Arguments.of("[getActualPlayTrack() after 1x next() starting by firstSong] => SecondSongSelected","SecondSongSelected", cdPlayer, 1, cdPlayer.getSongByNumber(1)),
Arguments.of("[getActualPlayTrack() after 2x next() starting by firstSong] => ThirdSongSelected","ThirdSongSelected" ,cdPlayer,1,cdPlayer.getSongByNumber(2))
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))
);
}
Loading…
Cancel
Save