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 dagger.internal.codegen.binding.FrameworkField; 28 import javax.inject.Inject; 29 import org.junit.Before; 30 import org.junit.Rule; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.junit.runners.JUnit4; 34 35 /** 36 * Test case for {@link FrameworkField}. 37 */ 38 @RunWith(JUnit4.class) 39 public class FrameworkFieldTest { 40 @Rule public CompilationRule compilationRule = new CompilationRule(); 41 42 private ClassName xTypeName; 43 setUp()44 @Before public void setUp() { 45 xTypeName = 46 ClassName.get(compilationRule.getElements().getTypeElement(X.class.getCanonicalName())); 47 } 48 frameworkType()49 @Test public void frameworkType() { 50 assertThat(FrameworkField.create(PROVIDER, xTypeName, "test").type()) 51 .isEqualTo(providerOf(xTypeName)); 52 assertThat(FrameworkField.create(MEMBERS_INJECTOR, xTypeName, "test").type()) 53 .isEqualTo(membersInjectorOf(xTypeName)); 54 } 55 nameSuffix()56 @Test public void nameSuffix() { 57 assertThat(FrameworkField.create(PROVIDER, xTypeName, "foo").name()) 58 .isEqualTo("fooProvider"); 59 assertThat(FrameworkField.create(PROVIDER, xTypeName, "fooProvider").name()) 60 .isEqualTo("fooProvider"); 61 } 62 63 static final class X { X()64 @Inject X() {} 65 } 66 } 67