1 /* 2 * Copyright (C) 2023 The Dagger Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package dagger.functional.kotlinsrc.staticprovides 18 19 import com.google.common.truth.Truth.assertThat 20 import com.google.common.truth.Truth.assertWithMessage 21 import java.lang.Deprecated 22 import org.junit.Test 23 import org.junit.runner.RunWith 24 import org.junit.runners.Parameterized 25 import org.junit.runners.Parameterized.Parameter 26 import org.junit.runners.Parameterized.Parameters 27 28 @RunWith(Parameterized::class) 29 class StaticProvidesTest { 30 @Parameter lateinit var component: StaticTestComponent 31 32 @Test setMultibindingnull33 fun setMultibinding() { 34 assertThat(component.multiboundStrings()) 35 .containsExactly( 36 "${AllStaticModule::class.java}.contributeString", 37 "${SomeStaticModule::class.java}.contributeStringFromAStaticMethod", 38 "${SomeStaticModule::class.java}.contributeStringFromAnInstanceMethod", 39 ) 40 } 41 42 @Test allStaticProvidesModules_noFieldInComponentBuildernull43 fun allStaticProvidesModules_noFieldInComponentBuilder() { 44 for (field in DaggerStaticTestComponent.Builder::class.java.getDeclaredFields()) { 45 assertWithMessage(field.name).that(field.type).isNotEqualTo(AllStaticModule::class.java) 46 } 47 } 48 49 @Test allStaticProvidesModules_deprecatedMethodInComponentBuildernull50 fun allStaticProvidesModules_deprecatedMethodInComponentBuilder() { 51 for (method in DaggerStaticTestComponent.Builder::class.java.getDeclaredMethods()) { 52 if (method.parameterTypes.contains(AllStaticModule::class.java)) { 53 assertWithMessage(method.name) 54 .that(method.isAnnotationPresent(Deprecated::class.java)) 55 .isTrue() 56 } 57 } 58 } 59 60 companion object { 61 @JvmStatic 62 @Parameters componentsnull63 fun components(): Collection<Array<Any>> { 64 return listOf( 65 arrayOf(DaggerStaticTestComponent.create()), 66 arrayOf(DaggerStaticTestComponentWithBuilder.builder().build()), 67 arrayOf( 68 DaggerStaticTestComponentWithBuilder.builder() 69 // Note: Kotlin doesn't allow instantiating AllStaticModule object. 70 .someStaticModule(SomeStaticModule()) 71 .build() 72 ) 73 ) 74 } 75 } 76 } 77