-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
MissingDeprecatedCheckTest.java
171 lines (140 loc) · 7.26 KB
/
MissingDeprecatedCheckTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2019 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks.annotation;
import static com.puppycrawl.tools.checkstyle.checks.annotation.MissingDeprecatedCheck.MSG_KEY_ANNOTATION_MISSING_DEPRECATED;
import static com.puppycrawl.tools.checkstyle.checks.annotation.MissingDeprecatedCheck.MSG_KEY_JAVADOC_DUPLICATE_TAG;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.jupiter.api.Test;
import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
public class MissingDeprecatedCheckTest extends AbstractModuleTestSupport {
@Override
protected String getPackageLocation() {
return "com/puppycrawl/tools/checkstyle/checks/annotation/missingdeprecated";
}
@Test
public void testGetDefaultJavadocTokens() {
final MissingDeprecatedCheck missingDeprecatedCheck =
new MissingDeprecatedCheck();
final int[] expected = {
JavadocTokenTypes.JAVADOC,
};
assertArrayEquals(expected, missingDeprecatedCheck.getDefaultJavadocTokens(),
"Default javadoc tokens are invalid");
}
@Test
public void testGetRequiredJavadocTokens() {
final MissingDeprecatedCheck checkObj = new MissingDeprecatedCheck();
final int[] expected = {
JavadocTokenTypes.JAVADOC,
};
assertArrayEquals(expected, checkObj.getRequiredJavadocTokens(),
"Default required javadoc tokens are invalid");
}
/**
* Tests that members that are only deprecated via javadoc are flagged.
*/
@Test
public void testBadDeprecatedAnnotation() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MissingDeprecatedCheck.class);
final String[] expected = {
"7: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"12: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"19: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"26: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"31: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"38: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"43: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"51: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"56: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
};
verify(checkConfig, getPath("InputMissingDeprecatedBadDeprecated.java"), expected);
}
/**
* Tests that members that are only deprecated via the annotation are flagged.
*/
@Test
public void testBadDeprecatedJavadoc() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MissingDeprecatedCheck.class);
final String[] expected = {
"11: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"29: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"38: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"48: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"55: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
};
verify(checkConfig, getPath("InputMissingDeprecatedBadJavadoc.java"), expected);
}
/**
* Tests various special deprecation conditions such as duplicate or empty tags.
*/
@Test
public void testSpecialCaseDeprecated() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MissingDeprecatedCheck.class);
final String[] expected = {
"5: " + getCheckMessage(MSG_KEY_JAVADOC_DUPLICATE_TAG, "@deprecated"),
"12: " + getCheckMessage(MSG_KEY_JAVADOC_DUPLICATE_TAG, "@deprecated"),
"14: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"19: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"33: " + getCheckMessage(MSG_KEY_JAVADOC_DUPLICATE_TAG, "@deprecated"),
"42: " + getCheckMessage(MSG_KEY_JAVADOC_DUPLICATE_TAG, "@deprecated"),
"51: " + getCheckMessage(MSG_KEY_JAVADOC_DUPLICATE_TAG, "@deprecated"),
"92: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"99: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
"106: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
};
verify(checkConfig, getPath("InputMissingDeprecatedSpecialCase.java"), expected);
}
/**
* Tests that good forms of deprecation are not flagged.
*/
@Test
public void testGoodDeprecated() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MissingDeprecatedCheck.class);
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputMissingDeprecatedGood.java"), expected);
}
@Test
public void testTwoInJavadocWithoutAnnotation() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MissingDeprecatedCheck.class);
final String[] expected = {
"8: " + getCheckMessage(MSG_KEY_JAVADOC_DUPLICATE_TAG, "@deprecated"),
"12: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
};
verify(checkConfig, getPath("InputMissingDeprecatedClass.java"), expected);
}
@Test
public void testEmptyJavadocLine() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MissingDeprecatedCheck.class);
final String[] expected = {
"11: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
};
verify(checkConfig, getPath("InputMissingDeprecatedMethod.java"), expected);
}
@Test
public void testPackageInfo() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MissingDeprecatedCheck.class);
final String[] expected = {
"2: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
};
verify(checkConfig, getPath("package-info.java"), expected);
}
}