• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 androidx.room.compiler.processing.util.Source;
20 import dagger.hilt.android.testing.compile.HiltCompilerTests;
21 import dagger.testing.compile.CompilerTests;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.junit.runners.JUnit4;
25 
26 /** Tests for errors generated by {@link DisableInstallInCheckProcessor} */
27 @RunWith(JUnit4.class)
28 public class DisableInstallInCheckProcessorErrorsTest {
29 
30   @Test
testIllegalCombinationInstallIn()31   public void testIllegalCombinationInstallIn() {
32     Source module =
33         CompilerTests.javaSource(
34             "foo.bar.NotModule",
35             "package foo.bar;",
36             "",
37             "import dagger.hilt.migration.DisableInstallInCheck;",
38             "",
39             "@DisableInstallInCheck",
40             "final class NotModule {}");
41 
42     Source entryPoint =
43         CompilerTests.javaSource(
44             "foo.bar.FooEntryPoint",
45             "package foo.bar;",
46             "",
47             "import dagger.hilt.components.SingletonComponent;",
48             "import dagger.hilt.migration.DisableInstallInCheck;",
49             "import dagger.hilt.EntryPoint;",
50             "import dagger.hilt.InstallIn;",
51             "",
52             "@DisableInstallInCheck",
53             "@EntryPoint",
54             "@InstallIn(SingletonComponent.class)",
55             "interface FooEntryPoint {}");
56 
57     HiltCompilerTests.hiltCompiler(module, entryPoint)
58         .withAdditionalJavacProcessors(new DisableInstallInCheckProcessor())
59         .withAdditionalKspProcessors(new KspDisableInstallInCheckProcessor.Provider())
60         .compile(
61             subject -> {
62               subject.hasErrorCount(2);
63               subject
64                   .hasErrorContaining(
65                       "@DisableInstallInCheck should only be used on modules. However, it was found"
66                           + " annotating foo.bar.NotModule")
67                   .onSource(module)
68                   .onLine(6);
69               subject
70                   .hasErrorContaining(
71                       "@DisableInstallInCheck should only be used on modules. However, it was found"
72                           + " annotating foo.bar.FooEntryPoint")
73                   .onSource(entryPoint)
74                   .onLine(11);
75             });
76   }
77 }
78