Skip to content

Commit 1372c78

Browse files
stoyanK7romani
authored andcommitted
Issue #13100: Create tests from DesignForExtension xdoc examples
1 parent 9fd2a91 commit 1372c78

File tree

5 files changed

+261
-0
lines changed

5 files changed

+261
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
///////////////////////////////////////////////////////////////////////////////////////////////
2+
// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3+
// Copyright (C) 2001-2023 the original author or authors.
4+
//
5+
// This library is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU Lesser General Public
7+
// License as published by the Free Software Foundation; either
8+
// version 2.1 of the License, or (at your option) any later version.
9+
//
10+
// This library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public
16+
// License along with this library; if not, write to the Free Software
17+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
///////////////////////////////////////////////////////////////////////////////////////////////
19+
20+
package com.puppycrawl.tools.checkstyle.checks.design;
21+
22+
import org.junit.jupiter.api.Disabled;
23+
import org.junit.jupiter.api.Test;
24+
25+
import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
26+
27+
@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345")
28+
public class DesignForExtensionCheckExamplesTest extends AbstractModuleTestSupport {
29+
@Override
30+
protected String getPackageLocation() {
31+
return "xdocs-examples";
32+
}
33+
34+
@Override
35+
protected String getResourceLocation() {
36+
return "com/puppycrawl/tools/checkstyle/checks/design/designforextension";
37+
}
38+
39+
@Test
40+
public void testExample1() throws Exception {
41+
final String[] expected = {
42+
43+
};
44+
45+
verifyWithInlineConfigParser(getPath("Example1.txt"), expected);
46+
}
47+
48+
@Test
49+
public void testExample2() throws Exception {
50+
final String[] expected = {
51+
52+
};
53+
54+
verifyWithInlineConfigParser(getPath("Example2.txt"), expected);
55+
}
56+
57+
@Test
58+
public void testExample3() throws Exception {
59+
final String[] expected = {
60+
61+
};
62+
63+
verifyWithInlineConfigParser(getPath("Example3.txt"), expected);
64+
}
65+
66+
@Test
67+
public void testExample4() throws Exception {
68+
final String[] expected = {
69+
70+
};
71+
72+
verifyWithInlineConfigParser(getPath("Example4.txt"), expected);
73+
}
74+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*xml
2+
<module name="Checker">
3+
<module name="TreeWalker">
4+
<module name="DesignForExtension"/>
5+
</module>
6+
</module>
7+
*/
8+
9+
// xdoc section -- start
10+
public abstract class Foo {
11+
private int bar;
12+
13+
public int m1() {return 2;} // Violation. No javadoc.
14+
15+
public int m2() {return 8;} // Violation. No javadoc.
16+
17+
private void m3() {m4();} // OK. Private method.
18+
19+
protected void m4() { } // OK. No implementation.
20+
21+
public abstract void m5(); // OK. Abstract method.
22+
23+
/**
24+
* This implementation ...
25+
@return some int value.
26+
*/
27+
public int m6() {return 1;} // OK. Have javadoc on overridable method.
28+
29+
/**
30+
* Some comments ...
31+
*/
32+
public int m7() {return 1;} // OK. Have javadoc on overridable method.
33+
34+
/**
35+
* This
36+
* implementation ...
37+
*/
38+
public int m8() {return 2;} // OK. Have javadoc on overridable method.
39+
40+
@Override
41+
public String toString() { // Violation. No javadoc for @Override method.
42+
return "";
43+
}
44+
}
45+
// xdoc section -- end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*xml
2+
<module name="Checker">
3+
<module name="TreeWalker">
4+
<module name="DesignForExtension">
5+
<property name="ignoredAnnotations" value="Override"/>
6+
</module>
7+
</module>
8+
</module>
9+
*/
10+
11+
// xdoc section -- start
12+
public abstract class Foo {
13+
private int bar;
14+
15+
public int m1() {return 2;} // Violation. No javadoc.
16+
17+
public int m2() {return 8;} // Violation. No javadoc.
18+
19+
private void m3() {m4();} // OK. Private method.
20+
21+
protected void m4() { } // OK. No implementation.
22+
23+
public abstract void m5(); // OK. Abstract method.
24+
25+
/**
26+
* This implementation ...
27+
@return some int value.
28+
*/
29+
public int m6() {return 1;} // OK. Have javadoc on overridable method.
30+
31+
/**
32+
* Some comments ...
33+
*/
34+
public int m7() {return 1;} // OK. Have javadoc on overridable method.
35+
36+
/**
37+
* This
38+
* implementation ...
39+
*/
40+
public int m8() {return 2;} // OK. Have javadoc on overridable method.
41+
42+
@Override
43+
public String toString() { // OK. Have javadoc on overridable method.
44+
return "";
45+
}
46+
}
47+
// xdoc section -- end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*xml
2+
<module name="Checker">
3+
<module name="TreeWalker">
4+
<module name="DesignForExtension">
5+
<property name="requiredJavadocPhrase" value="This implementation"/>
6+
</module>
7+
</module>
8+
</module>
9+
*/
10+
11+
// xdoc section -- start
12+
public abstract class Foo {
13+
private int bar;
14+
15+
public int m1() {return 2;} // Violation. No javadoc.
16+
17+
public int m2() {return 8;} // Violation. No javadoc.
18+
19+
private void m3() {m4();} // OK. Private method.
20+
21+
protected void m4() { } // OK. No implementation.
22+
23+
public abstract void m5(); // OK. Abstract method.
24+
25+
/**
26+
* This implementation ...
27+
@return some int value.
28+
*/
29+
public int m6() {return 1;} // OK. Have required javadoc.
30+
31+
/**
32+
* Some comments ...
33+
*/
34+
public int m7() {return 1;} // Violation. No required javadoc.
35+
36+
/**
37+
* This
38+
* implementation ...
39+
*/
40+
public int m8() {return 2;} // Violation. No required javadoc.
41+
42+
@Override
43+
public String toString() { // Violation. No required javadoc.
44+
return "";
45+
}
46+
}
47+
// xdoc section -- end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*xml
2+
<module name="Checker">
3+
<module name="TreeWalker">
4+
<module name="DesignForExtension">
5+
<property name="requiredJavadocPhrase"
6+
value="This[\s\S]*implementation"/>
7+
</module>
8+
</module>
9+
</module>
10+
*/
11+
12+
// xdoc section -- start
13+
public abstract class Foo {
14+
private int bar;
15+
16+
public int m1() {return 2;} // Violation. No javadoc.
17+
18+
public int m2() {return 8;} // Violation. No javadoc.
19+
20+
private void m3() {m4();}
21+
22+
protected void m4() { } // OK. No implementation.
23+
24+
public abstract void m5(); // OK. Abstract method.
25+
26+
/**
27+
* This implementation ...
28+
@return some int value.
29+
*/
30+
public int m6() {return 1;} // OK. Have required javadoc.
31+
32+
/**
33+
* Some comments ...
34+
*/
35+
public int m7() {return 1;} // Violation. No required javadoc.
36+
37+
/**
38+
* This
39+
* implementation ...
40+
*/
41+
public int m8() {return 2;} // OK. Have required javadoc.
42+
43+
@Override
44+
public String toString() { // Violation. No required javadoc.
45+
return "";
46+
}
47+
}
48+
// xdoc section -- end

0 commit comments

Comments
 (0)