1 /* 2 * Copyright (C) 2014 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.internal.codegen; 18 19 import static com.google.common.truth.Truth.assertThat; 20 import static dagger.internal.codegen.javapoet.TypeNames.MEMBERS_INJECTOR; 21 import static dagger.internal.codegen.javapoet.TypeNames.PROVIDER; 22 import static dagger.internal.codegen.javapoet.TypeNames.membersInjectorOf; 23 import static dagger.internal.codegen.javapoet.TypeNames.providerOf; 24 25 import com.google.testing.compile.CompilationRule; 26 import com.squareup.javapoet.ClassName; 27 import com.squareup.javapoet.ParameterizedTypeName; 28 import dagger.internal.codegen.binding.FrameworkField; 29 import javax.inject.Inject; 30 import org.junit.Before; 31 import org.junit.Rule; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.junit.runners.JUnit4; 35 36 /** 37 * Test case for {@link FrameworkField}. 38 */ 39 @RunWith(JUnit4.class) 40 public class FrameworkFieldTest { 41 @Rule public CompilationRule compilationRule = new CompilationRule(); 42 43 private ClassName xTypeName; 44 setUp()45 @Before public void setUp() { 46 xTypeName = 47 ClassName.get(compilationRule.getElements().getTypeElement(X.class.getCanonicalName())); 48 } 49 frameworkType()50 @Test public void frameworkType() { 51 assertThat(FrameworkField.create(ParameterizedTypeName.get(PROVIDER, xTypeName), "test").type()) 52 .isEqualTo(providerOf(xTypeName)); 53 assertThat( 54 FrameworkField.create(ParameterizedTypeName.get(MEMBERS_INJECTOR, xTypeName), "test") 55 .type()) 56 .isEqualTo(membersInjectorOf(xTypeName)); 57 } 58 nameSuffix()59 @Test public void nameSuffix() { 60 assertThat(FrameworkField.create(ParameterizedTypeName.get(PROVIDER, xTypeName), "foo").name()) 61 .isEqualTo("fooProvider"); 62 assertThat( 63 FrameworkField.create(ParameterizedTypeName.get(PROVIDER, xTypeName), "fooProvider") 64 .name()) 65 .isEqualTo("fooProvider"); 66 } 67 68 static final class X { X()69 @Inject X() {} 70 } 71 } 72