Skip to content

Commit 623e12e

Browse files
benzonicoWohops
authored andcommitted
SONARJAVA-1181 Migrate to javaCheckverifier
1 parent 3ae9f59 commit 623e12e

2 files changed

Lines changed: 33 additions & 68 deletions

File tree

java-checks/src/test/files/checks/UndocumentedApi.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
* some documentation
33
*/
44
public class UndocumentedApi { // Compliant - documented
5-
public String p; // Non-Compliant
5+
public String p; // Noncompliant
66
private String key; // Compliant - private
77

88
public UndocumentedApi() { // Compliant - empty constructor
99
}
1010

11-
public UndocumentedApi(String key) { // Non-Compliant
11+
public UndocumentedApi(String key) { // Noncompliant
1212
this.key = key;
1313
}
1414

15-
public void run() { // Non-Compliant
15+
public void run() { // Noncompliant
1616
}
1717

18-
public interface InnerUndocumentedInterface { // Non-Compliant
18+
public interface InnerUndocumentedInterface { // Noncompliant
1919
}
2020

2121
/**
@@ -43,20 +43,20 @@ public String toString() { // Compliant - method with override annotation
4343

4444
}
4545

46-
public enum FooEnum { // Non-Compliant
46+
public enum FooEnum { // Noncompliant {{Document this public enum.}}
4747
}
4848

49-
public interface Ainterface { // Non-Compliant
49+
public interface Ainterface { // Noncompliant {{Document this public interface.}}
5050
}
5151

52-
public @interface FooAnnotation { // Non-Compliant
52+
public @interface FooAnnotation { // Noncompliant {{Document this public annotation.}}
5353
}
5454

55-
public class AClass { // Non-Compliant
55+
public class AClass { // Noncompliant {{Document this public class.}}
5656

57-
public int a; // Non-Compliant
57+
public int a; // Noncompliant {{Document this public field.}}
5858

59-
public A() { // Non-Compliant
59+
public A() { // Noncompliant {{Document this public constructor.}}
6060
System.out.println();
6161
}
6262

@@ -65,7 +65,7 @@ public A() { // Non-Compliant
6565
/**
6666
* This is a Javadoc comment
6767
*/
68-
public class MyClass<T> implements Runnable { // Non-Compliant - missing '@param <T>'
68+
public class MyClass<T> implements Runnable { // Noncompliant {{Document the parameter(s): <T>}}
6969

7070
private int status; // Compliant - not public
7171

@@ -74,7 +74,7 @@ public class MyClass<T> implements Runnable { // Non-Compliant - missing '@pa
7474
*/
7575
public String message; // Compliant - well documented
7676

77-
public MyClass() { // Non-Compliant - missing documentation
77+
public MyClass() { // Noncompliant
7878
this.status = 0;
7979
}
8080

@@ -98,13 +98,13 @@ public void doSomething(int value) { // Compliant
9898
/**
9999
* @return foo
100100
*/
101-
public int doSomething(int value) { // Non-Compliant - missing '@param value'
101+
public int doSomething(int value) { // Noncompliant {{Document the parameter(s): value}}
102102
return value;
103103
}
104104

105105
/** plop
106106
* */
107-
public int doSomething() { // Non-Compliant - missing '@return'
107+
public int doSomething() { // Noncompliant {{Document this method return value.}}
108108
return value;
109109
}
110110
}
@@ -118,7 +118,7 @@ interface FooInterface {
118118

119119
/**
120120
* bar. */
121-
int foo(); // Non-Compliant
121+
int foo(); // Noncompliant
122122

123123
/**
124124
* @return
@@ -127,7 +127,7 @@ interface FooInterface {
127127

128128
/** plop.
129129
*/
130-
void foo(int a); // Non-Compliant
130+
void foo(int a); // Noncompliant {{Document the parameter(s): a}}
131131
}
132132

133133
/**
@@ -136,7 +136,7 @@ interface FooInterface {
136136
class FooClass {
137137
/** constructor.
138138
*/
139-
public FooClass(int a) { // Non-Compliant
139+
public FooClass(int a) { // Noncompliant {{Document the parameter(s): a}}
140140
System.out.println(a);
141141
}
142142

@@ -159,12 +159,12 @@ class FooPackage { // Compliant - non public
159159
public class Foo { // Compliant
160160
/** foo.
161161
*/
162-
public int foo(int a, int b, int c) { // Non-Compliant - single issue for parameters, + one for return value
162+
public int foo(int a, int b, int c) { // Noncompliant 2
163163
return 0;
164164
}
165165

166166

167-
public int foo(int a, int b, int c) { // Non-Compliant - single issue for complete method
167+
public int foo(int a, int b, int c) { // Noncompliant {{Document this public method.}}
168168
return 0;
169169
}
170170

@@ -174,13 +174,13 @@ public int foo(int a, int b, int c) { // Non-Compliant - single issue for comple
174174
public <T> void foo() { // Compliant - does not return anything
175175
}
176176

177-
public <T> void foo() { // Noncompliant - must document <T>
177+
public <T> void foo() { // Noncompliant {{Document this public method.}}
178178
}
179179

180180
/**
181181
* @param <T> foo
182182
*/
183-
public <T> int foo() { // Noncompliant - must document return value
183+
public <T> int foo() { // Noncompliant {{Document this method return value.}}
184184
}
185185

186186
/**
@@ -195,7 +195,7 @@ public void getThisThingDone() { //false negative this is interpreted as a gette
195195
}
196196
/**
197197
* */
198-
public interface bar { // Noncompliant empty documentation
198+
public interface bar { // Noncompliant {{Document this public interface.}}
199199
/**
200200
* @param <A> the annotation type
201201
* @param annotationType the <tt>Class</tt> object corresponding to
@@ -205,7 +205,7 @@ public interface bar { // Noncompliant empty documentation
205205
* @see #getAnnotationMirrors()
206206
*/
207207
<A extends Annotation> A getAnnotation(Class<A> annotationType);
208-
static class A{}
208+
static class A{} // Noncompliant {{Document this public class.}}
209209
public int i = 0;
210210

211211
/**
@@ -220,7 +220,7 @@ default void method(){
220220
/**
221221
*
222222
*/
223-
static final class DEFAULT {}
223+
static final class DEFAULT {} // Noncompliant {{Document this public class.}}
224224
public int i = 0;
225225
}
226226
/**
@@ -250,7 +250,7 @@ public class MyRunner extends Foo {
250250
/**
251251
* {@inheritDoc}
252252
*/
253-
public int foo(int a, int b, int c) { // Non-Compliant - single issue for parameters, + one for return value
253+
public int foo(int a, int b, int c) { // Compliant
254254
return 0;
255255
}
256256

@@ -259,7 +259,7 @@ private interface Bar {
259259
}
260260

261261
public void foo
262-
(
262+
( // Noncompliant
263263
)
264264
{
265265
}
@@ -268,21 +268,21 @@ private interface Bar {
268268
*/
269269
public interface Foo {
270270

271-
public foo();
271+
public foo(); // Noncompliant
272272

273273
}
274274

275275
@Target({METHOD})
276276
@Retention(RUNTIME)
277-
public @interface Transient {
278-
boolean value() default true;
277+
public @interface Transient { // Noncompliant
278+
boolean value() default true; // Noncompliant
279279
}
280280
}
281281
class AnonymousInnerClass {
282282
Comparator<String> doJob(){
283283
return new Comparator<String>() { // anon-inner-class
284284
class Hello { // inner-class
285-
public void doJob() { // false-positive
285+
public void doJob() {
286286
}
287287
}
288288

java-checks/src/test/java/org/sonar/java/checks/UndocumentedApiCheckTest.java

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*/
2020
package org.sonar.java.checks;
2121

22-
import org.junit.Rule;
2322
import org.junit.Test;
2423
import org.sonar.java.ast.JavaAstScanner;
24+
import org.sonar.java.checks.verifier.JavaCheckVerifier;
2525
import org.sonar.java.model.VisitorsBridge;
2626
import org.sonar.squidbridge.api.SourceFile;
2727
import org.sonar.squidbridge.checks.CheckMessagesVerifierRule;
@@ -32,54 +32,19 @@
3232

3333
public class UndocumentedApiCheckTest {
3434

35-
@Rule
36-
public CheckMessagesVerifierRule checkMessagesVerifier = new CheckMessagesVerifierRule();
37-
3835
@Test
3936
public void test() {
4037
UndocumentedApiCheck check = new UndocumentedApiCheck();
4138
assertThat(check.forClasses).isEqualTo("**");
42-
43-
SourceFile file = JavaAstScanner.scanSingleFile(new File("src/test/files/checks/UndocumentedApi.java"), new VisitorsBridge(check));
44-
checkMessagesVerifier.verify(file.getCheckMessages())
45-
.next().atLine(5)
46-
.next().atLine(11)
47-
.next().atLine(15)
48-
.next().atLine(18)
49-
.next().atLine(46).withMessage("Document this public enum.")
50-
.next().atLine(49).withMessage("Document this public interface.")
51-
.next().atLine(52).withMessage("Document this public annotation.")
52-
.next().atLine(55).withMessage("Document this public class.")
53-
.next().atLine(57).withMessage("Document this public field.")
54-
.next().atLine(59).withMessage("Document this public constructor.")
55-
.next().atLine(68).withMessage("Document the parameter(s): <T>")
56-
.next().atLine(77)
57-
.next().atLine(101).withMessage("Document the parameter(s): value")
58-
.next().atLine(107).withMessage("Document this method return value.")
59-
.next().atLine(121).withMessage("Document this method return value.")
60-
.next().atLine(130).withMessage("Document the parameter(s): a")
61-
.next().atLine(139).withMessage("Document the parameter(s): a")
62-
.next().atLine(162).withMessage("Document the parameter(s): a, b, c")
63-
.next().atLine(162).withMessage("Document this method return value.")
64-
.next().atLine(167).withMessage("Document this public method.")
65-
.next().atLine(177).withMessage("Document this public method.")
66-
.next().atLine(183).withMessage("Document this method return value.")
67-
.next().atLine(198).withMessage("Document this public interface.")
68-
.next().atLine(208).withMessage("Document this public class.")
69-
.next().atLine(223).withMessage("Document this public class.")
70-
.next().atLine(262)
71-
.next().atLine(271)
72-
.next().atLine(277)
73-
.next().atLine(278);
39+
JavaCheckVerifier.verify("src/test/files/checks/UndocumentedApi.java", check);
7440
}
7541

7642
@Test
7743
public void custom() {
7844
UndocumentedApiCheck check = new UndocumentedApiCheck();
7945
check.forClasses = "";
80-
8146
SourceFile file = JavaAstScanner.scanSingleFile(new File("src/test/files/checks/UndocumentedApi.java"), new VisitorsBridge(check));
82-
checkMessagesVerifier.verify(file.getCheckMessages());
47+
new CheckMessagesVerifierRule().verify(file.getCheckMessages());
8348
}
8449

8550
}

0 commit comments

Comments
 (0)