Skip to content

Commit

Permalink
Issue #13100: Create tests from FinalClass xdoc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyanK7 authored and romani committed Jul 29, 2023
1 parent 1372c78 commit 0179a6b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
@@ -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);
}
}
@@ -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

0 comments on commit 0179a6b

Please sign in to comment.