@ -171,11 +171,42 @@ class RadioPlayerTest {
@Test
void getOptions ( ) {
}
@Test
void chooseOption ( ) {
}
* /
@ParameterizedTest
@MethodSource ( "chooseItemOptions" )
void testChooseItem ( String testName , RadioPlayer testRp , String expectedResult ) {
String playedStation = testRp . playedStation ;
assertThat ( playedStation ) . describedAs ( testName ) . isEqualTo ( expectedResult ) ;
}
static Stream < Arguments > chooseItemOptions ( ) {
RadioPlayer rp = new RadioPlayer ( ) ;
rp . chooseItem ( 2 ) ;
RadioPlayer rp1 = new RadioPlayer ( ) ;
rp1 . chooseItem ( 5 ) ;
RadioPlayer rp2 = new RadioPlayer ( ) ;
rp2 . chooseItem ( - 1 ) ;
RadioPlayer rp3 = new RadioPlayer ( ) ;
rp3 . changeRegion ( "BY" ) ;
rp3 . chooseItem ( 2 ) ;
RadioPlayer rp4 = new RadioPlayer ( ) ;
rp4 . changeRegion ( "BY" ) ;
rp4 . chooseItem ( 5 ) ;
RadioPlayer rp5 = new RadioPlayer ( ) ;
rp5 . changeRegion ( "BY" ) ;
rp5 . chooseItem ( - 2 ) ;
return Stream . of (
Arguments . of ( "Test select station in saved playlist to play with nr isn`t bigger than playlist size" , rp , "Teddy" ) ,
Arguments . of ( "Test select station in saved playlist to play with nr is bigger than playlist size. Last station in playlist gets played" , rp1 , "MegaHits" ) ,
Arguments . of ( "Test select station in saved playlist to play with nr is lower than 0. First station in playlist gets played" , rp2 , "YouFM" ) ,
Arguments . of ( "Test select station in regional playlist to play with nr isn`t bigger than playlist size" , rp3 , "Bayern 1" ) ,
Arguments . of ( "Test select station in regional playlist to play with nr is bigger than playlist size. Last station in playlist gets played" , rp4 , "Hit Radio N1" ) ,
Arguments . of ( "Test select station in regional playlist to play with nr is lower than 0. Last station in playlist gets played" , rp5 , "Antenne Bayern" )
) ;
}
@ParameterizedTest
@MethodSource ( "testPlayOptions" )
void testPlay ( String testName , RadioPlayer testRp , String expectedResult ) {
@ -289,4 +320,57 @@ class RadioPlayerTest {
Arguments . of ( "Test for change order in saved playlist with nr is than smaller than 0 at front of playlist" , rp2 , 0 , "Teddy" )
) ;
}
@ParameterizedTest
@MethodSource ( "getItemListOptions" )
void testGetItemList ( String testName , RadioPlayer testRp , String testTyp , String [ ] expectedResult ) {
if ( testTyp . equals ( "region" ) ) {
testRp . changeRegion ( "BY" ) ;
}
String [ ] playList = testRp . getItemList ( ) ;
assertThat ( playList ) . describedAs ( testName ) . isEqualTo ( expectedResult ) ;
}
static Stream < Arguments > getItemListOptions ( ) {
RadioPlayer rp = new RadioPlayer ( ) ;
RadioPlayer rp1 = new RadioPlayer ( ) ;
rp1 . changeRegion ( "BY" ) ;
return Stream . of (
Arguments . of ( "Test for return saved playlist" , rp , "saved" , rp . savedPlaylist . toArray ( new String [ 0 ] ) ) ,
Arguments . of ( "Test for return regional playlist" , rp1 , "region" , rp1 . regionPlaylist . toArray ( new String [ 0 ] ) )
) ;
}
@ParameterizedTest
@MethodSource ( "muteOptions" )
void testMute ( String testName , String testTyp , RadioPlayer testRp , int expectedResult ) {
int volume ;
if ( testTyp . equals ( "actual" ) ) volume = testRp . getVolume ( ) ;
else volume = testRp . savedVolume ;
assertThat ( volume ) . describedAs ( testName ) . isEqualTo ( expectedResult ) ;
}
static Stream < Arguments > muteOptions ( ) {
RadioPlayer rp = new RadioPlayer ( ) ;
rp . setLautstaerke ( 25 ) ;
rp . mute ( ) ;
RadioPlayer rp1 = new RadioPlayer ( ) ;
rp1 . setLautstaerke ( 30 ) ;
rp1 . mute ( ) ;
return Stream . of (
Arguments . of ( "Test for mute RadioPlayer if volume is actually 0" , "actual" , rp , 0 ) ,
Arguments . of ( "Test for mute RadioPlayer if volume is saved before muting" , "saved" , rp1 , 30 )
) ;
}
@Test
void TestUnmute ( ) {
RadioPlayer rp = new RadioPlayer ( ) ;
rp . setLautstaerke ( 40 ) ;
rp . mute ( ) ;
rp . unmute ( ) ;
assertThat ( rp . getVolume ( ) ) . describedAs ( "Test if unmute is setting the saved volume" ) . isEqualTo ( rp . savedVolume ) ;
}
}