This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class MainApplication : Application() { | |
| @Inject | |
| lateinit var daggerHouse: DaggerHouse | |
| override fun onCreate() { | |
| super.onCreate() | |
| DaggerDaggerComponent.create().inject(this) | |
| daggerHouse.door.open() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | @Component(modules = [DaggerModule::class]) | |
| interface DaggerComponent { | |
| fun house(): DaggerHouse | |
| fun door(): Door | |
| fun inject(mainApplication: MainApplication) | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | @Module | |
| class DaggerModule { | |
| @Provides | |
| fun providesHouse(door: Door): DaggerHouse = DaggerHouse(door) | |
| @Provides | |
| fun providesDoor() : Door = DoorImpl() | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class DaggerHouse @Inject constructor(val door: Door) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class MainApplication : Application() { | |
| lateinit var house: House | |
| override fun onCreate() { | |
| super.onCreate() | |
| house = House() | |
| house.door.open() | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class House { | |
| val door: Door = DoorImpl() | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | interface Door { | |
| fun open() | |
| } | |
| class DoorImpl : Door { | |
| override fun open() { | |
| Log.println(Log.VERBOSE, null, "Opening door") | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | val movieById1 = movieDao.findById(1).blockingFirst() | |
| Assert.assertEquals(movieById1[0].title, movie1.title) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | @After | |
| fun closeDb() { | |
| testDatabase.close() | |
| } | |
| @Test | |
| fun testMovieDaoQueries() { | |
| val movie1 = Movie(1, "Batman Begins", "first movie", 3) | |
| movieDao.insert(movie1) |