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 MissingAndroidProcessorTest { 31 @Test missingProcessor()32 public void missingProcessor() { 33 JavaFileObject module = 34 JavaFileObjects.forSourceLines( 35 "test.TestModule", 36 "package test;", 37 "", 38 "import dagger.android.ContributesAndroidInjector;", 39 "import dagger.Module;", 40 "", 41 "@Module", 42 "interface TestModule {", 43 " @ContributesAndroidInjector", 44 " Object o();", 45 "}"); 46 JavaFileObject contributesAndroidInjectorStub = 47 JavaFileObjects.forSourceLines( 48 "dagger.android.ContributesAndroidInjector", 49 "package dagger.android;", 50 "", 51 "public @interface ContributesAndroidInjector {}"); 52 Compilation compilation = daggerCompiler().compile(module, contributesAndroidInjectorStub); 53 assertThat(compilation).failed(); 54 assertThat(compilation) 55 .hadErrorContaining("dagger.android.processor.AndroidProcessor") 56 .inFile(module) 57 .onLine(9); 58 } 59 } 60