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