blob: 294f44b496bf0edcb3277910913a781aade62068 [file] [log] [blame]
Julia McClellan16c82d62022-05-24 13:05:59 -04001/*
2 * Copyright 2022 The Android Open Source Project
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
17package androidx.build.lint
18
19import org.junit.Test
20import org.junit.runner.RunWith
21import org.junit.runners.JUnit4
22
23@RunWith(JUnit4::class)
Omar Ismailedf734f2024-05-28 12:34:57 +010024class IgnoreClassLevelDetectorTest :
25 AbstractLintDetectorTest(
26 useDetector = IgnoreClassLevelDetector(),
27 useIssues = listOf(IgnoreClassLevelDetector.ISSUE),
Julia McClellan16c82d62022-05-24 13:05:59 -040028 ) {
29 @Test
30 fun `Detection of class level ignore in Kotlin sources`() {
Omar Ismailedf734f2024-05-28 12:34:57 +010031 val input =
32 arrayOf(
33 kotlin(
34 """
Julia McClellan16c82d62022-05-24 13:05:59 -040035 package java.androidx
36
37 import org.junit.Ignore
38 import org.junit.Test
39
40 @Ignore("Class")
41 class TestClass {
42 @Test
43 fun oneTest() {}
44
45 @Test
46 @Ignore
47 fun twoTest() {}
48 }
Omar Ismailedf734f2024-05-28 12:34:57 +010049 """
50 ),
51 Stubs.IgnoreAnnotation,
52 Stubs.TestAnnotation
53 )
Julia McClellan16c82d62022-05-24 13:05:59 -040054
Omar Ismailedf734f2024-05-28 12:34:57 +010055 val expected =
56 """
Julia McClellan16c82d62022-05-24 13:05:59 -040057src/java/androidx/TestClass.kt:7: Error: @Ignore should not be used at the class level. Move the annotation to each test individually. [IgnoreClassLevelDetector]
58 @Ignore("Class")
59 ~~~~~~~~~~~~~~~~
601 errors, 0 warnings
61 """
Julia McClellan16c82d62022-05-24 13:05:59 -040062
63 check(*input).expect(expected)
64 }
65
66 @Test
67 fun `Detection of class level ignore in Java sources`() {
Omar Ismailedf734f2024-05-28 12:34:57 +010068 val input =
69 arrayOf(
70 java(
71 """
Julia McClellan16c82d62022-05-24 13:05:59 -040072 package java.androidx;
73
74 import org.junit.Ignore;
75 import org.junit.Test;
76
77 @Ignore
78 public class TestClass {
79 @Test
80 public void oneTest() {}
81
82 @Ignore
83 @Test
84 public void twoTest() {}
85 }
86 """
Omar Ismailedf734f2024-05-28 12:34:57 +010087 ),
88 Stubs.IgnoreAnnotation,
89 Stubs.TestAnnotation
90 )
Julia McClellan16c82d62022-05-24 13:05:59 -040091
Omar Ismailedf734f2024-05-28 12:34:57 +010092 val expected =
93 """
Julia McClellan16c82d62022-05-24 13:05:59 -040094src/java/androidx/TestClass.java:7: Error: @Ignore should not be used at the class level. Move the annotation to each test individually. [IgnoreClassLevelDetector]
95 @Ignore
96 ~~~~~~~
971 errors, 0 warnings
98 """
Julia McClellan16c82d62022-05-24 13:05:59 -040099
100 check(*input).expect(expected)
101 }
102
103 @Test
104 fun `Test level ignore allowed in Kotlin sources`() {
Omar Ismailedf734f2024-05-28 12:34:57 +0100105 val input =
106 arrayOf(
107 kotlin(
108 """
Julia McClellan16c82d62022-05-24 13:05:59 -0400109 package java.androidx
110
111 import org.junit.Ignore
112 import org.junit.Test
113
114 class IgnoreTestLevelKotlin {
115 @Test
116 @Ignore("Test")
117 fun oneTest() {}
118
119 @Test
120 fun twoTest() {}
121 }
122 """
Omar Ismailedf734f2024-05-28 12:34:57 +0100123 ),
124 Stubs.IgnoreAnnotation,
125 Stubs.TestAnnotation
126 )
Julia McClellan16c82d62022-05-24 13:05:59 -0400127
128 check(*input).expectClean()
129 }
130
131 @Test
132 fun `Test level ignore allowed in Java sources`() {
Omar Ismailedf734f2024-05-28 12:34:57 +0100133 val input =
134 arrayOf(
135 java(
136 """
Julia McClellan16c82d62022-05-24 13:05:59 -0400137 package java.androidx;
138
139 import org.junit.Ignore;
140 import org.junit.Test;
141
142 public class Test {
143 @Test
144 @Ignore
145 public void oneTest() {}
146
147 @Test
148 public void twoTest() {}
149 }
Omar Ismailedf734f2024-05-28 12:34:57 +0100150 """
151 ),
152 Stubs.IgnoreAnnotation,
153 Stubs.TestAnnotation
154 )
Julia McClellan16c82d62022-05-24 13:05:59 -0400155
156 check(*input).expectClean()
157 }
158}