issue#6 Add DisplayName annotation to all tests in core module

This commit is contained in:
Gergely Hegedus 2021-11-04 20:04:01 +02:00
parent c9d4223ce6
commit e7f840a1b9
9 changed files with 86 additions and 38 deletions

View file

@ -6,6 +6,7 @@ import org.fnives.test.showcase.core.storage.content.FavouriteContentLocalStorag
import org.fnives.test.showcase.model.content.ContentId
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.kotlin.doThrow
import org.mockito.kotlin.mock
@ -27,22 +28,27 @@ internal class AddContentToFavouriteUseCaseTest {
sut = AddContentToFavouriteUseCase(mockFavouriteContentLocalStorage)
}
@DisplayName("WHEN_nothing_happens_THEN_the_storage_is_not_touched")
@Test
fun WHEN_nothing_happens_THEN_the_storage_is_not_touched() {
fun initializationDoesntAffectStorage() {
verifyZeroInteractions(mockFavouriteContentLocalStorage)
}
@DisplayName("GIVEN_contentId_WHEN_called_THEN_storage_is_called")
@Test
fun GIVEN_contentId_WHEN_called_THEN_storage_is_called() = runBlockingTest {
fun contentIdIsDelegatedToStorage() = runBlockingTest {
sut.invoke(ContentId("a"))
verify(mockFavouriteContentLocalStorage, times(1)).markAsFavourite(ContentId("a"))
verifyNoMoreInteractions(mockFavouriteContentLocalStorage)
}
@DisplayName("GIVEN_throwing_local_storage_WHEN_thrown_THEN_its_propagated")
@Test
fun GIVEN_throwing_local_storage_WHEN_thrown_THEN_its_thrown() = runBlockingTest {
whenever(mockFavouriteContentLocalStorage.markAsFavourite(ContentId("a"))).doThrow(RuntimeException())
fun storageThrowingIsPropagated() = runBlockingTest {
whenever(mockFavouriteContentLocalStorage.markAsFavourite(ContentId("a"))).doThrow(
RuntimeException()
)
assertThrows(RuntimeException::class.java) {
runBlocking { sut.invoke(ContentId("a")) }

View file

@ -4,6 +4,7 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runBlockingTest
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.kotlin.doThrow
import org.mockito.kotlin.mock
@ -25,21 +26,24 @@ internal class FetchContentUseCaseTest {
sut = FetchContentUseCase(mockContentRepository)
}
@DisplayName("WHEN nothing happens THEN the storage is not touched")
@Test
fun WHEN_nothing_happens_THEN_the_storage_is_not_touched() {
fun initializationDoesntAffectRepository() {
verifyZeroInteractions(mockContentRepository)
}
@DisplayName("WHEN called THEN repository is called")
@Test
fun WHEN_called_THEN_repository_is_called() = runBlockingTest {
fun whenCalledRepositoryIsFetched() = runBlockingTest {
sut.invoke()
verify(mockContentRepository, times(1)).fetch()
verifyNoMoreInteractions(mockContentRepository)
}
@DisplayName("GIVEN throwing local storage WHEN thrown THEN its thrown")
@Test
fun GIVEN_throwing_local_storage_WHEN_thrown_THEN_its_thrown() = runBlockingTest {
fun whenRepositoryThrowsUseCaseAlsoThrows() = runBlockingTest {
whenever(mockContentRepository.fetch()).doThrow(RuntimeException())
assertThrows(RuntimeException::class.java) {

View file

@ -15,6 +15,7 @@ import org.fnives.test.showcase.model.content.ImageUrl
import org.fnives.test.showcase.model.shared.Resource
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
@ -45,8 +46,9 @@ internal class GetAllContentUseCaseTest {
sut = GetAllContentUseCase(mockContentRepository, mockFavouriteContentLocalStorage)
}
@DisplayName("GIVEN loading AND empty favourite WHEN observed THEN loading is shown")
@Test
fun GIVEN_loading_AND_empty_favourite_WHEN_observed_THEN_loading_is_shown() =
fun loadingResourceWithNoFavouritesResultsInLoadingResource() =
runBlockingTest(testDispatcher) {
favouriteContentIdFlow.value = emptyList()
contentFlow.value = Resource.Loading()
@ -57,8 +59,9 @@ internal class GetAllContentUseCaseTest {
Assertions.assertEquals(listOf(expected), actual)
}
@DisplayName("GIVEN loading AND listOfFavourite WHEN observed THEN loading is shown")
@Test
fun GIVEN_loading_AND_listOfFavourite_WHEN_observed_THEN_loading_is_shown() =
fun loadingResourceWithFavouritesResultsInLoadingResource() =
runBlockingTest(testDispatcher) {
favouriteContentIdFlow.value = listOf(ContentId("a"))
contentFlow.value = Resource.Loading()
@ -69,8 +72,9 @@ internal class GetAllContentUseCaseTest {
Assertions.assertEquals(listOf(expected), actual)
}
@DisplayName("GIVEN error AND empty favourite WHEN observed THEN error is shown")
@Test
fun GIVEN_error_AND_empty_favourite_WHEN_observed_THEN_error_is_shown() =
fun errorResourceWithNoFavouritesResultsInErrorResource() =
runBlockingTest(testDispatcher) {
favouriteContentIdFlow.value = emptyList()
val exception = Throwable()
@ -82,8 +86,9 @@ internal class GetAllContentUseCaseTest {
Assertions.assertEquals(listOf(expected), actual)
}
@DisplayName("GIVEN error AND listOfFavourite WHEN observed THEN error is shown")
@Test
fun GIVEN_error_AND_listOfFavourite_WHEN_observed_THEN_error_is_shown() =
fun errorResourceWithFavouritesResultsInErrorResource() =
runBlockingTest(testDispatcher) {
favouriteContentIdFlow.value = listOf(ContentId("b"))
val exception = Throwable()
@ -95,8 +100,9 @@ internal class GetAllContentUseCaseTest {
Assertions.assertEquals(listOf(expected), actual)
}
@DisplayName("GIVEN listOfContent AND empty favourite WHEN observed THEN favourites are returned")
@Test
fun GIVEN_listOfContent_AND_empty_favourite_WHEN_observed_THEN_favourites_are_returned() =
fun successResourceWithNoFavouritesResultsInNoFavouritedItems() =
runBlockingTest(testDispatcher) {
favouriteContentIdFlow.value = emptyList()
val content = Content(ContentId("a"), "b", "c", ImageUrl("d"))
@ -111,8 +117,9 @@ internal class GetAllContentUseCaseTest {
Assertions.assertEquals(listOf(expected), actual)
}
@DisplayName("GIVEN listOfContent AND other favourite id WHEN observed THEN favourites are returned")
@Test
fun GIVEN_listOfContent_AND_other_favourite_id_WHEN_observed_THEN_favourites_are_returned() =
fun successResourceWithDifferentFavouritesResultsInNoFavouritedItems() =
runBlockingTest(testDispatcher) {
favouriteContentIdFlow.value = listOf(ContentId("x"))
val content = Content(ContentId("a"), "b", "c", ImageUrl("d"))
@ -127,8 +134,9 @@ internal class GetAllContentUseCaseTest {
Assertions.assertEquals(listOf(expected), actual)
}
@DisplayName("GIVEN listOfContent AND same favourite id WHEN observed THEN favourites are returned")
@Test
fun GIVEN_listOfContent_AND_same_favourite_id_WHEN_observed_THEN_favourites_are_returned() =
fun successResourceWithSameFavouritesResultsInFavouritedItems() =
runBlockingTest(testDispatcher) {
favouriteContentIdFlow.value = listOf(ContentId("a"))
val content = Content(ContentId("a"), "b", "c", ImageUrl("d"))
@ -143,8 +151,9 @@ internal class GetAllContentUseCaseTest {
Assertions.assertEquals(listOf(expected), actual)
}
@DisplayName("GIVEN loading then data then added favourite WHEN observed THEN loading then correct favourites are returned")
@Test
fun GIVEN_loading_then_data_then_added_favourite_WHEN_observed_THEN_loading_then_correct_favourites_are_returned() =
fun whileLoadingAndAddingItemsReactsProperly() =
runBlockingTest(testDispatcher) {
favouriteContentIdFlow.value = emptyList()
val content = Content(ContentId("a"), "b", "c", ImageUrl("d"))
@ -169,8 +178,9 @@ internal class GetAllContentUseCaseTest {
Assertions.assertEquals(expected, actual.await())
}
@DisplayName("GIVEN loading then data then removed favourite WHEN observed THEN loading then correct favourites are returned")
@Test
fun GIVEN_loading_then_data_then_removed_favourite_WHEN_observed_THEN_loading_then_correct_favourites_are_returned() =
fun whileLoadingAndRemovingItemsReactsProperly() =
runBlockingTest(testDispatcher) {
favouriteContentIdFlow.value = listOf(ContentId("a"))
val content = Content(ContentId("a"), "b", "c", ImageUrl("d"))
@ -195,8 +205,9 @@ internal class GetAllContentUseCaseTest {
Assertions.assertEquals(expected, actual.await())
}
@DisplayName("GIVEN loading then data then loading WHEN observed THEN loading then correct favourites then loading are returned")
@Test
fun GIVEN_loading_then_data_then_loading_WHEN_observed_THEN_loading_then_correct_favourites_then_loadingare_returned() =
fun loadingThenDataThenLoadingReactsProperly() =
runBlockingTest(testDispatcher) {
favouriteContentIdFlow.value = listOf(ContentId("a"))
val content = Content(ContentId("a"), "b", "c", ImageUrl("d"))

View file

@ -6,6 +6,7 @@ import org.fnives.test.showcase.core.storage.content.FavouriteContentLocalStorag
import org.fnives.test.showcase.model.content.ContentId
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.kotlin.doThrow
import org.mockito.kotlin.mock
@ -27,21 +28,24 @@ internal class RemoveContentFromFavouritesUseCaseTest {
sut = RemoveContentFromFavouritesUseCase(mockFavouriteContentLocalStorage)
}
@DisplayName("WHEN nothing happens THEN the storage is not touched")
@Test
fun WHEN_nothing_happens_THEN_the_storage_is_not_touched() {
fun initializationDoesntAffectStorage() {
verifyZeroInteractions(mockFavouriteContentLocalStorage)
}
@DisplayName("GIVEN contentId WHEN called THEN storage is called")
@Test
fun GIVEN_contentId_WHEN_called_THEN_storage_is_called() = runBlockingTest {
fun givenContentIdCallsStorage() = runBlockingTest {
sut.invoke(ContentId("a"))
verify(mockFavouriteContentLocalStorage, times(1)).deleteAsFavourite(ContentId("a"))
verifyNoMoreInteractions(mockFavouriteContentLocalStorage)
}
@DisplayName("GIVEN throwing local storage WHEN thrown THEN its propogated")
@Test
fun GIVEN_throwing_local_storage_WHEN_thrown_THEN_its_thrown() = runBlockingTest {
fun storageExceptionThrowingIsPropogated() = runBlockingTest {
whenever(mockFavouriteContentLocalStorage.deleteAsFavourite(ContentId("a"))).doThrow(RuntimeException())
Assertions.assertThrows(RuntimeException::class.java) {

View file

@ -4,6 +4,7 @@ import org.fnives.test.showcase.core.storage.UserDataLocalStorage
import org.fnives.test.showcase.model.session.Session
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
@ -22,13 +23,15 @@ internal class IsUserLoggedInUseCaseTest {
sut = IsUserLoggedInUseCase(mockUserDataLocalStorage)
}
@DisplayName("WHEN nothing is called THEN storage is not called")
@Test
fun WHEN_nothing_is_called_THEN_storage_is_not_called() {
fun creatingDoesntAffectStorage() {
verifyZeroInteractions(mockUserDataLocalStorage)
}
@DisplayName("GIVEN session data saved WHEN is user logged in checked THEN true is returned")
@Test
fun GIVEN_session_data_saved_WHEN_is_user_logged_in_checked_THEN_true_is_returned() {
fun sessionInStorageResultsInLoggedIn() {
whenever(mockUserDataLocalStorage.session).doReturn(Session("a", "b"))
val actual = sut.invoke()
@ -36,8 +39,9 @@ internal class IsUserLoggedInUseCaseTest {
Assertions.assertEquals(true, actual)
}
@DisplayName("GIVEN no session data saved WHEN is user logged in checked THEN false is returned")
@Test
fun GIVEN_no_session_data_saved_WHEN_is_user_logged_in_checked_THEN_false_is_returned() {
fun noSessionInStorageResultsInLoggedOut() {
whenever(mockUserDataLocalStorage.session).doReturn(null)
val actual = sut.invoke()
@ -45,8 +49,9 @@ internal class IsUserLoggedInUseCaseTest {
Assertions.assertEquals(false, actual)
}
@DisplayName("GIVEN no session THEN session THEN no session WHEN is user logged in checked over again THEN every return is correct")
@Test
fun GIVEN_no_session_THEN_session_THEN_no_session_WHEN_is_user_logged_in_checked_over_again_THEN_every_return_is_correct() {
fun multipleSessionSettingsResultsInCorrectResponses() {
whenever(mockUserDataLocalStorage.session).doReturn(null)
val actual1 = sut.invoke()
whenever(mockUserDataLocalStorage.session).doReturn(Session("", ""))

View file

@ -6,6 +6,7 @@ import org.fnives.test.showcase.core.login.LogoutUseCase
import org.fnives.test.showcase.core.storage.UserDataLocalStorage
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.times
@ -36,13 +37,15 @@ internal class LogoutUseCaseTest {
testCoreComponent.inject(this)
}
@DisplayName("WHEN no call THEN storage is not interacted")
@Test
fun WHEN_no_call_THEN_storage_is_not_interacted() {
fun initializedDoesntAffectStorage() {
verifyZeroInteractions(mockUserDataLocalStorage)
}
@DisplayName("WHEN logout invoked THEN storage is cleared")
@Test
fun WHEN_logout_invoked_THEN_storage_is_cleared() = runBlockingTest {
fun logoutResultsInStorageCleaning() = runBlockingTest {
val repositoryBefore = contentRepository
sut.invoke()

View file

@ -9,6 +9,7 @@ import org.fnives.test.showcase.model.network.BaseUrl
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
@ -47,13 +48,15 @@ internal class LogoutUseCaseTest : KoinTest {
stopKoin()
}
@DisplayName("WHEN no call THEN storage is not interacted")
@Test
fun WHEN_no_call_THEN_storage_is_not_interacted() {
fun initializedDoesntAffectStorage() {
verifyZeroInteractions(mockUserDataLocalStorage)
}
@DisplayName("WHEN logout invoked THEN storage is cleared")
@Test
fun WHEN_logout_invoked_THEN_storage_is_cleared() = runBlockingTest {
fun logoutResultsInStorageCleaning() = runBlockingTest {
val repositoryBefore = getKoin().get<ContentRepository>()
sut.invoke()

View file

@ -7,13 +7,15 @@ import org.fnives.test.showcase.model.shared.Resource
import org.fnives.test.showcase.network.shared.exceptions.NetworkException
import org.fnives.test.showcase.network.shared.exceptions.ParsingException
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
@Suppress("TestFunctionName")
internal class AnswerUtilsKtTest {
@DisplayName("GIVEN network exception thrown WHEN wrapped into answer THEN answer error is returned")
@Test
fun GIVEN_network_exception_thrown_WHEN_wrapped_into_answer_THEN_answer_error_is_returned() = runBlocking {
fun networkExceptionThrownResultsInError() = runBlocking {
val exception = NetworkException(Throwable())
val expected = Answer.Error<Unit>(exception)
@ -22,8 +24,9 @@ internal class AnswerUtilsKtTest {
Assertions.assertEquals(expected, actual)
}
@DisplayName("GIVEN parsing exception thrown WHEN wrapped into answer THEN answer error is returned")
@Test
fun GIVEN_parsing_exception_thrown_WHEN_wrapped_into_answer_THEN_answer_error_is_returned() = runBlocking {
fun parsingExceptionThrownResultsInError() = runBlocking {
val exception = ParsingException(Throwable())
val expected = Answer.Error<Unit>(exception)
@ -32,8 +35,9 @@ internal class AnswerUtilsKtTest {
Assertions.assertEquals(expected, actual)
}
@DisplayName("GIVEN unexpected throwable thrown WHEN wrapped into answer THEN answer error is returned")
@Test
fun GIVEN_parsing_throwable_thrown_WHEN_wrapped_into_answer_THEN_answer_error_is_returned() = runBlocking {
fun unexpectedExceptionThrownResultsInError() = runBlocking {
val exception = Throwable()
val expected = Answer.Error<Unit>(UnexpectedException(exception))
@ -42,8 +46,9 @@ internal class AnswerUtilsKtTest {
Assertions.assertEquals(expected, actual)
}
@DisplayName("GIVEN string WHEN wrapped into answer THEN string answer is returned")
@Test
fun GIVEN_string_WHEN_wrapped_into_answer_THEN_string_answer_is_returned() = runBlocking {
fun stringIsReturnedWrappedIntoSuccess() = runBlocking {
val expected = Answer.Success("banan")
val actual = wrapIntoAnswer { "banan" }
@ -51,15 +56,17 @@ internal class AnswerUtilsKtTest {
Assertions.assertEquals(expected, actual)
}
@DisplayName("GIVEN cancellation exception WHEN wrapped into answer THEN cancellation exception is thrown")
@Test
fun GIVEN_cancellation_exception_WHEN_wrapped_into_answer_THEN_cancellation_exception_is_thrown() {
fun cancellationExceptionResultsInThrowingIt() {
Assertions.assertThrows(CancellationException::class.java) {
runBlocking { wrapIntoAnswer { throw CancellationException() } }
}
}
@DisplayName("GIVEN success answer WHEN converted into resource THEN Resource success is returned")
@Test
fun GIVEN_success_answer_WHEN_converted_into_resource_THEN_Resource_success_is_returned() {
fun successAnswerConvertsToSuccessResource() {
val expected = Resource.Success("alma")
val actual = Answer.Success("alma").mapIntoResource()
@ -67,8 +74,9 @@ internal class AnswerUtilsKtTest {
Assertions.assertEquals(expected, actual)
}
@DisplayName("GIVEN error answer WHEN converted into resource THEN Resource error is returned")
@Test
fun GIVEN_error_answer_WHEN_converted_into_resource_THEN_Resource_error_is_returned() {
fun errorAnswerConvertsToErrorResource() {
val exception = Throwable()
val expected = Resource.Error<Unit>(exception)

View file

@ -3,6 +3,7 @@ package org.fnives.test.showcase.core.storage
import org.fnives.test.showcase.model.session.Session
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
@ -23,16 +24,18 @@ internal class NetworkSessionLocalStorageAdapterTest {
sut = NetworkSessionLocalStorageAdapter(mockUserDataLocalStorage)
}
@DisplayName("GIVEN null as session WHEN saved THEN its delegated")
@Test
fun GIVEN_null_as_session_WHEN_saved_THEN_its_delegated() {
fun settingNullSessionIsDelegated() {
sut.session = null
verify(mockUserDataLocalStorage, times(1)).session = null
verifyNoMoreInteractions(mockUserDataLocalStorage)
}
@DisplayName("GIVEN session WHEN saved THEN its delegated")
@Test
fun GIVEN_session_WHEN_saved_THEN_its_delegated() {
fun settingDataAsSessionIsDelegated() {
val expected = Session("a", "b")
sut.session = Session("a", "b")
@ -41,8 +44,9 @@ internal class NetworkSessionLocalStorageAdapterTest {
verifyNoMoreInteractions(mockUserDataLocalStorage)
}
@DisplayName("WHEN session requested THEN its returned from delegated")
@Test
fun WHEN_session_requested_THEN_its_returned_from_delegated() {
fun gettingSessionReturnsFromDelegate() {
val expected = Session("a", "b")
whenever(mockUserDataLocalStorage.session).doReturn(expected)