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 app 18 19 import app.SimpleComponentClasses.SimpleComponent 20 import com.google.common.truth.Truth.assertThat 21 import library.InstanceType 22 import library.MySubcomponent 23 import org.junit.Before 24 import org.junit.Test 25 import org.junit.runner.RunWith 26 import org.junit.runners.JUnit4 27 28 @RunWith(JUnit4::class) 29 class SimpleComponentTest { 30 private lateinit var component: SimpleComponent 31 32 @Before setUpnull33 fun setUp() { 34 component = DaggerSimpleComponentClasses_SimpleComponent.create() 35 } 36 37 @Test fooTestnull38 fun fooTest() { 39 assertThat(component.foo()).isNotNull() 40 assertThat(component.foo()).isNotEqualTo(component.foo()) 41 } 42 43 @Test scopedFooTestnull44 fun scopedFooTest() { 45 assertThat(component.scopedFoo()).isNotNull() 46 assertThat(component.scopedFoo()).isEqualTo(component.scopedFoo()) 47 assertThat(component.scopedFoo()).isEqualTo(component.scopedFooProvider().get()) 48 } 49 50 @Test providedFooTestnull51 fun providedFooTest() { 52 assertThat(component.providedFoo()).isNotNull() 53 assertThat(component.providedFoo()).isNotEqualTo(component.providedFoo()) 54 } 55 56 @Test scopedProvidedFooTestnull57 fun scopedProvidedFooTest() { 58 assertThat(component.scopedProvidedFoo()).isNotNull() 59 assertThat(component.scopedProvidedFoo()).isEqualTo(component.scopedProvidedFoo()) 60 assertThat(component.scopedProvidedFoo()).isEqualTo(component.scopedProvidedFooProvider().get()) 61 } 62 63 @Test subcomponentTestnull64 fun subcomponentTest() { 65 val instanceType = InstanceType() 66 val subcomponent = component.mySubcomponentFactory().create(instanceType) 67 assertThat(subcomponent).isNotNull() 68 assertThat(subcomponent.instance()).isEqualTo(instanceType) 69 } 70 } 71