Issue #2161: unify test input locations for coding package

This commit is contained in:
rnveach 2015-10-16 20:52:34 -04:00
parent e76a439c2b
commit 96d3aaea19
12 changed files with 343 additions and 18 deletions

View File

@ -21,6 +21,9 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
import static com.puppycrawl.tools.checkstyle.checks.coding.AvoidInlineConditionalsCheck.MSG_KEY;
import java.io.File;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
@ -29,15 +32,21 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
public class AvoidInlineConditionalsCheckTest
extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "coding" + File.separator + filename);
}
@Test
public void testIt()
throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AvoidInlineConditionalsCheck.class);
final String[] expected = {
"97:29: " + getCheckMessage(MSG_KEY),
"98:20: " + getCheckMessage(MSG_KEY),
"150:34: " + getCheckMessage(MSG_KEY),
"32:29: " + getCheckMessage(MSG_KEY),
"33:20: " + getCheckMessage(MSG_KEY),
"46:34: " + getCheckMessage(MSG_KEY),
};
verify(checkConfig, getPath("InputWhitespace.java"), expected);
}

View File

@ -24,6 +24,9 @@ import static com.puppycrawl.tools.checkstyle.checks.coding.DeclarationOrderChec
import static com.puppycrawl.tools.checkstyle.checks.coding.DeclarationOrderCheck.MSG_INSTANCE;
import static com.puppycrawl.tools.checkstyle.checks.coding.DeclarationOrderCheck.MSG_STATIC;
import java.io.File;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
@ -34,6 +37,12 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
public class DeclarationOrderCheckTest
extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "coding" + File.separator + filename);
}
@Test
public void testDefault() throws Exception {
final DefaultConfiguration checkConfig =
@ -68,7 +77,7 @@ public class DeclarationOrderCheckTest
"178:5: " + getCheckMessage(MSG_INSTANCE),
"182:9: " + getCheckMessage(MSG_ACCESS),
};
verify(checkConfig, getPath("coding/InputDeclarationOrder.java"), expected);
verify(checkConfig, getPath("InputDeclarationOrder.java"), expected);
}
@Test
@ -87,7 +96,7 @@ public class DeclarationOrderCheckTest
"152:5: " + getCheckMessage(MSG_CONSTRUCTOR),
"178:5: " + getCheckMessage(MSG_INSTANCE),
};
verify(checkConfig, getPath("coding/InputDeclarationOrder.java"), expected);
verify(checkConfig, getPath("InputDeclarationOrder.java"), expected);
}
@Test
@ -124,7 +133,7 @@ public class DeclarationOrderCheckTest
"178:5: " + getCheckMessage(MSG_INSTANCE),
"182:9: " + getCheckMessage(MSG_ACCESS),
};
verify(checkConfig, getPath("coding/InputDeclarationOrder.java"), expected);
verify(checkConfig, getPath("InputDeclarationOrder.java"), expected);
}
@Test
@ -162,5 +171,4 @@ public class DeclarationOrderCheckTest
DeclarationOrderCheck check = new DeclarationOrderCheck();
check.visitToken(array);
}
}

View File

@ -21,6 +21,9 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
import static com.puppycrawl.tools.checkstyle.checks.coding.EmptyStatementCheck.MSG_KEY;
import java.io.File;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
@ -29,6 +32,12 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
public class EmptyStatementCheckTest
extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "coding" + File.separator + filename);
}
@Test
public void testEmptyStatements()
throws Exception {

View File

@ -21,6 +21,9 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
import static com.puppycrawl.tools.checkstyle.checks.coding.EqualsHashCodeCheck.MSG_KEY;
import java.io.File;
import java.io.IOException;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Assert;
import org.junit.Test;
@ -30,14 +33,20 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
public class EqualsHashCodeCheckTest
extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "coding" + File.separator + filename);
}
@Test
public void testIt() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(EqualsHashCodeCheck.class);
final String[] expected = {
"126:9: " + getCheckMessage(MSG_KEY),
"163:13: " + getCheckMessage(MSG_KEY),
"191:9: " + getCheckMessage(MSG_KEY),
"57:9: " + getCheckMessage(MSG_KEY),
"94:13: " + getCheckMessage(MSG_KEY),
"122:9: " + getCheckMessage(MSG_KEY),
};
verify(checkConfig, getPath("InputSemantic.java"), expected);
}
@ -47,7 +56,7 @@ public class EqualsHashCodeCheckTest
final DefaultConfiguration checkConfig =
createCheckConfig(EqualsHashCodeCheck.class);
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("coding/InputEqualsHashCodeCheck.java"), expected);
verify(checkConfig, getPath("InputEqualsHashCodeCheck.java"), expected);
}
@Test

View File

@ -44,18 +44,18 @@ public class IllegalInstantiationCheckTest
checkConfig.addAttribute(
"classes",
"java.lang.Boolean,"
+ "com.puppycrawl.tools.checkstyle.InputModifier,"
+ "com.puppycrawl.tools.checkstyle.checks.coding.InputModifier,"
+ "java.io.File,"
+ "java.awt.Color");
final String[] expected = {
"19:21: " + getCheckMessage(MSG_KEY, "java.lang.Boolean"),
"24:21: " + getCheckMessage(MSG_KEY, "java.lang.Boolean"),
"31:16: " + getCheckMessage(MSG_KEY, "java.lang.Boolean"),
"38:21: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.InputModifier"),
"38:21: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.checks.coding.InputModifier"),
"41:18: " + getCheckMessage(MSG_KEY, "java.io.File"),
"44:21: " + getCheckMessage(MSG_KEY, "java.awt.Color"),
};
verify(checkConfig, getPath("InputSemantic.java"), expected);
verify(checkConfig, getPath("checks/coding/InputSemantic.java"), expected);
}
@Test

