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