Skip to content

Commit

Permalink
inject factory into test
Browse files Browse the repository at this point in the history
  • Loading branch information
cmathew committed Oct 27, 2023
1 parent 9cd3f7e commit 4847704
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.wealthfront.magellan.sample.migration

import com.wealthfront.magellan.sample.migration.api.DogApi
import com.wealthfront.magellan.sample.migration.tide.DogDetailsScreenTest
import com.wealthfront.magellan.sample.migration.tide.DogListStepTest
import com.wealthfront.magellan.sample.migration.toolbar.ToolbarHelper
import dagger.Component
Expand All @@ -14,6 +13,5 @@ interface TestAppComponent : AppComponent {
val toolbarHelper: ToolbarHelper
val api: DogApi

fun inject(test: DogDetailsScreenTest)
fun inject(test: DogListStepTest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import javax.inject.Inject

@RunWith(RobolectricTestRunner::class)
class DogListStepTest {

private var chosenBreed: String? = null
private lateinit var dogListStep: DogListStep
@Inject lateinit var dogListStepFactory: DogListStepFactory
private val activityController = Robolectric.buildActivity(ComponentActivity::class.java)

private var chosenBreed: String? = null

@Before
fun setUp() {
val context = ApplicationProvider.getApplicationContext<Application>()
val component = ((context as AppComponentContainer).injector() as TestAppComponent)
dogListStep = DogListStep(component.toolbarHelper, component.api) { chosenBreed = it }
component.inject(this)
dogListStep = dogListStepFactory.create { chosenBreed = it }
coWhen { component.api.getAllBreeds() }
.thenReturn(DogBreedsResponse(message = mapOf("akita" to emptyList()), status = "success"))
}
Expand Down

0 comments on commit 4847704

Please sign in to comment.