1 /* 2 * Copyright (C) 2020 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.hilt.processor.internal.disableinstallincheck; 18 19 import static com.google.testing.compile.CompilationSubject.assertThat; 20 21 import com.google.testing.compile.Compilation; 22 import com.google.testing.compile.JavaFileObjects; 23 import dagger.testing.compile.CompilerTests; 24 import javax.tools.JavaFileObject; 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 import org.junit.runners.JUnit4; 28 29 /** Tests for errors generated by {@link DisableInstallInCheckProcessor} */ 30 @RunWith(JUnit4.class) 31 public class DisableInstallInCheckProcessorErrorsTest { 32 33 @Test testIllegalCombinationInstallIn()34 public void testIllegalCombinationInstallIn() { 35 JavaFileObject source = 36 JavaFileObjects.forSourceLines( 37 "foo.bar", 38 "package foo.bar;", 39 "", 40 "import dagger.hilt.migration.DisableInstallInCheck;", 41 "import dagger.hilt.EntryPoint;", 42 "", 43 "@DisableInstallInCheck", 44 "final class NotModule {}", 45 "", 46 "@DisableInstallInCheck", 47 "@EntryPoint", 48 "interface FooEntryPoint {}"); 49 50 Compilation compilation = 51 CompilerTests.compiler() 52 .withProcessors(new DisableInstallInCheckProcessor()) 53 .compile(source); 54 55 assertThat(compilation).failed(); 56 assertThat(compilation) 57 .hadErrorContaining( 58 "@DisableInstallInCheck should only be used on modules. However, it was found" 59 + " annotating foo.bar.NotModule") 60 .inFile(source) 61 .onLine(7); 62 assertThat(compilation) 63 .hadErrorContaining( 64 "@DisableInstallInCheck should only be used on modules. However, it was found" 65 + " annotating foo.bar.FooEntryPoint") 66 .inFile(source) 67 .onLine(11); 68 } 69 } 70