Created
July 6, 2023 14:02
-
-
Save ArunYogeshwaran/85de87179586d87beb14943e1058e99f to your computer and use it in GitHub Desktop.
The example below shows a system that toggles the "favorite" state of a given job in the cache.
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
// Unit under test. | |
fun toggleFavoriteForJob(job: Job) { | |
if (job.isFavorite) { | |
cache.unfavorite(job) | |
} else { | |
cache.favorite(job) | |
} | |
} | |
// A unit test using interaction testing. | |
fun `toggle favorite with already favorited job verify job is unfavorited`() { | |
// Test arrangements and setup. | |
val job = getTestFavoriteJob() | |
jobOperations.toggleFavoriteForJob(job) | |
verify(cache).unfavorite(job) | |
} | |
// A unit test using state testing. | |
fun `toggle favorite with favorited job verify job is unfavorited`() { | |
// Test arrangements and setup. | |
val job = getTestFavoriteJob() | |
jobOperations.toggleFavoriteForJob(job) | |
assertThat(cache.getJobWithId(job.id).isFavorite()).isFalse() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment