Skip to content

Commit

Permalink
Update dependencies (#20)
Browse files Browse the repository at this point in the history
* Update all versions

* Remove stately and include coroutines-core-common

* Try to fix iOS tests even though there is still one of them that won't work

* Fix iOS tests

* Fix linting
  • Loading branch information
Serchinastico authored Sep 17, 2019
1 parent db44700 commit b977683
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 32 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
org.gradle.jvmargs=-Xmx1536m
org.gradle.parallel=true
# kotlin
kotlin_version=1.3.41
kotlin_version=1.3.50
# android
gradle_android_version=3.4.1
gradle_android_version=3.5.0
# detekt
detekt_version=1.0.0-RC14
detekt_version=1.0.1
#ktor
ktor_version=1.2.2
ktor_version=1.2.4
#coroutines
coroutines_version=1.2.2
coroutines_version=1.3.1
#serialization
serialization_version=0.11.0
serialization_version=0.13.0

android.useAndroidX=true
android.enableJetifier=true
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Jun 11 20:16:29 CEST 2019
#Tue Sep 17 09:09:07 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import Nimble
import Shared

class PhotoListViewControllerTests: AcceptanceTestCase {

func testDisplayTenPhotoItemsWithTheAuthorName() {
givenPhotos()

openPhotoListViewController()

let tableView = tester().waitForView(withAccessibilityLabel: "PhotoCollectionView") as! UICollectionView
expect(tableView.numberOfItems(inSection: 0)).to(equal(10))
expectToShowPhotoList(withNumberOfItems: 10)
}

func testNotDisplayErrorTextWhenThereAreItems() {
Expand All @@ -33,6 +32,8 @@ class PhotoListViewControllerTests: AcceptanceTestCase {
}

func testDisplayLoadingActivityBeforeGettingPhotos() {
givenAlwaysLoading()

openPhotoListViewController()

tester().waitForView(withAccessibilityLabel: "LoadingView")
Expand All @@ -53,9 +54,16 @@ class PhotoListViewControllerTests: AcceptanceTestCase {

tester().waitForView(withAccessibilityLabel: "Gallery")
}

private func givenAlwaysLoading() {
let injectionModule = TestModule(
apiClient: PhotoApiClientStub(stub: PhotoApiClientStub.StubLoading()))
GalleryInjector().config(injector: injectionModule)
}

private func givenAnError() {
let injectionModule = TestModule(apiClient: PhotoApiClientStub(photos: [PhotoShot](), withErrors: true))
let injectionModule = TestModule(
apiClient: PhotoApiClientStub(stub: PhotoApiClientStub.StubError()))
GalleryInjector().config(injector: injectionModule)
}

Expand All @@ -70,12 +78,12 @@ class PhotoListViewControllerTests: AcceptanceTestCase {
)
photos.append(photo)
}
let injectionModule = TestModule(apiClient: PhotoApiClientStub(photos: photos, withErrors: false))
let injectionModule = TestModule(apiClient: PhotoApiClientStub(stub: PhotoApiClientStub.StubSuccess(photos: photos)))
GalleryInjector().config(injector: injectionModule)
}

@discardableResult
fileprivate func openPhotoListViewController() -> PhotoListViewController {
private func openPhotoListViewController() -> PhotoListViewController {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let photosViewController = storyboard.instantiateViewController(withIdentifier: "PhotoListViewController") as! PhotoListViewController
let rootViewController = UINavigationController()
Expand All @@ -84,6 +92,12 @@ class PhotoListViewControllerTests: AcceptanceTestCase {
tester().waitForAnimationsToFinish()
return photosViewController
}

private func expectToShowPhotoList(withNumberOfItems numberOfItems: Int) {
let tableView = tester().waitForView(withAccessibilityLabel: "PhotoCollectionView") as! UICollectionView
tester().waitForCell(at: IndexPath(item: 0, section: 0), inCollectionViewWithAccessibilityIdentifier: "PhotoCollectionView")
expect(tableView.numberOfItems(inSection: 0)).to(equal(numberOfItems))
}

class TestModule: InjectionModule {

Expand Down
2 changes: 1 addition & 1 deletion shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ kotlin {
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
implementation "co.touchlab:stately:0.9.2"

implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-json:$ktor_version"
Expand All @@ -49,6 +48,7 @@ kotlin {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"

//implementation "io.ktor:ktor-client-mock-native:$ktor_version"
api "io.ktor:ktor-client-mock:$ktor_version"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package com.karumi.gallery.app

import co.touchlab.stately.concurrency.AtomicReference
import co.touchlab.stately.concurrency.value
import co.touchlab.stately.freeze
import com.karumi.gallery.data.PhotosApiClient
import com.karumi.gallery.data.getEngine
import com.karumi.gallery.generated.KotlinConfig
import com.karumi.gallery.usecase.GetPhotos
import kotlin.native.concurrent.ThreadLocal

@ThreadLocal
object GalleryInjector {
private val galleryInjector = AtomicReference<InjectionModule?>(null)
private var galleryInjector: InjectionModule? = null
private val defaultInjector = InjectionModule()

operator fun invoke(): InjectionModule =
galleryInjector.value ?: defaultInjector
galleryInjector ?: defaultInjector

fun config(injector: InjectionModule) {
galleryInjector.value = injector.freeze()
galleryInjector = injector
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ package com.karumi.gallery.data.test
import com.karumi.gallery.data.PhotosApiClient
import com.karumi.gallery.data.getEngine
import com.karumi.gallery.model.Photos
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.delay

class PhotoApiClientStub(
private val photos: Photos,
private val withErrors: Boolean = false
private val stub: Stub
) : PhotosApiClient(getEngine(), "") {

override suspend fun getPhotos(): Photos = runBlocking {
throwErroIfNeeded()
photos
}

private fun throwErroIfNeeded() {
if (withErrors) {
throw RuntimeException()
override suspend fun getPhotos(): Photos =
when (stub) {
is Stub.Success -> stub.photos
is Stub.Error -> throw RuntimeException()
is Stub.Loading -> {
delay(10000)
listOf()
}
}

sealed class Stub {
data class Success(val photos: Photos) : Stub()
object Error : Stub()
object Loading : Stub()
}
}

0 comments on commit b977683

Please sign in to comment.