Browse Source

Merge commit '15ddf95671998e3ed736d151e654817feada8328' into HEAD

feature-pr-cdPlayerGetOptions
Jenkins 3 years ago
parent
commit
1310253866
  1. 12
      src/main/java/device/usbPlayer/UsbPlayer.java
  2. 111
      src/test/java/device/usbPlayer/UsbPlayerTest.java

12
src/main/java/device/usbPlayer/UsbPlayer.java

@ -69,14 +69,14 @@ public class UsbPlayer implements Device {
} }
//**********search method************* //**********search method*************
private boolean isAllAudio() {
public boolean isAllAudio() {
String song = ""; String song = "";
boolean flag = true; boolean flag = true;
for (int i = 0; i < Playlist.size(); i++) { for (int i = 0; i < Playlist.size(); i++) {
song = Playlist.get(i).substring(Playlist.get(i).length() - 4); song = Playlist.get(i).substring(Playlist.get(i).length() - 4);
if (song.equals(".mp3") | song.equals(".mp4") | song.equals(".wav")) {
if (song.equals(".mp3") | song.equals(".mp4")| song.equals(".m4a")| song.equals(".wav")| song.equals(".wma")| song.equals(".aac") ) {
flag = true; flag = true;
} else { } else {
flag = false; flag = false;
@ -211,4 +211,12 @@ public class UsbPlayer implements Device {
return false; return false;
} }
public void GoToFirst() {
//go to the first song in the list
setPlayTrack(getPlaylist().get(0));
}
public void GoToLast() {
setPlayTrack("Musik 03.mp3");
}
} }

111
src/test/java/device/usbPlayer/UsbPlayerTest.java

@ -3,6 +3,7 @@ package device.usbPlayer;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.ArrayList; import java.util.ArrayList;
@ -162,6 +163,7 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) {
Arguments.of("Volume was 100, should stay 100 ", up3, 100) Arguments.of("Volume was 100, should stay 100 ", up3, 100)
); );
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("quieter_10_Options") @MethodSource("quieter_10_Options")
void quieter_10_Test(String testName, UsbPlayer inputPlay, int expectedResult) { void quieter_10_Test(String testName, UsbPlayer inputPlay, int expectedResult) {
@ -242,5 +244,114 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) {
); );
} }
@ParameterizedTest
@MethodSource("isAllAudioOptions")
void isAllAudioTest(String testName, boolean inputTestResult, boolean expectedResult) {
// String current_Track = inputPlay.getPlayTrack();
assertThat(inputTestResult).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> isAllAudioOptions() {
//mp3
UsbPlayer up1 = new UsbPlayer();
//mp4
UsbPlayer up2 = new UsbPlayer();
ArrayList<String> Pl = new ArrayList<String>();
Pl.add("Musik 01.mp4");
Pl.add("Musik 02.mp4");
Pl.add("Musik 03.mp4");
up2.setPlaylist(Pl);
//m4a
UsbPlayer up3 = new UsbPlayer();
ArrayList<String> Pl1 = new ArrayList<String>();
Pl1.add("Musik 01.m4a");
Pl1.add("Musik 02.m4a");
Pl1.add("Musik 03.m4a");
up3.setPlaylist(Pl1);
//wav
UsbPlayer up4 = new UsbPlayer();
ArrayList<String> Pl2 = new ArrayList<String>();
Pl2.add("Musik 01.wav");
Pl2.add("Musik 02.wav");
Pl2.add("Musik 03.wav");
up4.setPlaylist(Pl2);
//wma
UsbPlayer up5 = new UsbPlayer();
ArrayList<String> Pl3 = new ArrayList<String>();
Pl3.add("Musik 01.wma");
Pl3.add("Musik 02.wma");
Pl3.add("Musik 03.wma");
up5.setPlaylist(Pl3);
//aac
UsbPlayer up6 = new UsbPlayer();
ArrayList<String> Pl4 = new ArrayList<String>();
Pl4.add("Musik 01.aac");
Pl4.add("Musik 02.aac");
Pl4.add("Musik 03.aac");
up6.setPlaylist(Pl4);
//mixed Audio and text Files in the Album
UsbPlayer up7 = new UsbPlayer();
ArrayList<String> Pl5 = new ArrayList<String>();
Pl5.add("Musik 01.aac");
Pl5.add("Musik 02.txt");
Pl5.add("Musik 03.aac");
up7.setPlaylist(Pl5);
return Stream.of(
Arguments.of("Check if the Files are .mp3 ", up1.isAllAudio(), true),
Arguments.of("Check if the Files are .mp4 ", up2.isAllAudio(), true),
Arguments.of("Check if the Files are .m4a ", up3.isAllAudio(), true),
Arguments.of("Check if the Files are .wav ", up4.isAllAudio(), true),
Arguments.of("Check if the Files are .wma ", up5.isAllAudio(), true),
Arguments.of("Check if the Files are .aac ", up6.isAllAudio(), true),
Arguments.of("Check case of mixed Files", up7.isAllAudio(), false)
);
}
//GoToFirst()
@ParameterizedTest
@MethodSource("GoToFirstOptions")
void GoToFirstTest(String testName, UsbPlayer inputUSB, String expectedResult) {
String firstSong = inputUSB.getPlayTrack();
assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> GoToFirstOptions() {
UsbPlayer up1 = new UsbPlayer();
up1.GoToFirst();
UsbPlayer up2 = new UsbPlayer();
up2.GoToFirst();
up2.GoToFirst();
UsbPlayer up3 = new UsbPlayer();
up3.next();
up3.GoToFirst();
return Stream.of(
Arguments.of("It should go to the first Song ", up1,up1.getPlaylist().get(0)),
Arguments.of("Call the function twice and it stills go to the first Song ", up2,up2.getPlaylist().get(0)),
Arguments.of("go to the next Song then back to first Song ", up3,up3.getPlaylist().get(0))
);
}
@ParameterizedTest
@MethodSource("GoToLastOptions")
void GoToLastTest(String testName, UsbPlayer inputUSB, String expectedResult) {
String firstSong = inputUSB.getPlayTrack();
assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> GoToLastOptions() {
//first case
UsbPlayer up1 = new UsbPlayer();
up1.GoToLast();
return Stream.of(
Arguments.of("It should go to the first Song ", up1,"Musik 03.mp3")
);
}
} }
Loading…
Cancel
Save