Browse Source

Merge remote-tracking branch 'origin/master'

feature-pr-USB-NextTest
sahar 3 years ago
parent
commit
801b9160f6
  1. 7
      Geraete.config
  2. 50
      src/main/java/device/CDPlayer.java
  3. 33
      src/main/java/device/cdPlayer/CD.java
  4. 87
      src/main/java/device/cdPlayer/CDPlayer.java
  5. 8
      src/main/java/device/cdPlayer/exceptions/CdFlapIsOpenException.java
  6. 8
      src/main/java/device/cdPlayer/exceptions/FormatNotSupportedException.java
  7. 8
      src/main/java/device/cdPlayer/exceptions/NoCDException.java
  8. 4
      src/main/java/device/radioPlayer/RadioPlayer.java
  9. 4
      src/main/java/device/usbPlayer/UsbPlayer.java
  10. 46
      src/test/java/device/CDPlayerTest.java
  11. 52
      src/test/java/device/cdPlayer/CDPlayerTest.java
  12. 4
      src/test/java/device/radioPlayer/RadioPlayerTest.java
  13. 2
      src/test/java/device/usbPlayer/UsbPlayerTest.java

7
Geraete.config

@ -1,3 +1,4 @@
CD=device.CdPlayer
Radio=device.RadioPlayer
USB=device.UsbPlayer
CD=device.cdPlayer.CdPlayer
Radio=device.radioPlayer.RadioPlayer
USB=device.usbPlayer.UsbPlayer

50
src/main/java/device/CDPlayer.java

@ -1,50 +0,0 @@
package device;
public class CDPlayer implements Device {
@Override
public void louder() {
}
@Override
public void quieter() {
}
@Override
public int getVolume() {
return 0;
}
@Override
public void next() {
}
@Override
public void prev() {
}
@Override
public String getInfoText() {
return null;
}
@Override
public String[] getOptions() {
return new String[0];
}
@Override
public String[] getItemList() {
return new String[0];
}
@Override
public String play() {
return null;
}
}

33
src/main/java/device/cdPlayer/CD.java

