• 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 androidx.room.compiler.processing.util.Source;
20 import com.google.common.collect.ImmutableList;
21 import dagger.testing.compile.CompilerTests;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.junit.runners.Parameterized;
25 import org.junit.runners.Parameterized.Parameters;
26 
27 @RunWith(Parameterized.class)
28 public class MissingAndroidProcessorTest {
29   @Parameters(name = "{0}")
parameters()30   public static ImmutableList<Object[]> parameters() {
31     return CompilerMode.TEST_PARAMETERS;
32   }
33 
34   private final CompilerMode compilerMode;
35 
MissingAndroidProcessorTest(CompilerMode compilerMode)36   public MissingAndroidProcessorTest(CompilerMode compilerMode) {
37     this.compilerMode = compilerMode;
38   }
39 
40   @Test
missingProcessor()41   public void missingProcessor() {
42     Source module =
43         CompilerTests.javaSource(
44             "test.TestModule",
45             "package test;",
46             "",
47             "import dagger.android.ContributesAndroidInjector;",
48             "import dagger.Module;",
49             "",
50             "@Module",
51             "interface TestModule {",
52             "  @ContributesAndroidInjector",
53             "  Object o();",
54             "}");
55     Source contributesAndroidInjectorStub =
56         CompilerTests.javaSource(
57             "dagger.android.ContributesAndroidInjector",
58             "package dagger.android;",
59             "",
60             "public @interface ContributesAndroidInjector {}");
61 
62     CompilerTests.daggerCompiler(module, contributesAndroidInjectorStub)
63         .withProcessingOptions(compilerMode.processorOptions())
64         .compile(
65             subject -> {
66               subject.hasErrorCount(1);
67               subject.hasErrorContaining("dagger.android.processor.AndroidProcessor")
68                   .onSource(module)
69                   .onLine(9);
70             });
71   }
72 }
73