Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thebino committed Aug 24, 2023
1 parent a91322c commit 500e122
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ val domainPhotosModule = module {

factory {
GetFacesUseCase(
application = get(),
photoRepository = get(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
*/
package photos.network.domain.photos.usecase

import android.app.Application
import android.graphics.Bitmap
import android.net.Uri
import android.provider.MediaStore
import kotlinx.coroutines.flow.Flow
import photos.network.repository.photos.PhotoRepository
import photos.network.repository.photos.model.Box

class GetFacesUseCase(
private val application: Application,
private val photoRepository: PhotoRepository,
) {
operator fun invoke(photoUri: Uri): Flow<List<Box>> {
return photoRepository.getFaces(photoUri = photoUri)
val bitmap: Bitmap = MediaStore.Images.Media.getBitmap(application.contentResolver, photoUri)
return photoRepository.getFaces(bitmap = bitmap)
}
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ val repositoryPhotosModule = module {

single<PhotoRepository> {
PhotoRepositoryImpl(
application = get(),
photoApi = get(),
photoDao = get(),
workManager = get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package photos.network.repository.photos

import android.net.Uri
import android.graphics.Bitmap
import kotlinx.coroutines.flow.Flow
import photos.network.repository.photos.model.Box
import photos.network.repository.photos.worker.SyncStatus
Expand All @@ -26,7 +26,7 @@ interface PhotoRepository {
fun getPhotos(): Flow<List<Photo>>
fun getPhoto(identifier: String): Flow<Photo?>

fun getFaces(photoUri: Uri): Flow<List<Box>>
fun getFaces(bitmap: Bitmap): Flow<List<Box>>

suspend fun addPhoto(photo: Photo)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
package photos.network.repository.photos

import android.app.Application
import android.content.res.AssetManager
import android.graphics.Bitmap
import android.net.Uri
import androidx.work.Constraints
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType
Expand All @@ -39,7 +37,6 @@ import java.time.Instant
import java.util.concurrent.TimeUnit

class PhotoRepositoryImpl(
private val application: Application,
private val mediaStore: MediaStore,
private val photoApi: PhotoApi,
private val photoDao: PhotoDao,
Expand Down Expand Up @@ -115,12 +112,10 @@ class PhotoRepositoryImpl(
photoDao.insertAll(photos = arrayOf(photo.toDatabasePhoto()))
}

override fun getFaces(photoUri: Uri): Flow<List<Box>> {
override fun getFaces(bitmap: Bitmap): Flow<List<Box>> {
return flow {
emit(emptyList())

val bitmap: Bitmap = android.provider.MediaStore.Images.Media.getBitmap(application.contentResolver, photoUri)

val faces = MTCNN(assetManager).detectFaces(
bitmap,
40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package photos.network.repository.photos

import android.content.Context
import android.content.res.AssetManager
import androidx.work.WorkManager
import com.google.common.truth.Truth
import io.mockk.every
Expand All @@ -33,7 +33,7 @@ import photos.network.system.mediastore.MediaStore
*/
class PhotoRepositoryTest {

private val applicationContext = mockk<Context>()
private val assetManager = mockk<AssetManager>()
private val photoApi = mockk<PhotoApi>()
private val photoDao = mockk<PhotoDao>()
private val mediaStore = mockk<MediaStore>()
Expand All @@ -45,6 +45,7 @@ class PhotoRepositoryTest {
photoDao = photoDao,
workManager = workManager,
mediaStore = mediaStore,
assetManager = assetManager,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Before
import org.junit.Test
import photos.network.domain.photos.usecase.GetFacesUseCase
import photos.network.domain.photos.usecase.GetPhotosUseCase
import photos.network.domain.photos.usecase.StartPhotosSyncUseCase
import photos.network.domain.settings.usecase.GetSettingsUseCase
Expand All @@ -45,12 +46,14 @@ class PhotosViewModelTests {
private val togglePrivacyUseCase = mockk<TogglePrivacyUseCase>()
private val getPhotosUseCase = mockk<GetPhotosUseCase>()
private val startPhotosSyncUseCase = mockk<StartPhotosSyncUseCase>()
private val getFacesUseCase = mockk<GetFacesUseCase>()
private val viewmodel by lazy {
photos.network.ui.photos.PhotosViewModel(
getSettingsUseCase = getSettingsUseCase,
togglePrivacyStateUseCase = togglePrivacyUseCase,
getPhotosUseCase = getPhotosUseCase,
startPhotosSyncUseCase = startPhotosSyncUseCase,
getFacesUseCase = getFacesUseCase
)
}
private val photo1 = Photo(
Expand Down

0 comments on commit 500e122

Please sign in to comment.