Created
February 5, 2023 22:27
-
-
Save ArunYogeshwaran/5098c3d6164e3787fe2be0df349ce12e to your computer and use it in GitHub Desktop.
An example of testing methods vs behaviours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun playArtist(artist: Artist) { | |
if (artist != Artist.TAYLOR_SWIFT) { | |
return IllegalArgException() | |
} | |
addToRecentlyPlayed(artist) | |
player.play(artist.getRandomSong()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `play artist verify recently played list contains artist`() { | |
val artist = Artist.TAYLOR_SWIFT | |
val audioPlayer = getAudioPlayer() | |
audioPlayer.playArtister(artist) | |
assertThat(recentlyPlayedList.contains(artist)).isTrue() | |
} | |
@Test | |
fun `play artist verify current song belongs to the artist`() { | |
val artist = Artist.TAYLOR_SWIFT | |
val audioPlayer = getAudioPlayer() | |
audioPlayer.playArtister(artist) | |
assertThat(audioPlayer.getCurrentSong().artist).isEqualTo(TAYLOR_SWIFT) | |
} | |
@Test | |
@Throws(IllegalArgException) | |
fun `play with invalid artist expect IllegalArgException`() { | |
val artist = Artist.MJ | |
val audioPlayer = getAudioPlayer() | |
audioPlayer.playArtister(artist) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `play artist verify recently played list and audio player state`() { | |
val artist = Artist.TAYLOR_SWIFT | |
val audioPlayer = getAudioPlayer() | |
audioPlayer.playArtister(artist) | |
assertThat(recentlyPlayedList.contains(artist)).isTrue() | |
assertThat(audioPlayer.getCurrentSong().artist).isEqualTo(TAYLOR_SWIFT) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment