Browse Source
Merge commit '33d834e7022e8fbebbe8f15124da3e92400910f6' into HEAD
feature-pr-RadioPlayer-getOptions
Merge commit '33d834e7022e8fbebbe8f15124da3e92400910f6' into HEAD
feature-pr-RadioPlayer-getOptions
Jenkins
3 years ago
5 changed files with 208 additions and 20 deletions
-
8src/main/java/device/usbPlayer/NoFolderFound.java
-
60src/main/java/device/usbPlayer/USB_Stick.java
-
50src/main/java/device/usbPlayer/UsbPlayer.java
-
71src/test/java/device/usbPlayer/USB_StickTest.java
-
39src/test/java/device/usbPlayer/UsbPlayerTest.java
@ -0,0 +1,8 @@ |
|||||
|
package device.usbPlayer; |
||||
|
|
||||
|
public class NoFolderFound extends Exception{ |
||||
|
public NoFolderFound(String message) |
||||
|
{ |
||||
|
super(message); |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
@ -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 |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue