Skip to content

Commit

Permalink
It has been refactored for tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
fevziomurtekin committed Oct 1, 2020
1 parent f8cfa72 commit 16cb8ae
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 22 deletions.
Binary file modified .gradle/6.6-rc-6/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/6.6-rc-6/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/6.6-rc-6/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/6.6-rc-6/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fevziomurtekin.deezer_clone.domain.network

import com.fevziomurtekin.deezer_clone.core.ApiAbstract
import com.fevziomurtekin.deezer_clone.core.MockUtil
import com.fevziomurtekin.deezer_clone.di.MainCoroutinesRule
import io.mockk.mockk
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -48,10 +49,10 @@ class DeezerServiceTest : ApiAbstract<DeezerService>() {
fun fetchArtistList() = runBlocking {
enqueueResponse("/artistsResponse.json")
// give to default genreID
val responseBody = service.fetchArtistList("0").await()
val responseBody = service.fetchArtistList(MockUtil.genreID).await()
mockWebServer.takeRequest()

client.fetchArtistList("0").getCompleted()
client.fetchArtistList(MockUtil.genreID).getCompleted()
assertThat(responseBody.artistData[0].id, `is`("8354140"))
assertThat(responseBody.artistData[0].type, `is`("artist"))
assertThat(responseBody.artistData[0].name, `is`("ezhel"))
Expand All @@ -63,10 +64,10 @@ class DeezerServiceTest : ApiAbstract<DeezerService>() {
fun fetchArtistDetails() = runBlocking {
enqueueResponse("/artistDetailsResponse.json")
// give to default genreID
val responseBody = service.fetchArtistDetails("8354140").await()
val responseBody = service.fetchArtistDetails(MockUtil.artistID).await()
mockWebServer.takeRequest()

client.fetchArtistList("0").getCompleted()
client.fetchArtistDetails(MockUtil.artistID).getCompleted()
assertThat(responseBody.id, `is`("8354140"))
assertThat(responseBody.type, `is`("artist"))
assertThat(responseBody.name, `is`("ezhel"))
Expand All @@ -79,10 +80,10 @@ class DeezerServiceTest : ApiAbstract<DeezerService>() {
fun fetchArtistAlbums() = runBlocking {
enqueueResponse("/artistAlbumsResponse.json")
// give to default genreID
val responseBody = service.fetchArtistAlbums("8354140").await()
val responseBody = service.fetchArtistAlbums(MockUtil.artistID).await()
mockWebServer.takeRequest()

client.fetchArtistList("8354140").getCompleted()
client.fetchArtistList(MockUtil.artistID).getCompleted()
assertThat(responseBody.total, `is`(20))
assertThat(responseBody.data[0].title, `is`("Müptezhel"))
assertThat(responseBody.data[0].id,`is`("51174732"))
Expand All @@ -94,10 +95,10 @@ class DeezerServiceTest : ApiAbstract<DeezerService>() {
fun fetchArtistRelated() = runBlocking {
enqueueResponse("/artistRelatedResponse.json")
// give to default genreID
val responseBody = service.fetchArtistRelated("8354140").await()
val responseBody = service.fetchArtistRelated(MockUtil.artistID).await()
mockWebServer.takeRequest()

client.fetchArtistList("8354140").getCompleted()
client.fetchArtistList(MockUtil.albumID).getCompleted()
assertThat(responseBody.data[0].id, `is`("389038"))
assertThat(responseBody.data[0].type, `is`("artist"))
assertThat(responseBody.data[0].name, `is`("Murda"))
Expand All @@ -109,10 +110,10 @@ class DeezerServiceTest : ApiAbstract<DeezerService>() {
fun fetchAlbumDetails() = runBlocking {
enqueueResponse("/albumDetailsResponse.json")
// give to default genreID
val responseBody = service.fetchAlbumDetails("302127").await()
val responseBody = service.fetchAlbumDetails(MockUtil.albumID).await()
mockWebServer.takeRequest()

client.fetchArtistList("302127").getCompleted()
client.fetchArtistList(MockUtil.albumID).getCompleted()
assertThat(responseBody.data[0].id, `is`("3135553"))
assertThat(responseBody.data[0].type, `is`("track"))
assertThat(responseBody.data[0].title, `is`( "One More Time"))
Expand All @@ -124,10 +125,10 @@ class DeezerServiceTest : ApiAbstract<DeezerService>() {
fun fetchSearchAlbum() = runBlocking {
enqueueResponse("/searchAlbumResponse.json")
// give to default genreID
val responseBody = service.fetchSearchAlbum("ezhel").await()
val responseBody = service.fetchSearchAlbum(MockUtil.query).await()
mockWebServer.takeRequest()

client.fetchSearchAlbum("ezhel").getCompleted()
client.fetchSearchAlbum(MockUtil.query).getCompleted()
assertThat(responseBody.data[0].artist.name, `is`("ezhel"))
assertThat(responseBody.data[0].title, `is`("felaket"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AlbumDetailsViewModelTest {
val fetchedData : LiveData<Result<List<AlbumData>>> = mainRepository.fetchAlbumTracks("302127").asLiveData()
fetchedData.observeForever(observer)

viewModel.fetchingAlbumDatas("302127")
viewModel.fetchingAlbumDatas(MockUtil.albumID)
delay(500L)

verify(observer).onChanged(Result.Succes(mockList))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class ArtistAlbumViewModelTest {
val mockList = listOf(MockUtil.artistAlbum)

val observer : Observer<Result<List<ArtistAlbumData>>> = mock()
val fetchedData : LiveData<Result<List<ArtistAlbumData>>> = mainRepository.fetchArtistAlbums("8354140").asLiveData()
val fetchedData : LiveData<Result<List<ArtistAlbumData>>> = mainRepository.fetchArtistAlbums(MockUtil.artistID).asLiveData()
fetchedData.observeForever(observer)

viewModel.fetchArtistAlbum("8354140")
viewModel.fetchArtistAlbum(MockUtil.artistID)
delay(500L)

verify(observer).onChanged(Result.Succes(mockList))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class ArtistDetailsViewModelTest {
val mockList = MockUtil.artistDetails

val observer : Observer<Result<ArtistDetailResponse>> = mock()
val fetchedData : LiveData<Result<ArtistDetailResponse>> = mainRepository.fetchArtistDetails("8354140").asLiveData()
val fetchedData : LiveData<Result<ArtistDetailResponse>> = mainRepository.fetchArtistDetails(MockUtil.artistID).asLiveData()
fetchedData.observeForever(observer)

viewModel.fetchArtistDetails("8354140")
viewModel.fetchArtistDetails(MockUtil.artistID)
delay(500L)

verify(observer).onChanged(Result.Succes(mockList))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class ArtistRelatedViewModelTest {
val mockList = listOf(MockUtil.artistRelatedData)

val observer : Observer<Result<List<ArtistRelatedData>>> = mock()
val fetchedData : LiveData<Result<List<ArtistRelatedData>>> = mainRepository.fetchArtistRelated("8354140").asLiveData()
val fetchedData : LiveData<Result<List<ArtistRelatedData>>> = mainRepository.fetchArtistRelated(MockUtil.artistID).asLiveData()
fetchedData.observeForever(observer)

viewModel.fetchArtistRelated("8354140")
viewModel.fetchArtistRelated(MockUtil.artistID)
delay(500L)

verify(observer).onChanged(Result.Succes(mockList))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class ArtistViewModelTest {
val mockList = listOf(MockUtil.artist)

val observer : Observer<Result<List<ArtistData>>> = mock()
val fetchedData : LiveData<Result<List<ArtistData>>> = mainRepository.fetchArtistList("0").asLiveData()
val fetchedData : LiveData<Result<List<ArtistData>>> = mainRepository.fetchArtistList(MockUtil.genreID).asLiveData()
fetchedData.observeForever(observer)

viewModel.fetchResult("0")
viewModel.fetchResult(MockUtil.genreID)
delay(500L)

verify(observer).onChanged(Result.Succes(mockList))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SearchViewModelTest {
whenever(deezerDao.getQueryList()).thenReturn(listOf(mockData))

val observer : Observer<Result<List<SearchData>>> = mock()
val fetchedData : LiveData<Result<List<SearchData>>> = mainRepository.fetchSearch("ezhel").asLiveData()
val fetchedData : LiveData<Result<List<SearchData>>> = mainRepository.fetchSearch(MockUtil.query).asLiveData()
fetchedData.observeForever(observer)

viewModel.fetchingRecentSearch()
Expand Down
Binary file modified buildSrc/.gradle/6.6-rc-6/executionHistory/executionHistory.lock
Binary file not shown.

0 comments on commit 16cb8ae

Please sign in to comment.