26 Commits

Author SHA1 Message Date
JPANZO fce439259b Test+Productive code for case:3 of method-test next created. 3 years ago
JPANZO d917a294b4 Test+Productive code for case:2 of method-test next created. 3 years ago
Jenkins 029d19a2ed Merge commit 'd1cb0386ba8ee77bb957c37f13dc82ccf10155fb' into HEAD 3 years ago
Jenkins a476dd0ccc Merge commit '7b164b510a89feb81909204e3471df8306f96789' into HEAD 3 years ago
Jan Ortner 7b164b510a bug fix renaming saved stations 3 years ago
Jan Ortner 25148dfdc5 added test and code for second region to changeRegion() 3 years ago
Jan Ortner e603340839 added first region to changeRegion() 3 years ago
Jan Ortner 3376c4c676 first Test for changeRegion() 3 years ago
Jenkins c2d338064b Merge commit '77768e5230a252ffb2657e59465d5df7cded6c61' into HEAD 3 years ago
sahar 77768e5230 UsbPlayerTest.PrevTest implemented 3 years ago
Jenkins bdc3221c16 Merge commit 'e8a5a507dfd85ef5696a8287f3c403cc66ce7a01' into HEAD 3 years ago
Jan Ortner e8a5a507df productive for quieter() if volume is zero 3 years ago
Jan Ortner 820cfc8cfa added Test for quieter if volume is 0 3 years ago
Jan Ortner 72e58fcef9 added productive Code for function quieter 3 years ago
sahar ebd9395495 Production Code of UsbPlayer.prev() implemented 3 years ago
Jan Ortner 81035aa6d7 Test for quieter 3 years ago
sahar 9ca661545f PrevTest in UsbPlayerTest.java 3 years ago
Jan Ortner 43854c18e5 added productive Code for louder if volume is max 3 years ago
Jan Ortner d8ae7a9897 implemented Test for louder max 3 years ago
Jenkins 1bafe6505f Merge commit '7d66b2e47ad5a005bc446384abc2cd5aaae5e21b' into HEAD 3 years ago
sahar 7d66b2e47a Next Production Code in USB Class implemented 3 years ago
Jan Ortner 05de803468 implemented basic louder function for one step louder 3 years ago
sahar c868d52567 NextTest in USB Class 3 years ago
sahar 494ba5e317 Merge remote-tracking branch 'origin/master' 3 years ago
sahar 801b9160f6 Merge remote-tracking branch 'origin/master' 3 years ago
sahar 88594dc43b Merge remote-tracking branch 'origin/master' 3 years ago
  1. 8
      src/main/java/device/cdPlayer/CDPlayer.java
  2. 56
      src/main/java/device/radioPlayer/RadioPlayer.java
  3. 11
      src/main/java/device/usbPlayer/UsbPlayer.java
  4. 31
      src/test/java/device/cdPlayer/CDPlayerTest.java
  5. 73
      src/test/java/device/radioPlayer/RadioPlayerTest.java
  6. 51
      src/test/java/device/usbPlayer/UsbPlayerTest.java

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

