• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.testing.compile.CompilationSubject.assertThat;
20 import static dagger.internal.codegen.Compilers.daggerCompiler;
21 
22 import com.google.testing.compile.Compilation;
23 import com.google.testing.compile.JavaFileObjects;
24 import javax.tools.JavaFileObject;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.JUnit4;
28 
29 @RunWith(JUnit4.class)
30 public class GenericMethodsTest {
31   @Test
parameterizedComponentMethods()32   public void parameterizedComponentMethods() {
33     JavaFileObject component =
34         JavaFileObjects.forSourceLines(
35             "test.TestComponent",
36             "package test;",
37             "",
38             "import dagger.Component;",
39             "import dagger.MembersInjector;",
40             "import java.util.Set;",
41             "",
42             "@Component",
43             "interface TestComponent {",
44             "  <T1> void injectTypeVariable(T1 type);",
45             "  <T2> MembersInjector<T2> membersInjector();",
46             "  <T3> Set<T3> setOfT();",
47             "  <UNUSED> TestComponent unused();",
48             "}");
49     Compilation compilation = daggerCompiler().compile(component);
50     assertThat(compilation).failed();
51     assertThat(compilation)
52         .hadErrorContaining("cannot have type variables")
53         .inFile(component)
54         .onLineContaining("<T1>");
55     assertThat(compilation)
56         .hadErrorContaining("cannot have type variables")
57         .inFile(component)
58         .onLineContaining("<T2>");
59     assertThat(compilation)
60         .hadErrorContaining("cannot have type variables")
61         .inFile(component)
62         .onLineContaining("<T3>");
63     assertThat(compilation)
64         .hadErrorContaining("cannot have type variables")
65         .inFile(component)
66         .onLineContaining("<UNUSED>");
67   }
68 }
69