Skip to content

Instantly share code, notes, and snippets.

@ArunYogeshwaran
Created February 5, 2023 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArunYogeshwaran/5098c3d6164e3787fe2be0df349ce12e to your computer and use it in GitHub Desktop.
Save ArunYogeshwaran/5098c3d6164e3787fe2be0df349ce12e to your computer and use it in GitHub Desktop.
An example of testing methods vs behaviours
fun playArtist(artist: Artist) {
if (artist != Artist.TAYLOR_SWIFT) {
return IllegalArgException()
}
addToRecentlyPlayed(artist)
player.play(artist.getRandomSong())
}
@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)
}
@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