Skip to content

Commit 242e838

Browse files
committed
Initial tests and formatting
1 parent 362d704 commit 242e838

File tree

7 files changed

+72
-29
lines changed

7 files changed

+72
-29
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- image: circleci/openjdk:8u222-stretch
4848
steps:
4949
- checkout
50-
- run:
50+
- run:
5151
name: Upload annotations to Bintray
5252
command: ./gradlew :annotations:bintrayUpload --no-daemon --no-build-cache --refresh-dependencies
5353
when: always

annotations/src/main/kotlin/com/google/auto/factory/AutoFactory.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ import kotlin.reflect.KClass
1414
@Retention(AnnotationRetention.BINARY)
1515
@Target(AnnotationTarget.CONSTRUCTOR, AnnotationTarget.TYPE, AnnotationTarget.FUNCTION)
1616
annotation class AutoFactory(
17-
/**
18-
* The <i>simple</i> name of the generated factory; the factory is always generated in the same
19-
* package as the annotated type. The default value (the empty string) will result in a factory
20-
* with the name of the type being created with {@code Factory} appended to the end. For example,
21-
* the default name for a factory for {@code MyType} will be {@code MyTypeFactory}.
22-
*
23-
* <p>If the annotated type is nested, then the generated factory's name will start with the
24-
* enclosing type names, separated by underscores. For example, the default name for a factory for
25-
* {@code Outer.Inner.ReallyInner} is {@code Outer_Inner_ReallyInnerFactory}. If {@code className}
26-
* is {@code Foo}, then the factory name is {@code Outer_Inner_Foo}.
27-
*/
28-
val name: String = "",
29-
/**
30-
* An array of interfaces that the generated factory is required to implement.
31-
*/
32-
val implementing: Array<KClass<out Any>>,
33-
/**
34-
* The type that the generated factory is require to extend.
35-
*/
36-
val extending: KClass<out Any> = Any::class,
37-
/**
38-
* Whether or not the generated factory should be final.
39-
* Defaults to disallowing subclasses (generating the factory as final).
40-
*/
41-
val allowSubclasses: Boolean = false)
17+
/**
18+
* The <i>simple</i> name of the generated factory; the factory is always generated in the same
19+
* package as the annotated type. The default value (the empty string) will result in a factory
20+
* with the name of the type being created with {@code Factory} appended to the end. For example,
21+
* the default name for a factory for {@code MyType} will be {@code MyTypeFactory}.
22+
*
23+
* <p>If the annotated type is nested, then the generated factory's name will start with the
24+
* enclosing type names, separated by underscores. For example, the default name for a factory for
25+
* {@code Outer.Inner.ReallyInner} is {@code Outer_Inner_ReallyInnerFactory}. If {@code className}
26+
* is {@code Foo}, then the factory name is {@code Outer_Inner_Foo}.
27+
*/
28+
val name: String = "",
29+
/**
30+
* An array of interfaces that the generated factory is required to implement.
31+
*/
32+
val implementing: Array<KClass<out Any>>,
33+
/**
34+
* The type that the generated factory is require to extend.
35+
*/
36+
val extending: KClass<out Any> = Any::class,
37+
/**
38+
* Whether or not the generated factory should be final.
39+
* Defaults to disallowing subclasses (generating the factory as final).
40+
*/
41+
val allowSubclasses: Boolean = false)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
versions.dependencies.javax.inject=1
22
versions.dependencies.jsr250-api=1.0
33
versions.dependencies.junit=5.5.2
4-
versions.dependencies.mockito=3.1.0
4+
versions.dependencies.mockito-kotlin=2.2.0
55
versions.dependencies.kotlinpoet=1.4.1

processor/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,14 @@ repositories {
1717
dependencies {
1818
implementation project(":annotations")
1919
api "com.squareup:kotlinpoet:${rootProject."versions.dependencies.kotlinpoet"}"
20+
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:${rootProject."versions.dependencies.mockito-kotlin"}"
21+
testImplementation "org.junit.jupiter:junit-jupiter-api:${rootProject."versions.dependencies.junit"}"
22+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${rootProject."versions.dependencies.junit"}"
23+
}
24+
test {
25+
testLogging {
26+
showStandardStreams = true
27+
}
28+
useJUnitPlatform()
2029
}
2130
apply from: Paths.get(rootDir.absolutePath, ".circleci", "publish.gradle")
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.github.stoyicker.auto.factory.kotlin.processor
22

3+
import com.google.auto.factory.AutoFactory
34
import javax.annotation.processing.AbstractProcessor
5+
import javax.annotation.processing.ProcessingEnvironment
46
import javax.annotation.processing.RoundEnvironment
57
import javax.annotation.processing.SupportedOptions
68
import javax.annotation.processing.SupportedSourceVersion
@@ -9,10 +11,20 @@ import javax.lang.model.element.TypeElement
911

1012
@SupportedSourceVersion(SourceVersion.RELEASE_8)
1113
@SupportedOptions(OPTION_KEY_KAPT_KOTLIN_GENERATED)
12-
class AutoFactoryKotlinProcessor : AbstractProcessor() {
14+
internal class AutoFactoryKotlinProcessor constructor(
15+
private val supportedAnnotationTypes: Set<String>) : AbstractProcessor() {
16+
@Suppress("unused") // Actual constructor used in production
17+
constructor() : this(setOf(AutoFactory::javaClass.name))
18+
19+
override fun init(processingEnv: ProcessingEnvironment?) {
20+
super.init(processingEnv)
21+
}
22+
1323
override fun process(p0: MutableSet<out TypeElement>?, p1: RoundEnvironment?): Boolean {
1424
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
1525
}
26+
27+
override fun getSupportedAnnotationTypes() = supportedAnnotationTypes
1628
}
1729

1830
private const val OPTION_KEY_KAPT_KOTLIN_GENERATED = "kapt.kotlin.generated"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.github.stoyicker.auto.factory.kotlin.processor
2+
3+
import com.nhaarman.mockitokotlin2.mock
4+
import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions
5+
import org.junit.jupiter.api.AfterEach
6+
import org.junit.jupiter.api.Assertions.assertSame
7+
import org.junit.jupiter.api.Test
8+
9+
internal class AutoFactoryKotlinProcessorTest {
10+
private val supportedAnnotationTypes = mock<Set<String>>()
11+
private val subject = AutoFactoryKotlinProcessor(supportedAnnotationTypes)
12+
13+
@AfterEach
14+
fun afterEach() {
15+
verifyNoMoreInteractions(supportedAnnotationTypes)
16+
}
17+
18+
@Test
19+
fun getSupportedAnnotationTypes() {
20+
assertSame(supportedAnnotationTypes, subject.supportedAnnotationTypes)
21+
}
22+
}

sample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies {
1313
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
1414
compileOnly project(":annotations")
1515
kapt project(":processor")
16-
testImplementation "org.mockito:mockito-core:${rootProject."versions.dependencies.mockito"}"
16+
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:${rootProject."versions.dependencies.mockito-kotlin"}"
1717
testImplementation "org.junit.jupiter:junit-jupiter-api:${rootProject."versions.dependencies.junit"}"
1818
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${rootProject."versions.dependencies.junit"}"
1919
}

0 commit comments

Comments
 (0)