forked from gpeal/Anvil-Sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a unit test for the code generator.
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
32 changes: 32 additions & 0 deletions
32
...test/java/com/gpeal/droidconanvilsample/anvilcompilers/ContributesApiCodeGeneratorTest.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.gpeal.droidconanvilsample.anvilcompilers | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import com.squareup.anvil.compiler.internal.testing.compileAnvil | ||
import com.tschuchort.compiletesting.KotlinCompilation.ExitCode.OK | ||
import dagger.Provides | ||
import dagger.Reusable | ||
import org.junit.Test | ||
|
||
class ContributesApiCodeGeneratorTest { | ||
|
||
@Test fun `a dagger module is generated`() { | ||
compileAnvil( | ||
""" | ||
package com.test | ||
import com.gpeal.droidconanvilsample.lib.daggerscopes.ContributesApi | ||
@ContributesApi | ||
interface TestApi | ||
""" | ||
) { | ||
assertThat(exitCode).isEqualTo(OK) | ||
|
||
val clazz = classLoader.loadClass("com.test.TestApi_Module") | ||
val providerMethod = clazz.declaredMethods.single() | ||
|
||
assertThat(providerMethod.returnType).isEqualTo(classLoader.loadClass("com.test.TestApi")) | ||
assertThat(providerMethod.annotations.map { it.annotationClass }).containsExactly(Provides::class, Reusable::class) | ||
} | ||
} | ||
} |