oligazar
8/25/2017 - 11:50 AM

Unit Tests

Unit Tests


    // This setup is that actually works
    // https://github.com/powermock/powermock/wiki/Mockito-2-Maven
    
// Dependencies for local unit tests
    testImplementation "junit:junit:4.12"
    testImplementation "org.hamcrest:hamcrest-all:1.3"
    
    // lets befriend kotling with Mockito
    testCompile ("com.nhaarman:mockito-kotlin:0.9.0", {
        exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib'
    })
    
    // testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:1.5.0"
    // testImplementation group: 'com.nhaarman', name: 'mockito-kotlin', version: '1.6.0'
    
    // Use either Mockito
    testImplementation "org.mockito:mockito-core:2.8.47"
    //testImplementation "org.mockito:mockito-all:1.10.19"
    
    // OR PowerMock instead, but NOT TOGETHER!
    testImplementation "org.powermock:powermock-module-junit4:1.7.1"
    testImplementation "org.powermock:powermock-api-mockito:1.7.1"

//      any() matches to this:
//      NotesServiceApi.NotesServiceCallback::class.java
        verify<NotesServiceApiImpl>(mServiceApi).getAllNotes(any())
// full version:
//      verify<NotesServiceApiImpl>(mServiceApi)
//             .getAllNotes(any<NotesServiceApi.NotesServiceCallback<List<Note>>>())