1 /* 2 * Copyright (C) 2016 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.guava; 18 19 import static com.google.common.truth.Truth.assertThat; 20 import static dagger.functional.guava.OptionalBindingComponents.Value.QUALIFIED_VALUE; 21 import static dagger.functional.guava.OptionalBindingComponents.Value.VALUE; 22 23 import com.google.common.collect.ImmutableList; 24 import dagger.functional.guava.OptionalBindingComponents.OptionalBindingComponent; 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 import org.junit.runners.Parameterized; 28 import org.junit.runners.Parameterized.Parameters; 29 30 /** Tests for present optional bindings. */ 31 @RunWith(Parameterized.class) 32 public final class OptionalBindingComponentsPresentTest { 33 34 @Parameters(name = "{0}") parameters()35 public static Iterable<Object[]> parameters() { 36 return ImmutableList.copyOf( 37 new Object[][] { 38 {DaggerOptionalBindingComponents_PresentOptionalBindingComponent.create()}, 39 {DaggerOptionalBindingComponents_AbsentOptionalBindingComponent.create().presentChild()}, 40 }); 41 } 42 43 private final OptionalBindingComponent component; 44 OptionalBindingComponentsPresentTest(OptionalBindingComponent component)45 public OptionalBindingComponentsPresentTest(OptionalBindingComponent component) { 46 this.component = component; 47 } 48 49 @Test optionalProvider()50 public void optionalProvider() { 51 assertThat(component.values().optionalProvider().get().get()).isEqualTo(VALUE); 52 } 53 54 @Test optionalLazy()55 public void optionalLazy() { 56 assertThat(component.values().optionalLazy().get().get()).isEqualTo(VALUE); 57 } 58 59 @Test optionalLazyProvider()60 public void optionalLazyProvider() { 61 assertThat(component.values().optionalLazyProvider().get().get().get()).isEqualTo(VALUE); 62 } 63 64 @Test qualifiedOptional()65 public void qualifiedOptional() { 66 assertThat(component.qualifiedValues().optionalInstance()).hasValue(QUALIFIED_VALUE); 67 } 68 69 @Test qualifiedOptionalProvider()70 public void qualifiedOptionalProvider() { 71 assertThat(component.qualifiedValues().optionalProvider().get().get()) 72 .isEqualTo(QUALIFIED_VALUE); 73 } 74 75 @Test qualifiedOptionalLazy()76 public void qualifiedOptionalLazy() { 77 assertThat(component.qualifiedValues().optionalLazy().get().get()).isEqualTo(QUALIFIED_VALUE); 78 } 79 80 @Test qualifiedOptionalLazyProvider()81 public void qualifiedOptionalLazyProvider() { 82 assertThat(component.qualifiedValues().optionalLazyProvider().get().get().get()) 83 .isEqualTo(QUALIFIED_VALUE); 84 } 85 86 @Test optionalNullableProvider()87 public void optionalNullableProvider() { 88 assertThat(component.optionalNullableProvider().get().get()).isNull(); 89 } 90 91 @Test optionalNullableLazy()92 public void optionalNullableLazy() { 93 assertThat(component.optionalNullableLazy().get().get()).isNull(); 94 } 95 96 @Test optionalNullableLazyProvider()97 public void optionalNullableLazyProvider() { 98 assertThat(component.optionalNullableLazyProvider().get().get().get()).isNull(); 99 } 100 } 101