diff --git a/.gradle/6.6-rc-6/executionHistory/executionHistory.bin b/.gradle/6.6-rc-6/executionHistory/executionHistory.bin index a99e5e9e..a80feae0 100644 Binary files a/.gradle/6.6-rc-6/executionHistory/executionHistory.bin and b/.gradle/6.6-rc-6/executionHistory/executionHistory.bin differ diff --git a/.gradle/6.6-rc-6/executionHistory/executionHistory.lock b/.gradle/6.6-rc-6/executionHistory/executionHistory.lock index 79d30a45..946a4bdb 100644 Binary files a/.gradle/6.6-rc-6/executionHistory/executionHistory.lock and b/.gradle/6.6-rc-6/executionHistory/executionHistory.lock differ diff --git a/.gradle/6.6-rc-6/fileHashes/fileHashes.bin b/.gradle/6.6-rc-6/fileHashes/fileHashes.bin index c249c87c..726506a7 100644 Binary files a/.gradle/6.6-rc-6/fileHashes/fileHashes.bin and b/.gradle/6.6-rc-6/fileHashes/fileHashes.bin differ diff --git a/.gradle/6.6-rc-6/fileHashes/fileHashes.lock b/.gradle/6.6-rc-6/fileHashes/fileHashes.lock index 2a276612..ea836146 100644 Binary files a/.gradle/6.6-rc-6/fileHashes/fileHashes.lock and b/.gradle/6.6-rc-6/fileHashes/fileHashes.lock differ diff --git a/.gradle/6.6-rc-6/fileHashes/resourceHashesCache.bin b/.gradle/6.6-rc-6/fileHashes/resourceHashesCache.bin index 2656b591..cf77f185 100644 Binary files a/.gradle/6.6-rc-6/fileHashes/resourceHashesCache.bin and b/.gradle/6.6-rc-6/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/6.6-rc-6/javaCompile/classAnalysis.bin b/.gradle/6.6-rc-6/javaCompile/classAnalysis.bin index 6d0bbb2a..3a904192 100644 Binary files a/.gradle/6.6-rc-6/javaCompile/classAnalysis.bin and b/.gradle/6.6-rc-6/javaCompile/classAnalysis.bin differ diff --git a/.gradle/6.6-rc-6/javaCompile/jarAnalysis.bin b/.gradle/6.6-rc-6/javaCompile/jarAnalysis.bin index 931d3002..edbdd0a7 100644 Binary files a/.gradle/6.6-rc-6/javaCompile/jarAnalysis.bin and b/.gradle/6.6-rc-6/javaCompile/jarAnalysis.bin differ diff --git a/.gradle/6.6-rc-6/javaCompile/javaCompile.lock b/.gradle/6.6-rc-6/javaCompile/javaCompile.lock index 99f4a294..709a7255 100644 Binary files a/.gradle/6.6-rc-6/javaCompile/javaCompile.lock and b/.gradle/6.6-rc-6/javaCompile/javaCompile.lock differ diff --git a/.gradle/6.6-rc-6/javaCompile/taskHistory.bin b/.gradle/6.6-rc-6/javaCompile/taskHistory.bin index 57daf45d..6f969739 100644 Binary files a/.gradle/6.6-rc-6/javaCompile/taskHistory.bin and b/.gradle/6.6-rc-6/javaCompile/taskHistory.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index e1b8ed55..2bfb9cc1 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 7e1b41a4..28e6d75e 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/app/src/main/java/com/fevziomurtekin/deezer_clone/domain/network/DeezerClient.kt b/app/src/main/java/com/fevziomurtekin/deezer_clone/domain/network/DeezerClient.kt index 294b367a..31ce4719 100644 --- a/app/src/main/java/com/fevziomurtekin/deezer_clone/domain/network/DeezerClient.kt +++ b/app/src/main/java/com/fevziomurtekin/deezer_clone/domain/network/DeezerClient.kt @@ -9,7 +9,7 @@ class DeezerClient @Inject constructor( fun fetchGenreList() = deezerService.fetchGenreList() - fun fetchArtistList(genreId:String) + suspend fun fetchArtistList(genreId:String) = deezerService.fetchArtistList(genreId) fun fetchArtistDetails(artistID: String) diff --git a/app/src/main/java/com/fevziomurtekin/deezer_clone/domain/network/DeezerService.kt b/app/src/main/java/com/fevziomurtekin/deezer_clone/domain/network/DeezerService.kt index a4a3a608..e8d8d212 100644 --- a/app/src/main/java/com/fevziomurtekin/deezer_clone/domain/network/DeezerService.kt +++ b/app/src/main/java/com/fevziomurtekin/deezer_clone/domain/network/DeezerService.kt @@ -20,7 +20,7 @@ interface DeezerService{ :Deferred @GET("genre/{genreId}/artists") - fun fetchArtistList(@Path("genreId") genreId:String) + suspend fun fetchArtistList(@Path("genreId") genreId:String) :Deferred @GET("artist/{artistId}") diff --git a/app/src/test/java/com/fevziomurtekin/deezer_clone/core/MockUtil.kt b/app/src/test/java/com/fevziomurtekin/deezer_clone/core/MockUtil.kt index 94d9008b..07658412 100644 --- a/app/src/test/java/com/fevziomurtekin/deezer_clone/core/MockUtil.kt +++ b/app/src/test/java/com/fevziomurtekin/deezer_clone/core/MockUtil.kt @@ -23,9 +23,9 @@ object MockUtil { val genres = listOf(data) - val searchData = SearchQuery("1","ezhel",12345.toLong()) + val recentData = SearchQuery("1","ezhel",12345.toLong()) - val searchList = listOf(searchData) + val searchList = listOf(recentData) val album = AlbumData( id="3135553",readable = true,title = "One More Time",title_short = "One More Time",title_version = "", @@ -75,7 +75,7 @@ object MockUtil { nb_album = 20,nb_fan =565833 ) - val recentData = SearchData( + val searchData = SearchData( id = "51174732",title = "Müptezhel" ,link = "https://www.deezer.com/album/51174732", cover = "https://api.deezer.com/album/51174732/image", cover_small = "https://e-cdns-images.dzcdn.net/images/cover/35d715873d3e8ae76a998f6bf38e1fa8/56x56-000000-80-0-0.jpg", @@ -92,4 +92,9 @@ object MockUtil { tracklist = "https://api.deezer.com/artist/8354140/top?limit=50",type = "artist",link ="https://www.deezer.com/artist/8354140", ), tracklist = "https://api.deezer.com/album/51174732/tracks", explicit_lyrics = true, type = "album" ) + + val genreID = "116" + val artistID = "8354140" + val albumID = "51174732" + val query = "Ezhel" } \ No newline at end of file diff --git a/app/src/test/java/com/fevziomurtekin/deezer_clone/domain/local/DeezerDaoTest.kt b/app/src/test/java/com/fevziomurtekin/deezer_clone/domain/local/DeezerDaoTest.kt index 5c5d7677..ac18e168 100644 --- a/app/src/test/java/com/fevziomurtekin/deezer_clone/domain/local/DeezerDaoTest.kt +++ b/app/src/test/java/com/fevziomurtekin/deezer_clone/domain/local/DeezerDaoTest.kt @@ -39,7 +39,7 @@ class DeezerDaoTest:LocalDatabase(){ @Test fun insertAndLoadSearchQuery() = runBlocking{ - val mockSearchData = MockUtil.searchData + val mockSearchData = MockUtil.recentData deezerDao.insertQuery(mockSearchData) val mockSearchList = MockUtil.searchList diff --git a/app/src/test/java/com/fevziomurtekin/deezer_clone/repository/MainRepositoryTest.kt b/app/src/test/java/com/fevziomurtekin/deezer_clone/repository/MainRepositoryTest.kt index de0e06d9..f36152f8 100644 --- a/app/src/test/java/com/fevziomurtekin/deezer_clone/repository/MainRepositoryTest.kt +++ b/app/src/test/java/com/fevziomurtekin/deezer_clone/repository/MainRepositoryTest.kt @@ -5,16 +5,21 @@ import androidx.lifecycle.asLiveData import app.cash.turbine.test import com.fevziomurtekin.deezer_clone.core.MockUtil import com.fevziomurtekin.deezer_clone.core.Result +import com.fevziomurtekin.deezer_clone.data.albumdetails.AlbumData +import com.fevziomurtekin.deezer_clone.data.albumdetails.AlbumDetailsResponse +import com.fevziomurtekin.deezer_clone.data.artist.ArtistData +import com.fevziomurtekin.deezer_clone.data.artist.ArtistsResponse +import com.fevziomurtekin.deezer_clone.data.artistdetails.* import com.fevziomurtekin.deezer_clone.data.genre.Data import com.fevziomurtekin.deezer_clone.data.genre.GenreResponse +import com.fevziomurtekin.deezer_clone.data.search.SearchData +import com.fevziomurtekin.deezer_clone.data.search.SearchQuery +import com.fevziomurtekin.deezer_clone.data.search.SearchResponse import com.fevziomurtekin.deezer_clone.di.MainCoroutinesRule import com.fevziomurtekin.deezer_clone.domain.local.DeezerDao import com.fevziomurtekin.deezer_clone.domain.network.DeezerClient import com.fevziomurtekin.deezer_clone.domain.network.DeezerService -import com.nhaarman.mockitokotlin2.atLeastOnce -import com.nhaarman.mockitokotlin2.mock -import com.nhaarman.mockitokotlin2.verify -import com.nhaarman.mockitokotlin2.whenever +import com.nhaarman.mockitokotlin2.* import kotlinx.coroutines.CompletableDeferred import org.junit.Assert.assertEquals import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -51,7 +56,7 @@ class MainRepositoryTest { fun fetchGenreListFromNetworkTest() = runBlocking { val mockData = GenreResponse(MockUtil.genres) val deferredData = CompletableDeferred(mockData) - whenever(deezerDao.getQueryList()).thenReturn(emptyList()) + whenever(deezerDao.getGenreList()).thenReturn(emptyList()) whenever(service.fetchGenreList()).thenReturn(deferredData) /** core testing */ @@ -70,10 +75,176 @@ class MainRepositoryTest { } verify(deezerDao, atLeastOnce()).getGenreList() - verify(service, atLeastOnce()).fetchGenreList() + verify(service, atLeastOnce()).fetchGenreList().await() verify(deezerDao, atLeastOnce()).insertGenreList(MockUtil.genres) } + @ExperimentalTime + @Test + fun fetchArtistListFromNetworkTest() = runBlocking { + val mockData = ArtistsResponse(listOf(MockUtil.artist)) + val deferredData = CompletableDeferred(mockData) + whenever(service.fetchArtistList(MockUtil.genreID)).thenReturn(deferredData) + + repository.fetchArtistList(MockUtil.genreID).test { + val result = expectItem() + assertEquals(result, Result.Succes(listOf(MockUtil.artist))) + assertEquals((result as Result.Succes>).data[0].name , "Ezhel") + assertEquals(result.data[0].id , "8354140") + assertEquals(result.data[1].name , "Sagopa Kajmer") + assertEquals(result.data[1].id , "12934") + expectComplete() + } + + verify(service, atLeastOnce()).fetchArtistList(MockUtil.genreID).await() + verifyNoMoreInteractions(service) + } + + + + @ExperimentalTime + @Test + fun fetchArtistDetailsFromNetworkTest() = runBlocking { + val mockData = MockUtil.artistDetails + val deferredData = CompletableDeferred(mockData) + whenever(service.fetchArtistDetails(MockUtil.artistID)).thenReturn(deferredData) + + repository.fetchArtistDetails(MockUtil.artistID).test { + val result = expectItem() + assertEquals(result, Result.Succes(mockData)) + assertEquals((result as Result.Succes).data.name , "Ezhel") + assertEquals(result.data.id , "8354140") + expectComplete() + } + + verify(service, atLeastOnce()).fetchArtistList(MockUtil.artistID).await() + verifyNoMoreInteractions(service) + } + + @ExperimentalTime + @Test + fun fetchArtistAlbumsFromNetworkTest() = runBlocking { + val mockData = ArtistAlbumResponse(data= listOf(MockUtil.artistAlbum),next= "",total=20) + val deferredData = CompletableDeferred(mockData) + whenever(service.fetchArtistAlbums(MockUtil.artistID)).thenReturn(deferredData) + + repository.fetchArtistAlbums(MockUtil.artistID).test { + val result = expectItem() + assertEquals(result, Result.Succes(listOf(MockUtil.artistAlbum))) + assertEquals((result as Result.Succes>).data[0].title , "Müptezhel") + assertEquals(result.data[0].id , "51174732") + assertEquals(result.data[1].title , "Made In Turkey") + assertEquals(result.data[1].id , "155597932") + expectComplete() + } + + verify(service, atLeastOnce()).fetchArtistAlbums(MockUtil.artistID).await() + verifyNoMoreInteractions(service) + } + + @ExperimentalTime + @Test + fun fetchArtistRelatedFromNetworkTest() = runBlocking { + val mockData = ArtistRelatedResponse(data= listOf(MockUtil.artistRelatedData),total=20) + val deferredData = CompletableDeferred(mockData) + whenever(service.fetchArtistRelated(MockUtil.artistID)).thenReturn(deferredData) + + repository.fetchArtistRelated(MockUtil.artistID).test { + val result = expectItem() + assertEquals(result, Result.Succes(listOf(MockUtil.artistRelatedData))) + assertEquals((result as Result.Succes>).data[0].name , "Murda") + assertEquals(result.data[0].id , "389038") + assertEquals(result.data[1].name , "Reynmen") + assertEquals(result.data[1].id , "13136341") + expectComplete() + } + + verify(service, atLeastOnce()).fetchArtistRelated(MockUtil.artistID).await() + verifyNoMoreInteractions(service) + } + + + @ExperimentalTime + @Test + fun fetchAlbumTracksFromNetworkTest() = runBlocking { + val mockData = AlbumDetailsResponse(data= listOf(MockUtil.album),total=12) + val deferredData = CompletableDeferred(mockData) + whenever(service.fetchAlbumDetails(MockUtil.albumID)).thenReturn(deferredData) + + repository.fetchAlbumTracks(MockUtil.albumID).test { + val result = expectItem() + assertEquals(result, Result.Succes(listOf(MockUtil.album))) + assertEquals((result as Result.Succes>).data[0].title , "Alo") + assertEquals(result.data[0].id , "425605922") + assertEquals(result.data[1].title , "Geceler") + assertEquals(result.data[1].id , "425605932") + expectComplete() + } + + verify(service, atLeastOnce()).fetchAlbumDetails(MockUtil.albumID).await() + verifyNoMoreInteractions(service) + } + + @ExperimentalTime + @Test + fun fetchRecentSearchFromDaoTest() = runBlocking { + val mockData = listOf(MockUtil.recentData) + whenever(deezerDao.getQueryList()).thenReturn(mockData) + + repository.fetchRecentSearch().test { + val result = expectItem() + assertEquals(result, mockData) + assertEquals(result[0].q , "Ezhel") + assertEquals(result[0].id , "1") + expectComplete() + } + + verify(deezerDao, atLeastOnce()).getQueryList() + verifyNoMoreInteractions(deezerDao) + } + + + @ExperimentalTime + @Test + fun insertSearchFromDaoTest() = runBlocking { + val mockData = MockUtil.recentData + whenever(deezerDao.getQueryList()).thenReturn(emptyList()) + + /*"1","ezhel",12345.toLong()*/ + repository.insertSearch(mockData) + repository.fetchRecentSearch().test { + val result = expectItem() + assertEquals(result, mockData) + assertEquals(result[0].q , "Ezhel") + assertEquals(result[0].id , "1") + assertEquals(result[0].time,12345.toLong()) + expectComplete() + } + + verify(deezerDao, atLeastOnce()).insertQuery(MockUtil.recentData) + } + + @ExperimentalTime + @Test + fun fetchSearchFromNetworkTest() = runBlocking { + val mockData = SearchResponse(data= listOf(MockUtil.searchData),next="",total=12) + val deferredData = CompletableDeferred(mockData) + whenever(service.fetchSearchAlbum(MockUtil.query)).thenReturn(deferredData) + + repository.fetchSearch(MockUtil.query).test { + val result = expectItem() + assertEquals(result, Result.Succes(listOf(MockUtil.searchData))) + assertEquals((result as Result.Succes>).data[0].title , "İmkansızım") + assertEquals(result.data[0].id , "51434782") + assertEquals(result.data[0].record_type , "single") + assertEquals(result.data[0].genre_id , "116") + expectComplete() + } + + verify(service, atLeastOnce()).fetchSearchAlbum(MockUtil.query).await() + verifyNoMoreInteractions(service) + } + } \ No newline at end of file diff --git a/app/src/test/java/com/fevziomurtekin/deezer_clone/viewmodel/SearchViewModelTest.kt b/app/src/test/java/com/fevziomurtekin/deezer_clone/viewmodel/SearchViewModelTest.kt index aa06996b..37aea5ea 100644 --- a/app/src/test/java/com/fevziomurtekin/deezer_clone/viewmodel/SearchViewModelTest.kt +++ b/app/src/test/java/com/fevziomurtekin/deezer_clone/viewmodel/SearchViewModelTest.kt @@ -51,8 +51,8 @@ class SearchViewModelTest { @Test fun fetchSearchTest() = runBlocking { - val mockData = MockUtil.searchData - val mockList = listOf(MockUtil.recentData) + val mockData = MockUtil.recentData + val mockList = listOf(MockUtil.searchData) whenever(deezerDao.getQueryList()).thenReturn(listOf(mockData)) val observer : Observer>> = mock() diff --git a/buildSrc/.gradle/6.6-rc-6/executionHistory/executionHistory.lock b/buildSrc/.gradle/6.6-rc-6/executionHistory/executionHistory.lock index d42c77af..fabbeef9 100644 Binary files a/buildSrc/.gradle/6.6-rc-6/executionHistory/executionHistory.lock and b/buildSrc/.gradle/6.6-rc-6/executionHistory/executionHistory.lock differ