Skip to content

Commit 6e84f68

Browse files
authored
Add test cases for type annotations on classes (#1368)
2 parents d201491 + 276810c commit 6e84f68

File tree

5 files changed

+143
-0
lines changed

5 files changed

+143
-0
lines changed

plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,14 @@ void testFormatAnnotations() throws Exception {
3030
mavenRunner().withArguments("spotless:apply").runNoError();
3131
assertFile(path).sameAsResource("java/formatannotations/FormatAnnotationsTestOutput.test");
3232
}
33+
34+
@Test
35+
void testFormatAnnotationsAccessModifiers() throws Exception {
36+
writePomWithJavaSteps("<formatAnnotations/>");
37+
38+
String path = "src/main/java/test.java";
39+
setFile(path).toResource("java/formatannotations/FormatAnnotationsAccessModifiersInput.test");
40+
mavenRunner().withArguments("spotless:apply").runNoError();
41+
assertFile(path).sameAsResource("java/formatannotations/FormatAnnotationsAccessModifiersOutput.test");
42+
}
3343
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Annotations in the wrong order. The preferred order is:
2+
// * declaration annotations
3+
// * access modifiers such as `public`
4+
// * type annotations
5+
// * type
6+
7+
class FormatAnnotationsAccessModifiers {
8+
9+
@Nullable public Object myMethod1() {
10+
return null;
11+
}
12+
13+
@Nullable
14+
public Object myMethod2() {
15+
return null;
16+
}
17+
18+
@Nullable
19+
public
20+
Object myMethod3() {
21+
return null;
22+
}
23+
24+
@Nullable
25+
@Deprecated
26+
public Object myMethod4() {
27+
return null;
28+
}
29+
30+
@Deprecated
31+
@Nullable
32+
public Object myMethod4a() {
33+
return null;
34+
}
35+
36+
@Override
37+
@Nullable
38+
@Deprecated
39+
public Object myMethod5() {
40+
return null;
41+
}
42+
43+
@Nullable @Deprecated public Object myMethod6() {
44+
return null;
45+
}
46+
}
47+
48+
@Deprecated
49+
@Interned
50+
@MustCall("close")
51+
@SuppressWarnings
52+
public class MyClass3 {
53+
// No body
54+
}
55+
56+
public
57+
@Deprecated
58+
@SuppressWarnings
59+
@Interned
60+
@MustCall("close")
61+
class MyClass4 {
62+
// No body
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Annotations in the wrong order. The preferred order is:
2+
// * declaration annotations
3+
// * access modifiers such as `public`
4+
// * type annotations
5+
// * type
6+
7+
class FormatAnnotationsAccessModifiers {
8+
9+
@Nullable public Object myMethod1() {
10+
return null;
11+
}
12+
13+
@Nullable public Object myMethod2() {
14+
return null;
15+
}
16+
17+
@Nullable public
18+
Object myMethod3() {
19+
return null;
20+
}
21+
22+
@Nullable @Deprecated
23+
public Object myMethod4() {
24+
return null;
25+
}
26+
27+
@Deprecated
28+
@Nullable public Object myMethod4a() {
29+
return null;
30+
}
31+
32+
@Override
33+
@Nullable @Deprecated
34+
public Object myMethod5() {
35+
return null;
36+
}
37+
38+
@Nullable @Deprecated public Object myMethod6() {
39+
return null;
40+
}
41+
}
42+
43+
@Deprecated
44+
@Interned @MustCall("close") @SuppressWarnings
45+
public class MyClass3 {
46+
// No body
47+
}
48+
49+
public
50+
@Deprecated
51+
@SuppressWarnings
52+
@Interned @MustCall("close") class MyClass4 {
53+
// No body
54+
}

testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test

+9
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,12 @@ class FormatAnnotationsTest {
7575
@Localized
7676
String localized;
7777
}
78+
79+
@Deprecated
80+
@SuppressWarnings
81+
public
82+
@Interned
83+
@MustCall("close")
84+
class MyClass1 {
85+
// No body
86+
}

testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test

+7
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@ class FormatAnnotationsTest {
4949

5050
@Localized String localized;
5151
}
52+
53+
@Deprecated
54+
@SuppressWarnings
55+
public
56+
@Interned @MustCall("close") class MyClass1 {
57+
// No body
58+
}

0 commit comments

Comments
 (0)