Skip to content

Commit

Permalink
Issue checkstyle#4158: Split and Organize Checkstyle inputs by Test f…
Browse files Browse the repository at this point in the history
…or MethodName
  • Loading branch information
Kietzmann authored and timurt committed May 6, 2017
1 parent 18a7206 commit b5b9955
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public class MethodNameCheckTest
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "naming" + File.separator + filename);
+ "naming" + File.separator
+ "methodname" + File.separator
+ filename);
}

@Test
Expand All @@ -59,7 +61,7 @@ public void testDefault()
final String[] expected = {
"137:10: " + getCheckMessage(MSG_INVALID_PATTERN, "ALL_UPPERCASE_METHOD", pattern),
};
verify(checkConfig, getPath("InputSimple.java"), expected);
verify(checkConfig, getPath("InputMethodNameSimple.java"), expected);
}

@Test
Expand All @@ -70,22 +72,25 @@ public void testMethodEqClass() throws Exception {
final String pattern = "^[a-z][a-zA-Z0-9]*$";

final String[] expected = {
"12:16: " + getCheckMessage(MSG_KEY, "InputMethNameEqualClsName"),
"12:16: " + getCheckMessage(MSG_INVALID_PATTERN, "InputMethNameEqualClsName", pattern),
"17:17: " + getCheckMessage(MSG_INVALID_PATTERN, "PRIVATEInputMethNameEqualClsName",
"12:16: " + getCheckMessage(MSG_KEY, "InputMethodNameEqualClassName"),
"12:16: " + getCheckMessage(MSG_INVALID_PATTERN,
"InputMethodNameEqualClassName", pattern),
"17:17: " + getCheckMessage(MSG_INVALID_PATTERN, "PRIVATEInputMethodNameEqualClassName",
pattern),
"23:20: " + getCheckMessage(MSG_KEY, "Inner"),
"23:20: " + getCheckMessage(MSG_INVALID_PATTERN, "Inner", pattern),
"28:20: " + getCheckMessage(MSG_INVALID_PATTERN, "InputMethNameEqualClsName", pattern),
"37:24: " + getCheckMessage(MSG_KEY, "InputMethNameEqualClsName"),
"37:24: " + getCheckMessage(MSG_INVALID_PATTERN, "InputMethNameEqualClsName", pattern),
"28:20: " + getCheckMessage(MSG_INVALID_PATTERN,
"InputMethodNameEqualClassName", pattern),
"37:24: " + getCheckMessage(MSG_KEY, "InputMethodNameEqualClassName"),
"37:24: " + getCheckMessage(MSG_INVALID_PATTERN,
"InputMethodNameEqualClassName", pattern),
"47:9: " + getCheckMessage(MSG_KEY, "SweetInterface"),
"47:9: " + getCheckMessage(MSG_INVALID_PATTERN, "SweetInterface", pattern),
"53:17: " + getCheckMessage(MSG_KEY, "Outter"),
"53:17: " + getCheckMessage(MSG_INVALID_PATTERN, "Outter", pattern),
};

verify(checkConfig, getPath("InputMethNameEqualClsName.java"), expected);
verify(checkConfig, getPath("InputMethodNameEqualClassName.java"), expected);
}

@Test
Expand All @@ -99,17 +104,20 @@ public void testMethodEqClassAllow() throws Exception {
final String pattern = "^[a-z][a-zA-Z0-9]*$";

final String[] expected = {
"12:16: " + getCheckMessage(MSG_INVALID_PATTERN, "InputMethNameEqualClsName", pattern),
"17:17: " + getCheckMessage(MSG_INVALID_PATTERN, "PRIVATEInputMethNameEqualClsName",
"12:16: " + getCheckMessage(MSG_INVALID_PATTERN,
"InputMethodNameEqualClassName", pattern),
"17:17: " + getCheckMessage(MSG_INVALID_PATTERN, "PRIVATEInputMethodNameEqualClassName",
pattern),
"23:20: " + getCheckMessage(MSG_INVALID_PATTERN, "Inner", pattern),
"28:20: " + getCheckMessage(MSG_INVALID_PATTERN, "InputMethNameEqualClsName", pattern),
"37:24: " + getCheckMessage(MSG_INVALID_PATTERN, "InputMethNameEqualClsName", pattern),
"28:20: " + getCheckMessage(MSG_INVALID_PATTERN,
"InputMethodNameEqualClassName", pattern),
"37:24: " + getCheckMessage(MSG_INVALID_PATTERN,
"InputMethodNameEqualClassName", pattern),
"47:9: " + getCheckMessage(MSG_INVALID_PATTERN, "SweetInterface", pattern),
"53:17: " + getCheckMessage(MSG_INVALID_PATTERN, "Outter", pattern),
};

verify(checkConfig, getPath("InputMethNameEqualClsName.java"), expected);
verify(checkConfig, getPath("InputMethodNameEqualClassName.java"), expected);
}

@Test
Expand All @@ -126,15 +134,18 @@ public void testAccessTuning() throws Exception {
final String pattern = "^[a-z][a-zA-Z0-9]*$";

final String[] expected = {
"12:16: " + getCheckMessage(MSG_INVALID_PATTERN, "InputMethNameEqualClsName", pattern),
"12:16: " + getCheckMessage(MSG_INVALID_PATTERN,
"InputMethodNameEqualClassName", pattern),
"23:20: " + getCheckMessage(MSG_INVALID_PATTERN, "Inner", pattern),
"28:20: " + getCheckMessage(MSG_INVALID_PATTERN, "InputMethNameEqualClsName", pattern),
"37:24: " + getCheckMessage(MSG_INVALID_PATTERN, "InputMethNameEqualClsName", pattern),
"28:20: " + getCheckMessage(MSG_INVALID_PATTERN,
"InputMethodNameEqualClassName", pattern),
"37:24: " + getCheckMessage(MSG_INVALID_PATTERN,
"InputMethodNameEqualClassName", pattern),
"47:9: " + getCheckMessage(MSG_INVALID_PATTERN, "SweetInterface", pattern),
"53:17: " + getCheckMessage(MSG_INVALID_PATTERN, "Outter", pattern),
};

verify(checkConfig, getPath("InputMethNameEqualClsName.java"), expected);
verify(checkConfig, getPath("InputMethodNameEqualClassName.java"), expected);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.puppycrawl.tools.checkstyle.checks.naming;
package com.puppycrawl.tools.checkstyle.checks.naming.methodname;

/**
* Test input for MethodNameCheck specifically
* whether the method name equals the class name.
*
* @author Travis Schneeberger
*/
public class InputMethNameEqualClsName {
public class InputMethodNameEqualClassName {

//illegal name
public int InputMethNameEqualClsName() {
public int InputMethodNameEqualClassName() {
return 0;
}

//illegal name
private int PRIVATEInputMethNameEqualClsName() {
private int PRIVATEInputMethodNameEqualClassName() {
return 0;
}

Expand All @@ -25,16 +25,16 @@ public int Inner() {
}

//OK name - name of the outter class's ctor
public int InputMethNameEqualClsName() {
public int InputMethodNameEqualClassName() {
return 0;
}
}

public void anotherMethod() {
new InputMethNameEqualClsName() {
new InputMethodNameEqualClassName() {

//illegal name
public int InputMethNameEqualClsName() {
public int InputMethodNameEqualClassName() {
return 1;
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.checks.naming;
package com.puppycrawl.tools.checkstyle.checks.naming.methodname;

public class InputMethodNameExtra
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.checks.naming;
package com.puppycrawl.tools.checkstyle.checks.naming.methodname;

public class InputMethodNameOverridenMethods extends SomeClass
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
////////////////////////////////////////////////////////////////////////////////
// Test case file for checkstyle.
// Created: Feb-2001
// Ignore error
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks.naming.methodname;
import java.io.*;
/**
* Contains simple mistakes:
* - Long lines
* - Tabs
* - Format of variables and parameters
* - Order of modifiers
* @author Oliver Burn
**/
final class InputMethodNameSimple
{
// Long line ----------------------------------------------------------------
// Contains a tab -> <-
// Contains trailing whitespace ->

// Name format tests
//
/** Invalid format **/
public static final int badConstant = 2;
/** Valid format **/
public static final int MAX_ROWS = 2;

/** Invalid format **/
private static int badStatic = 2;
/** Valid format **/
private static int sNumCreated = 0;

/** Invalid format **/
private int badMember = 2;
/** Valid format **/
private int mNumCreated1 = 0;
/** Valid format **/
protected int mNumCreated2 = 0;

/** commas are wrong **/
private int[] mInts = new int[] {1,2, 3,
4};

//
// Accessor tests
//
/** should be private **/
public static int sTest1;
/** should be private **/
protected static int sTest3;
/** should be private **/
static int sTest2;

/** should be private **/
int mTest1;
/** should be private **/
public int mTest2;

//
// Parameter name format tests
//

/**
* @return hack
* @param badFormat1 bad format
* @param badFormat2 bad format
* @param badFormat3 bad format
* @throws java.lang.Exception abc
**/
int test1(int badFormat1,int badFormat2,
final int badFormat3)
throws java.lang.Exception
{
return 0;
}

/** method that is 20 lines long **/
private void longMethod()
{
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
}

/** constructor that is 10 lines long **/
private InputMethodNameSimple()
{
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
}

/** test local variables */
private void localVariables()
{
// normal decl
int abc = 0;
int ABC = 0;

// final decls
final int cde = 0;
final int CDE = 0;

// decl in for loop init statement
for (int k = 0; k < 1; k++)
{
String innerBlockVariable = "";
}
for (int I = 0; I < 1; I++)
{
String InnerBlockVariable = "";
}
}

/** test method pattern */
void ALL_UPPERCASE_METHOD()
{
}

/** test illegal constant **/
private static final int BAD__NAME = 3;

// A very, very long line that is OK because it matches the regexp "^.*is OK.*regexp.*$"
// long line that has a tab -> <- and would be OK if tab counted as 1 char
// tabs that count as one char because of their position -> <- -> <-, OK

/** some lines to test the error column after tabs */
void errorColumnAfterTabs()
{
// with tab-width 8 all statements below start at the same column,
// with different combinations of ' ' and '\t' before the statement
int tab0 =1;
int tab1 =1;
int tab2 =1;
int tab3 =1;
int tab4 =1;
int tab5 =1;
}

// FIXME:
/* FIXME: a
* FIXME:
* TODO
*/
/* NOTHING */
/* YES */ /* FIXME: x */ /* YES!! */

/** test long comments **/
void veryLong()
{
/*
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
enough talk */
}

/**
* @see to lazy to document all args. Testing excessive # args
**/
void toManyArgs(int aArg1, int aArg2, int aArg3, int aArg4, int aArg5,
int aArg6, int aArg7, int aArg8, int aArg9)
{
}
}

/** Test class for variable naming in for each clauses. */
class InputMethodNameSimple2
{
/** Some more Javadoc. */
public void doSomething()
{
//"O" should be named "o"
for (Object O : new java.util.ArrayList())
{

}
}
}

/** Test enum for member naming check */
enum MyEnum1
{
/** ABC constant */
ABC,

/** XYZ constant */
XYZ;

/** Should be mSomeMemeber */
private int someMember;
}

0 comments on commit b5b9955

Please sign in to comment.