Skip to content

Commit

Permalink
Refactor Dagger's functional/kotlin tests to be in separate test targ…
Browse files Browse the repository at this point in the history
…ets.

This CL moves away from the `glob(*)`/`glob(*Test)` approach and puts each of the functional tests into its own target with its own dependencies list.

RELNOTES=N/A
PiperOrigin-RevId: 458088734
  • Loading branch information
bcorso authored and Dagger Team committed Jun 29, 2022
1 parent ed998f8 commit 8525a2a
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 50 deletions.
114 changes: 94 additions & 20 deletions javatests/dagger/functional/kotlin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,38 @@ load("//:test_defs.bzl", "GenJavaTests")

package(default_visibility = ["//:src"])

GenJavaTests(
name = "PropertyQualifierTest",
srcs = ["PropertyQualifierTest.java"],
functional = True,
test_only_deps = [

"//third_party/java/guava/base",
"//third_party/java/guava/collect",
"//third_party/java/junit",
"//third_party/java/truth",
],
deps = [
":FooWithInjectedQualifier",
":PropertyQualifierClasses",
],
)

kt_jvm_library(
name = "kotlin",
srcs = glob(
[
"*.java",
"*.kt",
],
exclude = [
"*Test.java",
"JavaTestQualifier.java",
"FooWithInjectedQualifier.kt",
],
),
name = "PropertyQualifierClasses",
srcs = ["PropertyQualifierClasses.kt"],
# TODO(danysantiago): Remove 'plugins' once kt_jvm_library supports 'exported_plugins'.
plugins = ["//javatests/dagger/functional/kotlin/processor:plugin"],
deps = [
":foo_with_injected_qualifier",
":FooWithInjectedQualifier",
":java_qualifier",
"//:dagger_with_compiler",
"//javatests/dagger/functional/kotlin/processor:annotation",
"//third_party/java/auto:factory",
],
)

kt_jvm_library(
name = "foo_with_injected_qualifier",
name = "FooWithInjectedQualifier",
srcs = ["FooWithInjectedQualifier.kt"],
deps = [
":java_qualifier",
Expand All @@ -56,25 +62,93 @@ kt_jvm_library(

java_library(
name = "java_qualifier",
srcs = ["JavaTestQualifier.java"],
srcs = [
"JavaTestQualifier.java",
"JavaTestQualifierWithTarget.java",
],
deps = [
"//:dagger_with_compiler",
],
)

GenJavaTests(
name = "kotlin_tests",
srcs = glob(["*Test.java"]),
name = "ObjectModuleTest",
srcs = ["ObjectModuleTest.java"],
functional = True,
test_only_deps = [

"//third_party/java/guava/base",
"//third_party/java/guava/collect",
"//third_party/java/junit",
"//third_party/java/truth",
],
deps = [
":foo_with_injected_qualifier",
":kotlin",
":ObjectModuleClasses",
],
)

kt_jvm_library(
name = "ObjectModuleClasses",
srcs = [
"ObjectModuleClasses.kt",
"PublicModuleWithNonPublicInclude.java",
],
# TODO(danysantiago): Remove 'plugins' once kt_jvm_library supports 'exported_plugins'.
plugins = ["//javatests/dagger/functional/kotlin/processor:plugin"],
deps = [
"//:dagger_with_compiler",
],
)

GenJavaTests(
name = "DependsOnGeneratedCodeTest",
srcs = ["DependsOnGeneratedCodeTest.java"],
functional = True,
test_only_deps = [

"//third_party/java/guava/base",
"//third_party/java/guava/collect",
"//third_party/java/junit",
"//third_party/java/truth",
],
deps = [
":DependsOnGeneratedCodeClasses",
],
)

kt_jvm_library(
name = "DependsOnGeneratedCodeClasses",
srcs = ["DependsOnGeneratedCodeClasses.kt"],
# TODO(danysantiago): Remove 'plugins' once kt_jvm_library supports 'exported_plugins'.
plugins = ["//javatests/dagger/functional/kotlin/processor:plugin"],
deps = [
"//third_party/java/auto:factory",
"//:dagger_with_compiler",
],
)

GenJavaTests(
name = "CompanionModuleTest",
srcs = ["CompanionModuleTest.java"],
functional = True,
test_only_deps = [

"//third_party/java/guava/base",
"//third_party/java/guava/collect",
"//third_party/java/junit",
"//third_party/java/truth",
],
deps = [
":CompanionModuleClasses",
],
)

kt_jvm_library(
name = "CompanionModuleClasses",
srcs = ["CompanionModuleClasses.kt"],
# TODO(danysantiago): Remove 'plugins' once kt_jvm_library supports 'exported_plugins'.
plugins = ["//javatests/dagger/functional/kotlin/processor:plugin"],
deps = [
"//:dagger_with_compiler",
],
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
/*
* Copyright (C) 2022 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dagger.functional.kotlin

import dagger.Binds
import dagger.Component
import dagger.Module
import dagger.Provides
import javax.inject.Inject
import javax.inject.Named

@Component(
Expand Down Expand Up @@ -95,3 +112,10 @@ class TestKotlinModuleWithPrivateCompanion {
fun randomFunction() = ""
}
}

data class TestDataA(val data: String)
data class TestDataB(val data: String)

interface TestInterface
class TestInjectable @Inject constructor() : TestInterface

Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ private object NonPublicObjectModule {
@Provides
fun provideInt() = 42
}

data class TestDataA(val data: String)
data class TestDataB(val data: String)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import dagger.Module
import dagger.Provides
import dagger.functional.kotlin.processor.TriggerGeneratedTypeProcessor
import javax.inject.Inject
import javax.inject.Qualifier

@Component(modules = [TestKotlinModuleWithQualifier::class])
interface TestKotlinComponentWithQualifier {
Expand Down Expand Up @@ -85,3 +86,10 @@ class TestMemberInjectedClassWithQualifier {

val generatedTypeDelegatedProperty by lazy { dagger.functional.kotlin.GeneratedType() }
}

data class TestDataA(val data: String)
data class TestDataB(val data: String)

@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class KotlinTestQualifier
30 changes: 0 additions & 30 deletions javatests/dagger/functional/kotlin/TestKotlinClasses.kt

This file was deleted.

0 comments on commit 8525a2a

Please sign in to comment.