Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #13100: Create tests from FinalClass xdoc examples
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...mples/java/com/puppycrawl/tools/checkstyle/checks/design/FinalClassCheckExamplesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/////////////////////////////////////////////////////////////////////////////////////////////// | ||
// checkstyle: Checks Java source code and other text files for adherence to a set of rules. | ||
// Copyright (C) 2001-2023 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.design; | ||
|
||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport; | ||
|
||
@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345") | ||
public class FinalClassCheckExamplesTest extends AbstractModuleTestSupport { | ||
@Override | ||
protected String getPackageLocation() { | ||
return "xdocs-examples"; | ||
} | ||
|
||
@Override | ||
protected String getResourceLocation() { | ||
return "com/puppycrawl/tools/checkstyle/checks/design/finalclass"; | ||
} | ||
|
||
@Test | ||
public void testExample1() throws Exception { | ||
final String[] expected = { | ||
|
||
}; | ||
|
||
verifyWithInlineConfigParser(getPath("Example1.txt"), expected); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...-examples/resources/com/puppycrawl/tools/checkstyle/checks/design/finalclass/Example1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*xml | ||
<module name="Checker"> | ||
<module name="TreeWalker"> | ||
<module name="FinalClass"/> | ||
</module> | ||
</module> | ||
*/ | ||
|
||
// xdoc section -- start | ||
final class MyClass { // OK | ||
private MyClass() { } | ||
} | ||
|
||
class MyClass { // violation, class should be declared final | ||
private MyClass() { } | ||
} | ||
|
||
class MyClass { // OK, since it has a public constructor | ||
int field1; | ||
String field2; | ||
private MyClass(int value) { | ||
this.field1 = value; | ||
this.field2 = " "; | ||
} | ||
public MyClass(String value) { | ||
this.field2 = value; | ||
this.field1 = 0; | ||
} | ||
} | ||
|
||
class TestAnonymousInnerClasses { // OK, class has an anonymous inner class. | ||
public static final TestAnonymousInnerClasses ONE = new TestAnonymousInnerClasses() { | ||
|
||
}; | ||
|
||
private TestAnonymousInnerClasses() { | ||
} | ||
} | ||
|
||
class Class1 { | ||
|
||
private class Class2 { // violation, class should be declared final | ||
} | ||
|
||
public class Class3 { // ok | ||
} | ||
|
||
} | ||
// xdoc section -- end |