1 /* 2 * Copyright (C) 2015 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.builder; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import com.google.common.util.concurrent.Futures; 22 import com.google.common.util.concurrent.ListenableFuture; 23 import org.junit.Test; 24 import org.junit.runner.RunWith; 25 import org.junit.runners.JUnit4; 26 27 /** Tests for {@link dagger.producers.ProductionComponent.Builder}. */ 28 @RunWith(JUnit4.class) 29 public final class ProductionComponentBuilderTest { 30 31 @Test successfulBuild()32 public void successfulBuild() throws Exception { 33 TestComponentWithBuilder component = 34 DaggerTestComponentWithBuilder.builder() 35 .depComponent(depComponent(15.3)) 36 .strModule(new StringModule()) 37 .build(); 38 assertThat(component.s().get()).isEqualTo("arg: 42"); 39 assertThat(component.d().get()).isEqualTo(15.3); 40 } 41 42 @Test successfulBuild_withMissingZeroArgModule()43 public void successfulBuild_withMissingZeroArgModule() throws Exception { 44 TestComponentWithBuilder component = 45 DaggerTestComponentWithBuilder.builder() 46 .depComponent(depComponent(15.3)) 47 .build(); 48 assertThat(component.s().get()).isEqualTo("arg: 42"); 49 assertThat(component.d().get()).isEqualTo(15.3); 50 } 51 52 @Test(expected = IllegalStateException.class) missingDepComponent()53 public void missingDepComponent() { 54 DaggerTestComponentWithBuilder.builder() 55 .strModule(new StringModule()) 56 .build(); 57 } 58 depComponent(final double value)59 private static DepComponent depComponent(final double value) { 60 return new DepComponent() { 61 @Override 62 public ListenableFuture<Double> d() { 63 return Futures.immediateFuture(value); 64 } 65 }; 66 } 67 } 68