Browse Source

UsbPlayerTest.getInfoTextTest First Case

feature-pr-USB-otherTests
sahar 3 years ago
parent
commit
69cbbf90fa
  1. 16
      src/main/java/device/usbPlayer/USB_Stick.java
  2. 11
      src/main/java/device/usbPlayer/UsbPlayer.java
  3. 3
      src/test/java/device/usbPlayer/USB_StickTest.java
  4. 119
      src/test/java/device/usbPlayer/UsbPlayerTest.java

16
src/main/java/device/usbPlayer/USB_Stick.java

@ -39,14 +39,26 @@ public class USB_Stick {
USB_Stick(String a){
}
USB_Stick(ArrayList<String> a1) {
Folders.add(a1);
currentAlbum = 0;
for (int i = 0; i < Folders.size(); i++) {
for (int j = 0; j < Folders.get(0).size(); j++) {
System.out.println("the song is "+Folders.get(0).get(j)+"\n");
}
}
}
public ArrayList<String> getAlbum() throws NoFolderFound{
if(Folders.size()==0) {
System.out.println("list ist leer");
throw new NoFolderFound("The USB Drive is empty");
}
else {
System.out.println("nicht leer");
return Folders.get(currentAlbum);
}
}

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

@ -61,7 +61,7 @@ public class UsbPlayer implements Device {
}
//*********constructure********
public UsbPlayer() {
public UsbPlayer(USB_Stick stick) {
super();
isDefect = false;
isConnected = true;
@ -70,11 +70,13 @@ public class UsbPlayer implements Device {
Playlist.add("Musik 03.mp3");
playTrack = Playlist.get(0);*/
try {
Playlist = USBDrive.getAlbum();
Playlist = stick.getAlbum();
} catch (NoFolderFound e) {
e.printStackTrace();
}
playTrack = Playlist.get(0);
if (isAllAudio()) {
playTrack = Playlist.get(0);
}
}
@ -154,7 +156,8 @@ public class UsbPlayer implements Device {
@Override
public String getInfoText() {
return null;
return "USB Player is on : "+this.getPlayTrack();
}
@Override

3
src/test/java/device/usbPlayer/USB_StickTest.java

@ -47,7 +47,6 @@ class USB_StickTest {
);
}
//ChangeAlbum
@ParameterizedTest
@MethodSource("ChangeAlbumOptions")
void ChangeAlbumTest(String testName, USB_Stick s) throws NoFolderFound {
@ -68,4 +67,6 @@ class USB_StickTest {
);
}
}

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

@ -11,7 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class UsbPlayerTest {
UsbPlayer up = new UsbPlayer();
//UsbPlayer up = new UsbPlayer();
@ParameterizedTest
@MethodSource("PlayOptions")
@ -21,21 +21,22 @@ class UsbPlayerTest {
}
static Stream<Arguments> PlayOptions() {
UsbPlayer up1 = new UsbPlayer();
UsbPlayer up8 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
UsbPlayer up8 = new UsbPlayer(USBDrive);
up8.setPlayTrack("");
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
ArrayList<String> l = new ArrayList<String>();
l.add("a.mp3");
l.add("b.mp3");
l.add("c.gif");
up2.setPlaylist(l);
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
ArrayList<String> Pl = new ArrayList<String>();
up3.setPlaylist(Pl);
UsbPlayer up6 = new UsbPlayer();
UsbPlayer up6 = new UsbPlayer(USBDrive);
up6.setDefect(true);
UsbPlayer up7 = new UsbPlayer();
UsbPlayer up7 = new UsbPlayer(USBDrive);
up7.setConnected(false);
@ -57,9 +58,10 @@ class UsbPlayerTest {
}
static Stream<Arguments> louderOptions() {
UsbPlayer up11 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up11 = new UsbPlayer(USBDrive);
up11.louder();
UsbPlayer up22 = new UsbPlayer();
UsbPlayer up22 = new UsbPlayer(USBDrive);
up22.setLautstaerke(100);
up22.louder();
return Stream.of(
@ -76,9 +78,10 @@ class UsbPlayerTest {
}
static Stream<Arguments> quieterOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.quieter();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.setLautstaerke(10);
up2.quieter();
return Stream.of(
@ -96,13 +99,14 @@ class UsbPlayerTest {
}
static Stream<Arguments> NextOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.next();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
for (int i = 1; i < up2.getPlaylist().size(); i++) {
up2.next();
}
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
for (int i = 1; i < up3.getPlaylist().size(); i++) {
up3.next();
}
@ -123,9 +127,10 @@ class UsbPlayerTest {
}
static Stream<Arguments> PrevOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.prev();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
for (int i = 1; i < up2.getPlaylist().size(); i++) {//3
up2.prev();
}
@ -145,16 +150,17 @@ class UsbPlayerTest {
}
static Stream<Arguments> louder_10_Options() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.Louder_10();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
for (int i = 0; i <= 3; i++) {
up2.Louder_10();
}
up2.quieter_10();
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.setLautstaerke(100);
up3.Louder_10();
return Stream.of(
@ -172,17 +178,18 @@ class UsbPlayerTest {
}
static Stream<Arguments> quieter_10_Options() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.setLautstaerke(10);
up1.quieter_10();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.setLautstaerke(50);
for (int i = 0; i < 3; i++) {
up2.quieter_10();
}
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.quieter_10();
return Stream.of(
@ -205,7 +212,8 @@ class UsbPlayerTest {
}
static Stream<Arguments> FindSongOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
return Stream.of(
Arguments.of("The song is not in the Album", up1.findSong("song 4"), -1),
Arguments.of("The song is in the Album", up1.findSong("Musik 02"), 1),
@ -222,16 +230,17 @@ class UsbPlayerTest {
}
static Stream<Arguments> GoToOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.GoTo("Musik 03.mp3");
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.GoTo("Musik 04.mp3");
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.GoTo("Musik 02");
UsbPlayer up4 = new UsbPlayer();
UsbPlayer up4 = new UsbPlayer(USBDrive);
up4.next();
up4.GoTo("Musik");
@ -252,45 +261,46 @@ class UsbPlayerTest {
}
static Stream<Arguments> isAllAudioOptions() {
USB_Stick USBDrive = new USB_Stick();
//mp3
UsbPlayer up1 = new UsbPlayer();
UsbPlayer up1 = new UsbPlayer(USBDrive);
//mp4
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
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();
UsbPlayer up3 = new UsbPlayer(USBDrive);
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();
UsbPlayer up4 = new UsbPlayer(USBDrive);
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();
UsbPlayer up5 = new UsbPlayer(USBDrive);
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();
UsbPlayer up6 = new UsbPlayer(USBDrive);
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();
UsbPlayer up7 = new UsbPlayer(USBDrive);
ArrayList<String> Pl5 = new ArrayList<String>();
Pl5.add("Musik 01.aac");
Pl5.add("Musik 02.txt");
@ -318,14 +328,15 @@ class UsbPlayerTest {
}
static Stream<Arguments> GoToFirstOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.GoToFirst();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.GoToFirst();
up2.GoToFirst();
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.next();
up3.GoToFirst();
@ -344,15 +355,16 @@ class UsbPlayerTest {
}
static Stream<Arguments> GoToLastOptions() {
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up1 = new UsbPlayer();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.GoToLast();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.GoToLast();
up2.GoToLast();
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.next();
up3.GoToLast();
@ -372,16 +384,17 @@ class UsbPlayerTest {
}
static Stream<Arguments> setPlayTrackOptions() {
USB_Stick USBDrive = new USB_Stick();
//first case
UsbPlayer up1 = new UsbPlayer();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.setPlayTrack("Musik 02.mp3");
//Second Case
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.setPlayTrack("Musik 02.mp3");
//Third Case
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.setPlayTrack("Musik 04.mp3");
return Stream.of(
@ -389,6 +402,26 @@ class UsbPlayerTest {
Arguments.of("It should change the current Song if it is in the Albume", up2,"Musik 02.mp3"),
Arguments.of("Tried to change the Song,but the Song name does not exist in the Album(No change)", up3,"Musik 01.mp3")
);
}////
@ParameterizedTest
@MethodSource("getInfoTextOptions")
void getInfoTextTest(String testName, UsbPlayer inputUSB, String expectedResult) {
String infotxt = inputUSB.getInfoText();
assertThat(infotxt ).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> getInfoTextOptions() {
USB_Stick USBDrive = new USB_Stick();
//USB_Stick emptyUSB = new USB_Stick("");
//first case
UsbPlayer up1 = new UsbPlayer(USBDrive);
return Stream.of(
Arguments.of("USB Player with Albums ", up1,"USB Player is on : "+up1.getPlayTrack())
);
}
}
Loading…
Cancel
Save