Skip to content

Instantly share code, notes, and snippets.

View frostyshadows's full-sized avatar
馃

Sherry Yuan frostyshadows

馃
View GitHub Profile
class MainApplication : Application() {
@Inject
lateinit var daggerHouse: DaggerHouse
override fun onCreate() {
super.onCreate()
DaggerDaggerComponent.create().inject(this)
daggerHouse.door.open()
@Component(modules = [DaggerModule::class])
interface DaggerComponent {
fun house(): DaggerHouse
fun door(): Door
fun inject(mainApplication: MainApplication)
}
@Module
class DaggerModule {
@Provides
fun providesHouse(door: Door): DaggerHouse = DaggerHouse(door)
@Provides
fun providesDoor() : Door = DoorImpl()
}
class DaggerHouse @Inject constructor(val door: Door)
class MainApplication : Application() {
lateinit var house: House
override fun onCreate() {
super.onCreate()
house = House()
house.door.open()
}
class House {
val door: Door = DoorImpl()
}
interface Door {
fun open()
}
class DoorImpl : Door {
override fun open() {
Log.println(Log.VERBOSE, null, "Opening door")
}
}
package com.example.sherryuan.moviesdb
import android.arch.persistence.room.Room
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import com.example.sherryuan.moviesdb.database.MovieDao
import com.example.sherryuan.moviesdb.database.MovieDb
import com.example.sherryuan.moviesdb.models.Movie
import org.junit.*
import org.junit.runner.RunWith
val movieById1 = movieDao.findById(1).blockingFirst()
Assert.assertEquals(movieById1[0].title, movie1.title)
@After
fun closeDb() {
testDatabase.close()
}
@Test
fun testMovieDaoQueries() {
val movie1 = Movie(1, "Batman Begins", "first movie", 3)
movieDao.insert(movie1)