@ -44,8 +44,10 @@ public class CDPlayer implements Device {
public void next() { public void next() {
List<String> playList = Arrays.asList(loadedCD.getPlayList()); List<String> playList = Arrays.asList(loadedCD.getPlayList());
int indexOfActualPlayTrack=playList.indexOf(actualPlayTrack); int indexOfActualPlayTrack=playList.indexOf(actualPlayTrack);
this.actualPlayTrack=playList.get(indexOfActualPlayTrack +1);
int indexOfNextPlayTrack=(indexOfActualPlayTrack+1)%loadedCD.getPlayList().length;
//System.out.println("actualIndex= "+indexOfActualPlayTrack);
this.actualPlayTrack=playList.get(indexOfNextPlayTrack );
//System.out.println("nextSong= "+actualPlayTrack);
} }
@Override @Override
@ -65,7 +67,7 @@ public class CDPlayer implements Device {
@Override @Override
public String[] getItemList() { public String[] getItemList() {
return new String[0];
return loadedCD.getPlayList();
} }

56
src/main/java/device/radioPlayer/RadioPlayer.java

@ -8,13 +8,14 @@ public class RadioPlayer implements Device {
public RadioPlayer() { public RadioPlayer() {
super(); super();
Playlist.add("Radio YouFM");
Playlist.add("Radio Teddy");
Playlist.add("Radio MegaHits");
Playlist.add("YouFM");
Playlist.add("Teddy");
Playlist.add("MegaHits");
playTrack=Playlist.get(0); playTrack=Playlist.get(0);
} }
ArrayList<String> Playlist=new ArrayList<String>(); ArrayList<String> Playlist=new ArrayList<String>();
int Lautstaerke = 0; int Lautstaerke = 0;
String playTrack=""; String playTrack="";
@ -26,23 +27,52 @@ public class RadioPlayer implements Device {
return Lautstaerke; return Lautstaerke;
} }
public void changeRegion(String region){
switch (region) {
case "BY":
Playlist.clear();
Playlist.add("Antenne Bayern");
Playlist.add("Bayern 1");
Playlist.add("Bayern 3");
Playlist.add("Hit Radio N1");
playTrack=Playlist.get(0);
break;
case "HE":
Playlist.clear();
Playlist.add("Hit Radio FFH");
Playlist.add("HR 1");
Playlist.add("HR 3");
Playlist.add("You FM");
playTrack=Playlist.get(0);
break;
case "BW":
Playlist.clear();
Playlist.add("DASDING");
Playlist.add("SWR 1");
Playlist.add("SWR 3");
Playlist.add("sunshine live");
playTrack=Playlist.get(0);
break;
default:
Playlist.clear();
Playlist.add("YouFM");
Playlist.add("Teddy");
Playlist.add("MegaHits");
playTrack=Playlist.get(0);
break;
}
}
@Override @Override
public void louder() { public void louder() {
if(Lautstaerke < 100) {
Lautstaerke += 1;
} else {
Lautstaerke = 100;
}
if(Lautstaerke < 100){Lautstaerke+=1;}
else Lautstaerke = 100;
} }
@Override @Override
public void quieter() { public void quieter() {
if(Lautstaerke > 0) {
Lautstaerke -= 1;
} else {
Lautstaerke = 0;
}
if(Lautstaerke > 0){Lautstaerke-=1;}
else Lautstaerke = 0;
} }
@Override @Override
public int getVolume() { public int getVolume() {

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

@ -111,12 +111,19 @@ public class UsbPlayer implements Device {
@Override @Override
public void next() { public void next() {
int currentIdex = Playlist.indexOf(playTrack);
int nextIndex = (currentIdex + 1) % Playlist.size();
playTrack = Playlist.get(nextIndex);
} }
@Override @Override
public void prev() { public void prev() {
int currentIdex = Playlist.indexOf(playTrack);
int nextIndex = Playlist.size() - 1;
if (currentIdex != 0) {
nextIndex = (currentIdex - 1);
}
playTrack = Playlist.get(nextIndex);
} }
@Override @Override

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

@ -156,10 +156,17 @@ class CDPlayerTest {
@ParameterizedTest @ParameterizedTest
@MethodSource("nextTestData") @MethodSource("nextTestData")
void nextTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, String expectedResult){ void nextTest(String testName,String testDirection, CDPlayer _cdPlayer,int anzClicks, String expectedResult){
if(testDirection.equals("SecondSongSelected")|| testDirection.equals("ThirdSongSelected")){
for (int i = 0; i < anzClicks; i++) { for (int i = 0; i < anzClicks; i++) {
_cdPlayer.next(); _cdPlayer.next();
} }
if(testDirection.equals("SecondSongSelected")){
assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult);
}
if(testDirection.equals("FirstSongSelected")){
for (int i = 0; i <anzClicks; i++) {
_cdPlayer.next();
}
assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult); assertThat(_cdPlayer.getActualPlayTrack()).describedAs(testName).isEqualTo(expectedResult);
} }
} }
@ -168,13 +175,25 @@ class CDPlayerTest {
String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"}; String[] audioPlayList=new String[]{"Audio 01","Audio 02","Audio 03","Audio 04","Audio 05"};
CD audioCD=new CD("Audio",audioPlayList); CD audioCD=new CD("Audio",audioPlayList);
CDPlayer cdPlayer=new CDPlayer();
cdPlayer.tapOnCdFlap();
cdPlayer.setCD(audioCD);
cdPlayer.tapOnCdFlap();
CDPlayer cdPlayer1=new CDPlayer();
cdPlayer1.tapOnCdFlap();
cdPlayer1.setCD(audioCD);
cdPlayer1.tapOnCdFlap();
CDPlayer cdPlayer2=new CDPlayer();
cdPlayer2.tapOnCdFlap();
cdPlayer2.setCD(audioCD);
cdPlayer2.tapOnCdFlap();
CDPlayer cdPlayer3=new CDPlayer();
cdPlayer3.tapOnCdFlap();
cdPlayer3.setCD(audioCD);
cdPlayer3.tapOnCdFlap();
return Stream.of( return Stream.of(
Arguments.of("[getActualPlayTrack() after 1x next() starting by firstSong] => SecondSongSelected","SecondSongSelected", cdPlayer, 1, cdPlayer.getSongByNumber(1))
Arguments.of("[getActualPlayTrack() after 1x next() starting by firstSong] => SecondSongSelected","SecondSongSelected", cdPlayer1, 1, cdPlayer1.getSongByNumber(1)),
Arguments.of("[getActualPlayTrack() after 2x next() starting by firstSong] => ThirdSongSelected","ThirdSongSelected" ,cdPlayer2,2,cdPlayer2.getSongByNumber(2)),
Arguments.of("[getActualPlayTrack() after 1x next() starting by lastSong] => FirstSongSelected","FirstSongSelected", cdPlayer3,cdPlayer3.getItemList().length,cdPlayer3.getSongByNumber(0))
); );
} }

73
src/test/java/device/radioPlayer/RadioPlayerTest.java

@ -16,35 +16,58 @@ class RadioPlayerTest {
RadioPlayer rp = new RadioPlayer(); RadioPlayer rp = new RadioPlayer();
@Test
void louder() {
rp.setLautstaerke(0);
rp.louder();
assertThat(rp.getLautstaerke()).isEqualTo(1);
@ParameterizedTest
@MethodSource("quieterLouderOptions")
void quieterLouderTest(String testName, RadioPlayer testRp, int expectedResult) {
int volume = testRp.getLautstaerke();
assertThat(volume).describedAs(testName).isEqualTo(expectedResult);
} }
@Test
void louderMax() {
rp.setLautstaerke(100);
rp.louder();
assertThat(rp.getLautstaerke()).isEqualTo(100);
static Stream<Arguments> quieterLouderOptions() {
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
RadioPlayer rp3 = new RadioPlayer();
RadioPlayer rp4 = new RadioPlayer();
rp1.setLautstaerke(0);
rp1.louder();
rp2.setLautstaerke(100);
rp2.louder();
rp3.setLautstaerke(1);
rp3.quieter();
rp4.setLautstaerke(0);
rp4.quieter();
return Stream.of(
Arguments.of("Test for one step louder", rp1, 1),
Arguments.of("Test for max louder", rp2, 100),
Arguments.of("Test for one step quieter", rp3, 0),
Arguments.of("Test for min quieter", rp4, 0)
);
} }
@Test
void quieter() {
rp.setLautstaerke(1);
rp.quieter();
assertThat(rp.getLautstaerke()).isEqualTo(0);
@ParameterizedTest
@MethodSource("changeRegionOptions")
void changeRegionTest(String testName, RadioPlayer testRp, String expectedResult) {
String station = testRp.playTrack;
assertThat(station).describedAs(testName).isEqualTo(expectedResult);
} }
@Test
void quieterMax() {
rp.setLautstaerke(0);
rp.quieter();
assertThat(rp.getLautstaerke()).isEqualTo(0);
static Stream<Arguments> changeRegionOptions() {
RadioPlayer rp1 = new RadioPlayer();
RadioPlayer rp2 = new RadioPlayer();
RadioPlayer rp3 = new RadioPlayer();
rp1.changeRegion("BY");
rp2.changeRegion("HE");
rp3.changeRegion("BW");
return Stream.of(
Arguments.of("Test change Region to Bayern", rp1, "Antenne Bayern"),
Arguments.of("Test change Region to Hessen", rp2, "Hit Radio FFH"),
Arguments.of("Test change Region to Baden-Wuerttemberg", rp3, "DASDING")
);
} }
/* /*
Jenkins config test
@Test @Test
void getVolume() { void getVolume() {
} }
@ -66,9 +89,9 @@ class RadioPlayerTest {
rp2.prev(); rp2.prev();
rp3.prev(); rp3.prev();
return Stream.of( return Stream.of(
Arguments.of("Next Station Test", rp1, "Radio Teddy"),
Arguments.of("Prev Station Test", rp2, "Radio YouFM"),
Arguments.of("Prev works on first Station ", rp3, "Radio MegaHits")
Arguments.of("Next Station Test", rp1, "Teddy"),
Arguments.of("Prev Station Test", rp2, "YouFM"),
Arguments.of("Prev works on first Station ", rp3, "MegaHits")
); );
} }

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

@ -86,4 +86,55 @@ void louderTest(String testName, UsbPlayer inputPlay, int expectedResult) {
); );
} }
@ParameterizedTest
@MethodSource("NextOptions")
void NextTest(String testName, UsbPlayer inputPlay, String expectedResult) {
String current_Track = inputPlay.getPlayTrack();
assertThat(current_Track).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> NextOptions() {
UsbPlayer up1 = new UsbPlayer();
up1.next();
UsbPlayer up2 = new UsbPlayer();
for (int i = 1; i < up2.getPlaylist().size(); i++) {
up2.next();
}
UsbPlayer up3 = new UsbPlayer();
for (int i = 1; i < up3.getPlaylist().size(); i++) {
up3.next();
}
up3.next();
return Stream.of(
Arguments.of("Second-Song : Musik 02.mp3 ", up1, "Musik 02.mp3"),
Arguments.of("Last-Song : Musik 03.mp3 ", up2, "Musik 03.mp3"),
Arguments.of("From last to first Song : Musik 01.mp3 ", up3, "Musik 01.mp3")
);
}
////////////////
@ParameterizedTest
@MethodSource("PrevOptions")
void PrevTest(String testName, UsbPlayer inputPlay, String expectedResult) {
String current_Track = inputPlay.getPlayTrack();
assertThat(current_Track).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> PrevOptions() {
UsbPlayer up1 = new UsbPlayer();
up1.prev();
UsbPlayer up2 = new UsbPlayer();
for (int i = 1; i < up2.getPlaylist().size(); i++) {//3
up2.prev();
}
return Stream.of(
Arguments.of("From first-Song to last-Song : Musik 03.mp3 ", up1, "Musik 03.mp3"),
Arguments.of("From first-Song to second-Song(Backward) : Musik 02.mp3 ", up2, "Musik 02.mp3")
);
}
} }
Loading…
Cancel
Save