sahar
3 years ago
13 changed files with 210 additions and 103 deletions
-
7Geraete.config
-
50src/main/java/device/CDPlayer.java
-
33src/main/java/device/cdPlayer/CD.java
-
87src/main/java/device/cdPlayer/CDPlayer.java
-
8src/main/java/device/cdPlayer/exceptions/CdFlapIsOpenException.java
-
8src/main/java/device/cdPlayer/exceptions/FormatNotSupportedException.java
-
8src/main/java/device/cdPlayer/exceptions/NoCDException.java
-
4src/main/java/device/radioPlayer/RadioPlayer.java
-
4src/main/java/device/usbPlayer/UsbPlayer.java
-
46src/test/java/device/CDPlayerTest.java
-
52src/test/java/device/cdPlayer/CDPlayerTest.java
-
4src/test/java/device/radioPlayer/RadioPlayerTest.java
-
2src/test/java/device/usbPlayer/UsbPlayerTest.java
@ -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 |
|||
|
@ -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; |
|||
} |
|||
|
|||
} |
@ -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; |
|||
} |
|||
} |
@ -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; |
|||
} |
|||
|
|||
} |
@ -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."); |
|||
} |
|||
} |
@ -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."); |
|||
} |
|||
} |
@ -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."); |
|||
} |
|||
} |
@ -1,4 +1,6 @@ |
|||
package device; |
|||
package device.radioPlayer; |
|||
|
|||
import device.Device; |
|||
|
|||
import java.util.ArrayList; |
|||
|
@ -1,4 +1,6 @@ |
|||
package device; |
|||
package device.usbPlayer; |
|||
|
|||
import device.Device; |
|||
|
|||
public class UsbPlayer implements Device { |
|||
|
@ -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() { |
|||
} |
|||
|
|||
*/ |
|||
} |
@ -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) |
|||
); |
|||
} |
|||
|
|||
|
|||
} |
@ -1,5 +1,7 @@ |
|||
package device; |
|||
package device.radioPlayer; |
|||
|
|||
|
|||
import device.radioPlayer.RadioPlayer; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
@ -1,4 +1,4 @@ |
|||
package device; |
|||
package device.usbPlayer; |
|||
|
|||
import org.junit.jupiter.api.Test; |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue