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.producers.optional; 18 19 import static com.google.common.truth.Truth.assertThat; 20 import static dagger.functional.producers.optional.OptionalBindingComponents.Value.QUALIFIED_VALUE; 21 import static dagger.functional.producers.optional.OptionalBindingComponents.Value.VALUE; 22 23 import com.google.common.collect.ImmutableList; 24 import dagger.functional.producers.optional.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 {DaggerOptionalBindingComponents_PresentOptionalProvisionBindingComponent.create()} 41 }); 42 } 43 44 private final OptionalBindingComponent component; 45 OptionalBindingComponentsPresentTest(OptionalBindingComponent component)46 public OptionalBindingComponentsPresentTest(OptionalBindingComponent component) { 47 this.component = component; 48 } 49 50 @Test optional()51 public void optional() throws Exception { 52 assertThat(component.optionalInstance().get()).hasValue(VALUE); 53 } 54 55 @Test optionalProducer()56 public void optionalProducer() throws Exception { 57 assertThat(component.optionalProducer().get().get().get().get()).isEqualTo(VALUE); 58 } 59 60 @Test optionalProduced()61 public void optionalProduced() throws Exception { 62 assertThat(component.optionalProduced().get().get().get()).isEqualTo(VALUE); 63 } 64 65 @Test qualifiedOptional()66 public void qualifiedOptional() throws Exception { 67 assertThat(component.qualifiedOptionalInstance().get()).hasValue(QUALIFIED_VALUE); 68 } 69 70 @Test qualifiedOptionalProducer()71 public void qualifiedOptionalProducer() throws Exception { 72 assertThat(component.qualifiedOptionalProducer().get().get().get().get()) 73 .isEqualTo(QUALIFIED_VALUE); 74 } 75 76 @Test qualifiedOptionalProduced()77 public void qualifiedOptionalProduced() throws Exception { 78 assertThat(component.qualifiedOptionalProduced().get().get().get()).isEqualTo(QUALIFIED_VALUE); 79 } 80 81 @Test optionalNullableProducer()82 public void optionalNullableProducer() throws Exception { 83 assertThat(component.optionalNullableProducer().get().get().get().get()).isNull(); 84 } 85 86 @Test optionalNullableProduced()87 public void optionalNullableProduced() throws Exception { 88 assertThat(component.optionalNullableProduced().get().get().get()).isNull(); 89 } 90 } 91