1 /* 2 * Copyright (C) 2021 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 static com.google.common.truth.Truth.assertThat; 20 21 import library1.Dep; 22 import library1.MyComponentDependency; 23 import library1.MyComponentModule; 24 import org.junit.Before; 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 import org.junit.runners.JUnit4; 28 29 @RunWith(JUnit4.class) 30 public final class MyComponentTest { 31 private MyComponent component; 32 33 @Before setup()34 public void setup() { 35 component = DaggerMyComponent.factory() 36 .create(new MyComponentModule(new Dep()), new MyComponentDependency()); 37 } 38 39 @Test testFooIsScoped()40 public void testFooIsScoped() { 41 assertThat(component.foo()).isEqualTo(component.foo()); 42 } 43 44 @Test testAssistedFoo()45 public void testAssistedFoo() { 46 assertThat(component.assistedFooFactory().create(5)).isNotNull(); 47 } 48 49 @Test testScopedQualifiedBindsTypeIsScoped()50 public void testScopedQualifiedBindsTypeIsScoped() { 51 assertThat(component.scopedQualifiedBindsType()) 52 .isEqualTo(component.scopedQualifiedBindsType()); 53 } 54 55 @Test testScopedUnqualifiedBindsTypeIsScoped()56 public void testScopedUnqualifiedBindsTypeIsScoped() { 57 assertThat(component.scopedUnqualifiedBindsType()) 58 .isEqualTo(component.scopedUnqualifiedBindsType()); 59 } 60 61 @Test testUnscopedQualifiedBindsTypeIsNotScoped()62 public void testUnscopedQualifiedBindsTypeIsNotScoped() { 63 assertThat(component.unscopedQualifiedBindsType()) 64 .isNotEqualTo(component.unscopedQualifiedBindsType()); 65 } 66 67 @Test testUnscopedUnqualifiedBindsTypeIsNotScoped()68 public void testUnscopedUnqualifiedBindsTypeIsNotScoped() { 69 assertThat(component.unscopedUnqualifiedBindsType()) 70 .isNotEqualTo(component.unscopedUnqualifiedBindsType()); 71 } 72 73 @Test testScopedQualifiedProvidesTypeIsScoped()74 public void testScopedQualifiedProvidesTypeIsScoped() { 75 assertThat(component.scopedQualifiedProvidesType()) 76 .isEqualTo(component.scopedQualifiedProvidesType()); 77 } 78 79 @Test testScopedUnqualifiedProvidesTypeIsScoped()80 public void testScopedUnqualifiedProvidesTypeIsScoped() { 81 assertThat(component.scopedUnqualifiedProvidesType()) 82 .isEqualTo(component.scopedUnqualifiedProvidesType()); 83 } 84 85 @Test testUnscopedQualifiedProvidesTypeIsNotScoped()86 public void testUnscopedQualifiedProvidesTypeIsNotScoped() { 87 assertThat(component.unscopedQualifiedProvidesType()) 88 .isNotEqualTo(component.unscopedQualifiedProvidesType()); 89 } 90 91 @Test testUnscopedUnqualifiedProvidesTypeIsNotScoped()92 public void testUnscopedUnqualifiedProvidesTypeIsNotScoped() { 93 assertThat(component.unscopedUnqualifiedProvidesType()) 94 .isNotEqualTo(component.unscopedUnqualifiedProvidesType()); 95 } 96 97 @Test testMyComponentDependencyBinding()98 public void testMyComponentDependencyBinding() { 99 assertThat(component.qualifiedMyComponentDependencyBinding()) 100 .isNotEqualTo(component.unqualifiedMyComponentDependencyBinding()); 101 } 102 } 103