View File

@ -124,9 +124,9 @@ public class OneTopLevelClassCheckTest extends BaseCheckTestSupport {
final DefaultConfiguration checkConfig =
createCheckConfig(OneTopLevelClassCheck.class);
final String[] expected = {
"83: " + getCheckMessage(MSG_KEY, "InputDeclarationOrderEnum"),
"10: " + getCheckMessage(MSG_KEY, "InputDeclarationOrderEnum"),
};
verify(checkConfig, getPath("coding" + File.separator + "InputDeclarationOrder.java"), expected);
verify(checkConfig, getPath("checks" + File.separator + "design" + File.separator + "InputDeclarationOrder.java"), expected);
}
@Test

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.coding;
package com.puppycrawl.tools.checkstyle.checks.coding;
public class InputDeclarationOrder
{

View File

@ -0,0 +1,83 @@
package com.puppycrawl.tools.checkstyle.checks.coding;
/**
* Input class for testing EmptyStatementCheck
* @author Rick Giles
* @version 5-May-2003
*/
public class InputEmptyStatement
{
public InputEmptyStatement()
{
;
}
public void EmptyMethod()
{
;
}
public void EmptyStatements(boolean cond)
{
for (;cond;);
for (;cond;)
{
;
}
if (true);
if (true)
{
;
}
if (cond)
{
int i;
}
else
{
;
}
switch (1)
{
case 1 :
;
default :
;
}
while (cond);
while (cond)
{
;
}
do;
while (cond);
do
{
;
}
while (cond);
try
{
;
}
catch (Exception ex)
{
;
}
finally
{
;
}
}
}

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.coding;
package com.puppycrawl.tools.checkstyle.checks.coding;
public class InputEqualsHashCodeCheck {
public boolean notEquals() {

View File

@ -0,0 +1,135 @@
////////////////////////////////////////////////////////////////////////////////
// Test case file for checkstyle.
// Created: 2001
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks.coding;
import java.io.*; // star import for instantiation tests
import java.awt.Dimension; // explicit import for instantiation tests
import java.awt.Color;
/**
* Test case for detecting simple semantic errors.
* @author Lars Kühne
**/
class InputSemantic
{
/* Boolean instantiation in a static initializer */
static {
Boolean x = new Boolean(true);
}
/* Boolean instantiation in a non-static initializer */
{
Boolean x = new Boolean(true);
Boolean[] y = new Boolean[]{Boolean.TRUE, Boolean.FALSE};
}
/** fully qualified Boolean instantiation in a method. **/
Boolean getBoolean()
{
return new java.lang.Boolean(true);
}
void otherInstantiations()
{
// instantiation of classes in the same package
Object o1 = new InputBraces();
Object o2 = new InputModifier();
// classes in another package with .* import
ByteArrayOutputStream s = new ByteArrayOutputStream();
File f = new File("/tmp");
// classes in another package with explicit import
Dimension dim = new Dimension();
Color col = new Color(0, 0, 0);
}
public class EqualsVsHashCode1
{
public boolean equals(int a) // wrong arg type, don't flag
{
return a == 1;
}
}
public class EqualsVsHashCode2
{
public boolean equals(String a) // flag
{
return true;
}
}
public class EqualsVsHashCode3
{
public boolean equals(Object a) // don't flag
{
return true;
}
public int hashCode()
{
return 0;
}
}
public class EqualsVsHashCode4
{
// in anon inner class
ByteArrayOutputStream bos1 = new ByteArrayOutputStream()
{
public boolean equals(Object a) // don't flag
{
return true;
}
public int hashCode()
{
return 0;
}
};
ByteArrayOutputStream bos2 = new ByteArrayOutputStream()
{
public boolean equals(Object a) // flag
{
return true;
}
};
}
public void triggerEmptyBlockWithoutBlock()
{
// an if statement without a block to increase test coverage
if (true)
return;
}
// empty instance initializer
{
}
public class EqualsVsHashCode5
{
public <A> boolean equals(int a) // wrong arg type, don't flag even with generics
{
return a == 1;
}
}
public class EqualsVsHashCode6
{
public <A> boolean equals(Comparable<A> a) // flag, weven with generics
{
return true;
}
}
private class InputBraces {
}
private class InputModifier {
}
}

View File

@ -0,0 +1,54 @@
////////////////////////////////////////////////////////////////////////////////
// Test case file for checkstyle.
// Created: 2001
////////////////////////////////////////////////////////////////////////////////
package com . puppycrawl
.tools.
checkstyle.checks.coding;
/**
* Class for testing inline conditionals.
* error missing author tag
**/
class InputWhitespace
{
/** method **/
void method1()
{
final int a = 1;
int b= 1; // Ignore 1
b=1; // Ignore 1
b+=1; // Ignore 1
b -=- 1 + (+ b); // Ignore 2
b = b ++ + b --; // Ignore 1
b = ++ b - -- b; // Ignore 1
}
private int mVar4 = 1;
/** test questions **/
private void testQuestions()
{
boolean b = (1 == 2)?true:false;
b = (1==2) ? false : true;
}
/** assert statement test */
public void assertTest()
{
// OK
assert true;
// OK
assert true : "Whups";
// evil colons, should be OK
assert "OK".equals(null) ? false : true : "Whups";
// missing WS around assert
assert(true);
// missing WS around colon
assert true:"Whups";
}
}

View File

@ -0,0 +1,18 @@
package com.puppycrawl.tools.checkstyle.checks.design;
public class InputDeclarationOrder
{
private class InnerClass
{
}
}
enum InputDeclarationOrderEnum
{
ENUM_VALUE_1;
class AsyncProcess {
private final int startLogErrorsCnt = 0;
protected final int maxTotalConcurrentTasks = 0;
}
}