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. 9
      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(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{ public ArrayList<String> getAlbum() throws NoFolderFound{
if(Folders.size()==0) { if(Folders.size()==0) {
System.out.println("list ist leer");
throw new NoFolderFound("The USB Drive is empty"); throw new NoFolderFound("The USB Drive is empty");
} }
else { else {
System.out.println("nicht leer");
return Folders.get(currentAlbum); return Folders.get(currentAlbum);
} }
} }

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

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

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

@ -47,7 +47,6 @@ class USB_StickTest {
); );
} }
//ChangeAlbum
@ParameterizedTest @ParameterizedTest
@MethodSource("ChangeAlbumOptions") @MethodSource("ChangeAlbumOptions")
void ChangeAlbumTest(String testName, USB_Stick s) throws NoFolderFound { 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 { class UsbPlayerTest {
UsbPlayer up = new UsbPlayer();
//UsbPlayer up = new UsbPlayer();
@ParameterizedTest @ParameterizedTest
@MethodSource("PlayOptions") @MethodSource("PlayOptions")
@ -21,21 +21,22 @@ class UsbPlayerTest {
} }
static Stream<Arguments> PlayOptions() { 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(""); up8.setPlayTrack("");
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
ArrayList<String> l = new ArrayList<String>(); ArrayList<String> l = new ArrayList<String>();
l.add("a.mp3"); l.add("a.mp3");
l.add("b.mp3"); l.add("b.mp3");
l.add("c.gif"); l.add("c.gif");
up2.setPlaylist(l); up2.setPlaylist(l);
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
ArrayList<String> Pl = new ArrayList<String>(); ArrayList<String> Pl = new ArrayList<String>();
up3.setPlaylist(Pl); up3.setPlaylist(Pl);
UsbPlayer up6 = new UsbPlayer();
UsbPlayer up6 = new UsbPlayer(USBDrive);
up6.setDefect(true); up6.setDefect(true);
UsbPlayer up7 = new UsbPlayer();
UsbPlayer up7 = new UsbPlayer(USBDrive);
up7.setConnected(false); up7.setConnected(false);
@ -57,9 +58,10 @@ class UsbPlayerTest {
} }
static Stream<Arguments> louderOptions() { static Stream<Arguments> louderOptions() {
UsbPlayer up11 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up11 = new UsbPlayer(USBDrive);
up11.louder(); up11.louder();
UsbPlayer up22 = new UsbPlayer();
UsbPlayer up22 = new UsbPlayer(USBDrive);
up22.setLautstaerke(100); up22.setLautstaerke(100);
up22.louder(); up22.louder();
return Stream.of( return Stream.of(
@ -76,9 +78,10 @@ class UsbPlayerTest {
} }
static Stream<Arguments> quieterOptions() { static Stream<Arguments> quieterOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.quieter(); up1.quieter();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.setLautstaerke(10); up2.setLautstaerke(10);
up2.quieter(); up2.quieter();
return Stream.of( return Stream.of(
@ -96,13 +99,14 @@ class UsbPlayerTest {
} }
static Stream<Arguments> NextOptions() { static Stream<Arguments> NextOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.next(); up1.next();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
for (int i = 1; i < up2.getPlaylist().size(); i++) { for (int i = 1; i < up2.getPlaylist().size(); i++) {
up2.next(); up2.next();
} }
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
for (int i = 1; i < up3.getPlaylist().size(); i++) { for (int i = 1; i < up3.getPlaylist().size(); i++) {
up3.next(); up3.next();
} }
@ -123,9 +127,10 @@ class UsbPlayerTest {
} }
static Stream<Arguments> PrevOptions() { static Stream<Arguments> PrevOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.prev(); up1.prev();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
for (int i = 1; i < up2.getPlaylist().size(); i++) {//3 for (int i = 1; i < up2.getPlaylist().size(); i++) {//3
up2.prev(); up2.prev();
} }
@ -145,16 +150,17 @@ class UsbPlayerTest {
} }
static Stream<Arguments> louder_10_Options() { static Stream<Arguments> louder_10_Options() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.Louder_10(); up1.Louder_10();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
for (int i = 0; i <= 3; i++) { for (int i = 0; i <= 3; i++) {
up2.Louder_10(); up2.Louder_10();
} }
up2.quieter_10(); up2.quieter_10();
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.setLautstaerke(100); up3.setLautstaerke(100);
up3.Louder_10(); up3.Louder_10();
return Stream.of( return Stream.of(
@ -172,17 +178,18 @@ class UsbPlayerTest {
} }
static Stream<Arguments> quieter_10_Options() { 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.setLautstaerke(10);
up1.quieter_10(); up1.quieter_10();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.setLautstaerke(50); up2.setLautstaerke(50);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
up2.quieter_10(); up2.quieter_10();
} }
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.quieter_10(); up3.quieter_10();
return Stream.of( return Stream.of(
@ -205,7 +212,8 @@ class UsbPlayerTest {
} }
static Stream<Arguments> FindSongOptions() { static Stream<Arguments> FindSongOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
return Stream.of( return Stream.of(
Arguments.of("The song is not in the Album", up1.findSong("song 4"), -1), 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), Arguments.of("The song is in the Album", up1.findSong("Musik 02"), 1),
@ -222,16 +230,17 @@ class UsbPlayerTest {
} }
static Stream<Arguments> GoToOptions() { static Stream<Arguments> GoToOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.GoTo("Musik 03.mp3"); up1.GoTo("Musik 03.mp3");
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.GoTo("Musik 04.mp3"); up2.GoTo("Musik 04.mp3");
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.GoTo("Musik 02"); up3.GoTo("Musik 02");
UsbPlayer up4 = new UsbPlayer();
UsbPlayer up4 = new UsbPlayer(USBDrive);
up4.next(); up4.next();
up4.GoTo("Musik"); up4.GoTo("Musik");
@ -252,45 +261,46 @@ class UsbPlayerTest {
} }
static Stream<Arguments> isAllAudioOptions() { static Stream<Arguments> isAllAudioOptions() {
USB_Stick USBDrive = new USB_Stick();
//mp3 //mp3
UsbPlayer up1 = new UsbPlayer();
UsbPlayer up1 = new UsbPlayer(USBDrive);
//mp4 //mp4
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
ArrayList<String> Pl = new ArrayList<String>(); ArrayList<String> Pl = new ArrayList<String>();
Pl.add("Musik 01.mp4"); Pl.add("Musik 01.mp4");
Pl.add("Musik 02.mp4"); Pl.add("Musik 02.mp4");
Pl.add("Musik 03.mp4"); Pl.add("Musik 03.mp4");
up2.setPlaylist(Pl); up2.setPlaylist(Pl);
//m4a //m4a
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
ArrayList<String> Pl1 = new ArrayList<String>(); ArrayList<String> Pl1 = new ArrayList<String>();
Pl1.add("Musik 01.m4a"); Pl1.add("Musik 01.m4a");
Pl1.add("Musik 02.m4a"); Pl1.add("Musik 02.m4a");
Pl1.add("Musik 03.m4a"); Pl1.add("Musik 03.m4a");
up3.setPlaylist(Pl1); up3.setPlaylist(Pl1);
//wav //wav
UsbPlayer up4 = new UsbPlayer();
UsbPlayer up4 = new UsbPlayer(USBDrive);
ArrayList<String> Pl2 = new ArrayList<String>(); ArrayList<String> Pl2 = new ArrayList<String>();
Pl2.add("Musik 01.wav"); Pl2.add("Musik 01.wav");
Pl2.add("Musik 02.wav"); Pl2.add("Musik 02.wav");
Pl2.add("Musik 03.wav"); Pl2.add("Musik 03.wav");
up4.setPlaylist(Pl2); up4.setPlaylist(Pl2);
//wma //wma
UsbPlayer up5 = new UsbPlayer();
UsbPlayer up5 = new UsbPlayer(USBDrive);
ArrayList<String> Pl3 = new ArrayList<String>(); ArrayList<String> Pl3 = new ArrayList<String>();
Pl3.add("Musik 01.wma"); Pl3.add("Musik 01.wma");
Pl3.add("Musik 02.wma"); Pl3.add("Musik 02.wma");
Pl3.add("Musik 03.wma"); Pl3.add("Musik 03.wma");
up5.setPlaylist(Pl3); up5.setPlaylist(Pl3);
//aac //aac
UsbPlayer up6 = new UsbPlayer();
UsbPlayer up6 = new UsbPlayer(USBDrive);
ArrayList<String> Pl4 = new ArrayList<String>(); ArrayList<String> Pl4 = new ArrayList<String>();
Pl4.add("Musik 01.aac"); Pl4.add("Musik 01.aac");
Pl4.add("Musik 02.aac"); Pl4.add("Musik 02.aac");
Pl4.add("Musik 03.aac"); Pl4.add("Musik 03.aac");
up6.setPlaylist(Pl4); up6.setPlaylist(Pl4);
//mixed Audio and text Files in the Album //mixed Audio and text Files in the Album
UsbPlayer up7 = new UsbPlayer();
UsbPlayer up7 = new UsbPlayer(USBDrive);
ArrayList<String> Pl5 = new ArrayList<String>(); ArrayList<String> Pl5 = new ArrayList<String>();
Pl5.add("Musik 01.aac"); Pl5.add("Musik 01.aac");
Pl5.add("Musik 02.txt"); Pl5.add("Musik 02.txt");
@ -318,14 +328,15 @@ class UsbPlayerTest {
} }
static Stream<Arguments> GoToFirstOptions() { static Stream<Arguments> GoToFirstOptions() {
UsbPlayer up1 = new UsbPlayer();
USB_Stick USBDrive = new USB_Stick();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.GoToFirst(); up1.GoToFirst();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.GoToFirst(); up2.GoToFirst();
up2.GoToFirst(); up2.GoToFirst();
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.next(); up3.next();
up3.GoToFirst(); up3.GoToFirst();
@ -344,15 +355,16 @@ class UsbPlayerTest {
} }
static Stream<Arguments> GoToLastOptions() { static Stream<Arguments> GoToLastOptions() {
USB_Stick USBDrive = new USB_Stick();
//first case //first case
UsbPlayer up1 = new UsbPlayer();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.GoToLast(); up1.GoToLast();
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.GoToLast(); up2.GoToLast();
up2.GoToLast(); up2.GoToLast();
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.next(); up3.next();
up3.GoToLast(); up3.GoToLast();
@ -372,16 +384,17 @@ class UsbPlayerTest {
} }
static Stream<Arguments> setPlayTrackOptions() { static Stream<Arguments> setPlayTrackOptions() {
USB_Stick USBDrive = new USB_Stick();
//first case //first case
UsbPlayer up1 = new UsbPlayer();
UsbPlayer up1 = new UsbPlayer(USBDrive);
up1.setPlayTrack("Musik 02.mp3"); up1.setPlayTrack("Musik 02.mp3");
//Second Case //Second Case
UsbPlayer up2 = new UsbPlayer();
UsbPlayer up2 = new UsbPlayer(USBDrive);
up2.setPlayTrack("Musik 02.mp3"); up2.setPlayTrack("Musik 02.mp3");
//Third Case //Third Case
UsbPlayer up3 = new UsbPlayer();
UsbPlayer up3 = new UsbPlayer(USBDrive);
up3.setPlayTrack("Musik 04.mp3"); up3.setPlayTrack("Musik 04.mp3");
return Stream.of( 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("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") 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