Browse Source

Merge commit '33d834e7022e8fbebbe8f15124da3e92400910f6' into HEAD

feature-pr-RadioPlayer-getOptions
Jenkins 3 years ago
parent
commit
603b2e0029
  1. 8
      src/main/java/device/usbPlayer/NoFolderFound.java
  2. 60
      src/main/java/device/usbPlayer/USB_Stick.java
  3. 42
      src/main/java/device/usbPlayer/UsbPlayer.java
  4. 71
      src/test/java/device/usbPlayer/USB_StickTest.java
  5. 39
      src/test/java/device/usbPlayer/UsbPlayerTest.java

8
src/main/java/device/usbPlayer/NoFolderFound.java

@ -0,0 +1,8 @@
package device.usbPlayer;
public class NoFolderFound extends Exception{
public NoFolderFound(String message)
{
super(message);
}
}

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

@ -0,0 +1,60 @@
package device.usbPlayer;
import java.util.ArrayList;
import device.usbPlayer.NoFolderFound;
public class USB_Stick {
public ArrayList<ArrayList<String>> Folders = new ArrayList<>();
int currentAlbum ;
USB_Stick() {
ArrayList<String> a1 = new ArrayList<String>();
a1.add("Musik 01.mp3");
a1.add("Musik 02.mp3");
a1.add("Musik 03.mp3");
Folders.add(0,a1);
ArrayList<String> a2 = new ArrayList<String>();
a2.add("File 01.txt");
a2.add("File 02.txt");
a2.add("File 03.txt");
Folders.add(1,a2);
ArrayList<String> a3 = new ArrayList<String>();
a3.add("Photo 01.gif");
a3.add("Photo 02.gif");
a3.add("Photo 03.gif");
Folders.add(2,a3);
ArrayList<String> a4 = new ArrayList<String>();
a4.add("Music 01.mp3");
a4.add("Music 02.mp3");
a4.add("Music 03.mp3");
Folders.add(3,a4);
currentAlbum = 0;
}
USB_Stick(String a){
}
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);
}
}
public void ChangeAlbum(){
++currentAlbum;
}
}

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

