aboutsummaryrefslogtreecommitdiff
path: root/javatests/dagger/functional/kotlinsrc/membersinject
diff options
context:
space:
mode:
Diffstat (limited to 'javatests/dagger/functional/kotlinsrc/membersinject')
-rw-r--r--javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectTest.kt4
-rw-r--r--javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectionWithJavaKeywordNamesTest.kt73
-rw-r--r--javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectionWithTypeAliasSuperclassTest.kt55
3 files changed, 131 insertions, 1 deletions
diff --git a/javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectTest.kt b/javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectTest.kt
index 2fc44258f..e7a751f27 100644
--- a/javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectTest.kt
+++ b/javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectTest.kt
@@ -23,8 +23,8 @@ import dagger.MembersInjector
import dagger.functional.kotlinsrc.membersinject.subpackage.a.AGrandchild
import dagger.functional.kotlinsrc.membersinject.subpackage.a.AParent
import dagger.functional.kotlinsrc.membersinject.subpackage.b.BChild
+import dagger.internal.Provider
import javax.inject.Inject
-import javax.inject.Provider
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@@ -85,7 +85,9 @@ class MembersInjectTest {
}
class A : B() // No injected members
+
open class B : C() // No injected members
+
open class C {
@Inject lateinit var value: String
}
diff --git a/javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectionWithJavaKeywordNamesTest.kt b/javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectionWithJavaKeywordNamesTest.kt
new file mode 100644
index 000000000..adbfd502c
--- /dev/null
+++ b/javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectionWithJavaKeywordNamesTest.kt
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2023 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.kotlinsrc.membersinject
+
+import com.google.common.truth.Truth.assertThat
+import dagger.BindsInstance
+import dagger.Component
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedFactory
+import dagger.assisted.AssistedInject
+import javax.inject.Inject
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+// Regression test for https://github.com/google/dagger/issues/3995.
+@RunWith(JUnit4::class)
+internal class MembersInjectionWithJavaKeywordNamesTest {
+ @Component
+ interface MyComponent {
+ fun myClass(): MyClass
+
+ @Component.Builder
+ interface Builder {
+ @BindsInstance fun addInteger(int: Int): Builder
+ @BindsInstance fun addString(string: String): Builder
+ @BindsInstance fun addLong(long: Long): Builder
+ fun build(): MyComponent
+ }
+ }
+
+ @Suppress("BadInject")
+ class MyClass @Inject constructor(val int: Int) {
+ @Inject @JvmField var string: String = ""
+
+ var long: Long? = null
+
+ @Inject fun injectMethod(long: Long) {
+ this.long = long
+ }
+ }
+
+ @Test
+ fun testParametersWithJavaKeywordNames() {
+ val int = 1
+ val long = 2L
+ val string = "string"
+ val myClass =
+ DaggerMembersInjectionWithJavaKeywordNamesTest_MyComponent.builder()
+ .addInteger(int)
+ .addString(string)
+ .addLong(long)
+ .build()
+ .myClass()
+ assertThat(myClass.int).isEqualTo(int)
+ assertThat(myClass.long).isEqualTo(long)
+ assertThat(myClass.string).isEqualTo(string)
+ }
+}
diff --git a/javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectionWithTypeAliasSuperclassTest.kt b/javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectionWithTypeAliasSuperclassTest.kt
new file mode 100644
index 000000000..e45f63e84
--- /dev/null
+++ b/javatests/dagger/functional/kotlinsrc/membersinject/MembersInjectionWithTypeAliasSuperclassTest.kt
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2024 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.kotlinsrc.membersinject
+
+import com.google.common.truth.Truth.assertThat
+import dagger.Component
+import javax.inject.Inject
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+/** This is a regression test for https://github.com/google/dagger/issues/4199 */
+@RunWith(JUnit4::class)
+class MembersInjectionWithTypeAliasSuperclassTest {
+ @Test
+ fun testMembersInjection() {
+ val myClass = MyClass()
+ DaggerTestComponent.create().inject(myClass)
+ assertThat(myClass.foo).isNotNull()
+ assertThat(myClass.bar).isNotNull()
+ }
+}
+
+@Component
+interface TestComponent {
+ fun inject(myClass: MyClass)
+}
+
+class MyClass: MyBaseClassAlias() {
+ @Inject lateinit var foo: Foo
+}
+
+typealias MyBaseClassAlias = MyBaseClass
+
+abstract class MyBaseClass {
+ @Inject lateinit var bar: Bar
+}
+
+class Foo @Inject constructor()
+class Bar @Inject constructor()