Skip to content

Instantly share code, notes, and snippets.

View mitrejcevski's full-sized avatar

Jovche Mitrejchevski mitrejcevski

View GitHub Profile
class TestingTripsController: TripsController {
override fun findTripsFor(userId: UserId): List<Trip> {
return listOf(tripToAmsterdam, tripToLondon)
}
}
open class TripsController {
...
fun someTripsCheck() {
...
val trips = findTripsFor(userId)
...
}
protected open fun findTripsFor(userId: UserId): List<Trip> {
return TripsDao.findTripsFor(userId)
class TripsController {
...
fun someTripsCheck() {
...
val trips = TripsDao.findTripsFor(userId)
...
}
}
@Test
fun find_users_by_id() {
val userId = UUID.randomUUID()
val john = aUser().withUserId(userId).build()
val usersCatalog = InMemoryUsersCatalogIncluding(john)
val userFound = usersCatalog.findByUserId(userId)
assertEquals(john, userFound)
}
@Test
fun find_users_by_id() {
val userId = UUID.randomUUID()
val john = User(userId, "John", "Doe", 30, Location.UNKNOWN)
val usersCatalog = InMemoryUsersCatalogIncluding(john)
val userFound = usersCatalog.findByUserId(userId)
assertEquals(john, userFound)
}
data class User(
val userId: UUID,
val firstName: String,
val lastName: String,
val age: Int,
val location: Location
)
class RoboTestRunner : AndroidJUnitRunner() {
override fun newApplication(
classLoader: ClassLoader?,
className: String?,
context: Context?
): Application {
return super.newApplication(classLoader, TestRoboApp::class.java.name, context)
}
}
@Before
fun setUp() {
loadKoinModules(loginModule)
}
@After
fun tearDown() {
unloadKoinModules(loginModule)
}
class TestRoboApp : Application() {
override fun onCreate() {
super.onCreate()
startKoin { }
}
override fun onTerminate() {
stopKoin()
super.onTerminate()
private val loginModule = module {
val credentialsValidator = LoginCredentialsValidator()
val loginApi = InMemoryLoginApi()
val loginRepository = RemoteLoginRepository(loginApi)
viewModel {
LoginViewModel(credentialsValidator, loginRepository)
}
}
@Before