@ -0,0 +1,33 @@
package device.cdPlayer;
public class CD {
private String format;
private String[] playList;
public CD() {}
public CD(String format) {
this.format = format;
}
public CD(String format, String[] playList) {
this.format = format;
this.playList = playList;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
public String[] getPlayList() {
return playList;
}
public void setPlayList(String[] playList) {
this.playList = playList;
}
}

87
src/main/java/device/cdPlayer/CDPlayer.java

@ -0,0 +1,87 @@
package device.cdPlayer;
import device.Device;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CDPlayer implements Device {
// 0-Leer; true-1
private int CdDriveContent=0;
private int CdFlap=0;
private int volume = 0;
private List<String> supportedFormats = new ArrayList<String>(Arrays.asList(new String[] {"Audio","MP3","WMA","AAC"}));
private String actualPlayTrack="";
private CD loadedCD;
private String[] cdAlbum=new String[]{};
@Override
public void louder() {
if(volume < 100) {
volume += 1;
} else {
volume = 100;
}
}
@Override
public void quieter() {
if(volume > 0) {
volume -= 1;
} else {
volume = 0;
}
}
@Override
public int getVolume() {
return volume;
}
@Override
public void next() {
}
@Override
public void prev() {
}
@Override
public String getInfoText() {
return null;
}
@Override
public String[] getOptions() {
return new String[0];
}
@Override
public String[] getItemList() {
return new String[0];
}
@Override
public String play() {
return null;
}
//Getters und Setters
public void setCD(CD _loadedCD) {
loadedCD=_loadedCD;
this.setCdDriveContent();
this.actualPlayTrack=loadedCD.getPlayList()[0];
}
private void setCdDriveContent() {
CdDriveContent = 1;
}
}

8
src/main/java/device/cdPlayer/exceptions/CdFlapIsOpenException.java

@ -0,0 +1,8 @@
package device.cdPlayer.exceptions;
public class CdFlapIsOpenException extends RuntimeException{
//String message="Cd Flap must be closed.";
public CdFlapIsOpenException() {
super("Cd Flap must be closed.");
}
}

8
src/main/java/device/cdPlayer/exceptions/FormatNotSupportedException.java

@ -0,0 +1,8 @@
package device.cdPlayer.exceptions;
public class FormatNotSupportedException extends RuntimeException{
//String message="Cd-Format not supported.";
public FormatNotSupportedException() {
super("Cd-Format not supported.");
}
}

8
src/main/java/device/cdPlayer/exceptions/NoCDException.java

@ -0,0 +1,8 @@
package device.cdPlayer.exceptions;
public class NoCDException extends RuntimeException {
//String message="CD must be set.";
public NoCDException() {
super("CD must be set.");
}
}

4
src/main/java/device/RadioPlayer.java → src/main/java/device/radioPlayer/RadioPlayer.java

@ -1,4 +1,6 @@
package device;
package device.radioPlayer;
import device.Device;
import java.util.ArrayList; import java.util.ArrayList;

4
src/main/java/device/UsbPlayer.java → src/main/java/device/usbPlayer/UsbPlayer.java

@ -1,4 +1,6 @@
package device;
package device.usbPlayer;
import device.Device;
public class UsbPlayer implements Device { public class UsbPlayer implements Device {

46
src/test/java/device/CDPlayerTest.java

@ -1,46 +0,0 @@
package device;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class CDPlayerTest {
/*
@Test
void louder() {
}
@Test
void quieter() {
}
@Test
void getVolume() {
}
@Test
void next() {
}
@Test
void prev() {
}
@Test
void getInfoText() {
}
@Test
void getOptions() {
}
@Test
void chooseOption() {
}
@Test
void play() {
}
*/
}

52
src/test/java/device/cdPlayer/CDPlayerTest.java

@ -0,0 +1,52 @@
package device.cdPlayer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(MockitoExtension.class)
class CDPlayerTest {
@ParameterizedTest
@MethodSource("quieterTestData")
void quieterTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, int expectedResult) {
for (int i = 0; i < anzClicks; i++) {
_cdPlayer.quieter();
}
if(testDirection.equals("VolumeDecreased")){
for (int i = 0; i < 20; i++) {
_cdPlayer.louder();
}
for (int i = 0; i < anzClicks; i++) {
_cdPlayer.quieter();
}
assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(expectedResult);
}
if(testDirection.equals("VolumeHasNotChanged")){
assertThat(_cdPlayer.getVolume()).describedAs(testName).isEqualTo(expectedResult);
}if(testDirection.equals("VolumeNotIncreased")){
assertThat(_cdPlayer.getVolume()).describedAs(testName).isNotEqualTo(expectedResult);
}
}
static Stream<Arguments> quieterTestData () {
CDPlayer cdPlayer=new CDPlayer();
return Stream.of(
Arguments.of("[getVolume() after 20x quieter() starting by 20] => VolumeHasDecreased","VolumeDecreased", cdPlayer, 19, 1),
Arguments.of("[getVolume() after 20x quieter() starting by 0] => VolumeHasNotChanged","VolumeHasNotChanged" ,cdPlayer,20,0),
Arguments.of("[getVolume() after 5x quieter() starting by 0] => VolumeNotIncreased","VolumeNotIncreased", cdPlayer,5,5)
);
}
}

4
src/test/java/device/RadioPlayerTest.java → src/test/java/device/radioPlayer/RadioPlayerTest.java

@ -1,5 +1,7 @@
package device;
package device.radioPlayer;
import device.radioPlayer.RadioPlayer;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;

2
src/test/java/device/UsbPlayerTest.java → src/test/java/device/usbPlayer/UsbPlayerTest.java

@ -1,4 +1,4 @@
package device;
package device.usbPlayer;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
Loading…
Cancel
Save