@ -6,13 +6,14 @@ import java.util.ArrayList;
public class UsbPlayer implements Device {
private ArrayList<String> Playlist = new ArrayList<String>();
private String playTrack = "";
private Boolean isConnected;
private Boolean isDefect;
int Lautstaerke = 0;
public USB_Stick USBDrive = new USB_Stick();
//*********setters und getters********
public ArrayList<String> getPlaylist() {
return Playlist;
}
@ -43,7 +44,9 @@ public class UsbPlayer implements Device {
}
public void setPlayTrack(String playTrack) {
if (this.findSong(playTrack) != -1) {
this.playTrack = playTrack;
} else System.out.println("The Song does not exist in the Albume");
}
@ -62,12 +65,19 @@ public class UsbPlayer implements Device {
super();
isDefect = false;
isConnected = true;
Playlist.add("Musik 01.mp3");
/*Playlist.add("Musik 01.mp3");
Playlist.add("Musik 02.mp3");
Playlist.add("Musik 03.mp3");
playTrack = Playlist.get(0);*/
try {
Playlist = USBDrive.getAlbum();
} catch (NoFolderFound e) {
e.printStackTrace();
}
playTrack = Playlist.get(0);
}
//**********search method*************
public boolean isAllAudio() {
@ -76,7 +86,7 @@ public class UsbPlayer implements Device {
for (int i = 0; i < Playlist.size(); i++) {
song = Playlist.get(i).substring(Playlist.get(i).length() - 4);
if (song.equals(".mp3") | song.equals(".mp4")| song.equals(".m4a")| song.equals(".wav")| song.equals(".wma")| song.equals(".aac") ) {
if (song.equals(".mp3") | song.equals(".mp4") | song.equals(".m4a") | song.equals(".wav") | song.equals(".wma") | song.equals(".aac")) {
flag = true;
} else {
flag = false;
@ -85,10 +95,12 @@ public class UsbPlayer implements Device {
}
return flag;
}
//**********search method*************
@Override
public void quieter() {
if(Lautstaerke > 0) {
if (Lautstaerke > 0) {
Lautstaerke -= 1;
} else {
Lautstaerke = 0;
@ -97,21 +109,21 @@ public class UsbPlayer implements Device {
@Override
public void louder() {
if(Lautstaerke < 100) {
if (Lautstaerke < 100) {
Lautstaerke += 1;
} else {
Lautstaerke = 100;
}
}
public void Louder_10(){
public void Louder_10() {
Lautstaerke += 10;
if (Lautstaerke > 100) {
Lautstaerke = 100;
}
}
public void quieter_10(){
public void quieter_10() {
Lautstaerke -= 10;
if (Lautstaerke < 0) {
Lautstaerke = 0;
@ -198,15 +210,15 @@ public class UsbPlayer implements Device {
}
public int findSong(String songName){
public int findSong(String songName) {
int songIndex =-1, index=-1;
int songIndex = -1, index = -1;
String song;
for (int j = 0; j < getPlaylist().size(); j++) {
song = getPlaylist().get(j);
songIndex=song.toLowerCase().indexOf(songName.toLowerCase());
songIndex = song.toLowerCase().indexOf(songName.toLowerCase());
if (songIndex != -1) {
index = j;
@ -216,12 +228,11 @@ public class UsbPlayer implements Device {
return index;
}
public boolean GoTo(String songName){
if(findSong(songName) != -1){
public boolean GoTo(String songName) {
if (findSong(songName) != -1) {
playTrack = getPlaylist().get(findSong(songName));//songName;
return true;
}
else
} else
//playTrack = songName;
return false;
}
@ -232,6 +243,7 @@ public class UsbPlayer implements Device {
}
public void GoToLast() {
setPlayTrack("Musik 03.mp3");
//go to the last Song
setPlayTrack(this.getPlaylist().get(this.getPlaylist().size() - 1));
}
}

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

@ -0,0 +1,71 @@
package device.usbPlayer;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;//hasMessageMatching
import java.util.stream.Stream;
import java.util.ArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.assertj.core.api.AssertionsForClassTypes.catchThrowable;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class USB_StickTest {
@ParameterizedTest
@MethodSource("getAlbumOptions")
void getAlbumTest(String testName, USB_Stick s, int TestNr) throws NoFolderFound {
ArrayList<String> album =new ArrayList<String>();
if (TestNr == 1){
album = s.getAlbum();
assertThat(album).describedAs(testName).isNotEmpty();}
else {
// when
Throwable thrown = catchThrowable(() -> s.getAlbum());
// then
assertThat(thrown)
.isInstanceOf(NoFolderFound.class)
.hasMessageContaining("The USB Drive is empty");
}
}
static Stream<Arguments> getAlbumOptions() throws NoFolderFound {
USB_Stick stick = new USB_Stick();
USB_Stick emptyStick = new USB_Stick("");
return Stream.of(
Arguments.of("First Album is loaded", stick, 1),
Arguments.of("No Album is loaded", emptyStick, 2)
);
}
//ChangeAlbum
@ParameterizedTest
@MethodSource("ChangeAlbumOptions")
void ChangeAlbumTest(String testName, USB_Stick s) throws NoFolderFound {
ArrayList<String> a = new ArrayList<String>();
a = s.getAlbum();
assertThat(a).describedAs(testName).contains("File 01.txt", "File 02.txt", "File 03.txt");
}
static Stream<Arguments> ChangeAlbumOptions() {
USB_Stick stick = new USB_Stick();
ArrayList<String> AlbumsItems = new ArrayList<>();
stick.ChangeAlbum();
return Stream.of(
Arguments.of("First Album is loaded", stick)//,something
);
}
}

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

@ -348,9 +348,46 @@ class UsbPlayerTest {
UsbPlayer up1 = new UsbPlayer();
up1.GoToLast();
UsbPlayer up2 = new UsbPlayer();
up2.GoToLast();
up2.GoToLast();
UsbPlayer up3 = new UsbPlayer();
up3.next();
up3.GoToLast();
return Stream.of(
Arguments.of("It should go to the Last Song ", up1,up1.getPlaylist().get(up1.getPlaylist().size()-1)),
Arguments.of("It should go to the Last Song even after calling the function twice ", up2,up2.getPlaylist().get(up2.getPlaylist().size()-1)),
Arguments.of("It should go to the Last Song even changing the current song ", up3,up3.getPlaylist().get(up3.getPlaylist().size()-1))
);
}
@ParameterizedTest
@MethodSource("setPlayTrackOptions")
void setPlayTrackTest(String testName, UsbPlayer inputUSB, String expectedResult) {
String firstSong = inputUSB.getPlayTrack();
assertThat(firstSong ).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> setPlayTrackOptions() {
//first case
UsbPlayer up1 = new UsbPlayer();
up1.setPlayTrack("Musik 02.mp3");
//Second Case
UsbPlayer up2 = new UsbPlayer();
up2.setPlayTrack("Musik 02.mp3");
//Third Case
UsbPlayer up3 = new UsbPlayer();
up3.setPlayTrack("Musik 04.mp3");
return Stream.of(
Arguments.of("It should go to the first Song ", up1,"Musik 03.mp3")
Arguments.of("It should change the current Song ", up1,"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")
);
}
Loading…
Cancel
Save