Issue #2161: unify test input locations for coding package

This commit is contained in:
rnveach 2015-10-16 23:02:06 -04:00 committed by Roman Ivanov
parent 5f3eced2d8
commit de60ea7b86
17 changed files with 208 additions and 26 deletions

View File

@ -158,7 +158,7 @@ public class DescendantTokenCheckTest extends BaseCheckTestSupport {
"17:9: switch without \"default\" clause.",
};
verify(checkConfig, getPath("InputMissingSwitchDefault.java"), expected);
verify(checkConfig, getPath("checks/InputMissingSwitchDefault.java"), expected);
}
@Test
@ -172,11 +172,11 @@ public class DescendantTokenCheckTest extends BaseCheckTestSupport {
checkConfig.addAttribute("maximumMessage", "Literal Strings should be compared using equals(), not ''==''.");
final String[] expected = {
"11:18: Literal Strings should be compared using equals(), not '=='.",
"16:20: Literal Strings should be compared using equals(), not '=='.",
"21:22: Literal Strings should be compared using equals(), not '=='.",
"7:18: Literal Strings should be compared using equals(), not '=='.",
"12:20: Literal Strings should be compared using equals(), not '=='.",
"17:22: Literal Strings should be compared using equals(), not '=='.",
};
verify(checkConfig, getPath("coding" + File.separator + "InputStringLiteralEquality.java"), expected);
verify(checkConfig, getPath("checks" + File.separator + "InputStringLiteralEquality.java"), expected);
}
@Test

View File

@ -21,6 +21,9 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
import static com.puppycrawl.tools.checkstyle.checks.coding.MissingSwitchDefaultCheck.MSG_KEY;
import java.io.File;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -37,6 +40,12 @@ public class MissingSwitchDefaultCheckTest
checkConfig = createCheckConfig(MissingSwitchDefaultCheck.class);
}
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "coding" + File.separator + filename);
}
@Test
public void testMissingSwitchDefault() throws Exception {
final String[] expected = {

View File

@ -22,6 +22,7 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
import static com.puppycrawl.tools.checkstyle.checks.coding.NoCloneCheck.MSG_KEY;
import java.io.File;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
@ -34,6 +35,12 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
*/
public class NoCloneCheckTest
extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "coding" + File.separator + filename);
}
@Test
public void testHasClone()
throws Exception {
@ -48,7 +55,7 @@ public class NoCloneCheckTest
"60: " + getCheckMessage(MSG_KEY),
"98: " + getCheckMessage(MSG_KEY),
};
verify(checkConfig, getPath("coding" + File.separator + "InputClone.java"), expected);
verify(checkConfig, getPath("InputClone.java"), expected);
}
@Test

View File

@ -23,6 +23,7 @@ import static com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck.MSG
import static com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck.MSG_VARIABLE;
import java.io.File;
import java.io.IOException;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Assert;
@ -32,6 +33,12 @@ import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
public class RequireThisCheckTest 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 =
@ -44,7 +51,7 @@ public class RequireThisCheckTest extends BaseCheckTestSupport {
"56:9: " + getCheckMessage(MSG_VARIABLE, "z", "\"this\""),
};
verify(checkConfig,
getPath("coding" + File.separator + "InputRequireThis.java"),
getPath("InputRequireThis.java"),
expected);
}
@ -57,7 +64,7 @@ public class RequireThisCheckTest extends BaseCheckTestSupport {
"17:9: " + getCheckMessage(MSG_METHOD, "method1", "\"this\""),
};
verify(checkConfig,
getPath("coding" + File.separator + "InputRequireThis.java"),
getPath("InputRequireThis.java"),
expected);
}
@ -73,7 +80,7 @@ public class RequireThisCheckTest extends BaseCheckTestSupport {
"56:9: " + getCheckMessage(MSG_VARIABLE, "z", "\"this\""),
};
verify(checkConfig,
getPath("coding" + File.separator + "InputRequireThis.java"),
getPath("InputRequireThis.java"),
expected);
}
@ -94,7 +101,7 @@ public class RequireThisCheckTest extends BaseCheckTestSupport {
"8:16: " + getCheckMessage(MSG_METHOD, "other", "\"this\""),
};
verify(checkConfig,
getPath("coding" + File.separator + "InputRequireThis2.java"),
getPath("InputRequireThis2.java"),
expected);
}
@ -111,7 +118,7 @@ public class RequireThisCheckTest extends BaseCheckTestSupport {
final DefaultConfiguration checkConfig = createCheckConfig(RequireThisCheck.class);
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig,
getPath("coding" + File.separator + "InputRequireThis3.java"),
getPath("InputRequireThis3.java"),
expected);
}
}

View File

@ -22,6 +22,7 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
import static com.puppycrawl.tools.checkstyle.checks.coding.StringLiteralEqualityCheck.MSG_KEY;
import java.io.File;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
@ -31,6 +32,12 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
public class StringLiteralEqualityCheckTest
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 =
@ -40,7 +47,7 @@ public class StringLiteralEqualityCheckTest
"16:20: " + getCheckMessage(MSG_KEY, "=="),
"21:22: " + getCheckMessage(MSG_KEY, "=="),
};
verify(checkConfig, getPath("coding" + File.separator + "InputStringLiteralEquality.java"), expected);
verify(checkConfig, getPath("InputStringLiteralEquality.java"), expected);
}
@Test

View File

@ -40,7 +40,7 @@ public class SuperCloneCheckTest
"35:19: " + getCheckMessage(MSG_KEY, "clone", "super.clone"),
"60:48: " + getCheckMessage(MSG_KEY, "clone", "super.clone"),
};
verify(checkConfig, getPath("coding/InputClone.java"), expected);
verify(checkConfig, getPath("checks/coding/InputClone.java"), expected);
}
@Test

View File

@ -109,14 +109,15 @@ public class OneTopLevelClassCheckTest extends BaseCheckTestSupport {
createCheckConfig(OneTopLevelClassCheck.class);
final String[] expected = {
"25: " + getCheckMessage(MSG_KEY, "NoSuperClone"),
"33: " + getCheckMessage(MSG_KEY, "InnerClone"),
"50: " + getCheckMessage(MSG_KEY, "CloneWithTypeArguments"),
"58: " + getCheckMessage(MSG_KEY, "CloneWithTypeArgumentsAndNoSuper"),
"67: " + getCheckMessage(MSG_KEY, "MyClassWithGenericSuperMethod"),
"84: " + getCheckMessage(MSG_KEY, "AnotherClass"),
"97: " + getCheckMessage(MSG_KEY, "NativeTest"),
"29: " + getCheckMessage(MSG_KEY, "InnerClone"),
"33: " + getCheckMessage(MSG_KEY, "CloneWithTypeArguments"),
"37: " + getCheckMessage(MSG_KEY, "CloneWithTypeArgumentsAndNoSuper"),
"41: " + getCheckMessage(MSG_KEY, "MyClassWithGenericSuperMethod"),
"45: " + getCheckMessage(MSG_KEY, "AnotherClass"),
"48: " + getCheckMessage(MSG_KEY, "NativeTest"),
};
verify(checkConfig, getPath("coding" + File.separator + "InputClone.java"), expected);
verify(checkConfig, getPath("checks" + File.separator + "design"
+ File.separator + "InputClone.java"), expected);
}
@Test

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle;
package com.puppycrawl.tools.checkstyle.checks;
public class InputMissingSwitchDefault {
public void foo() {

View File

@ -0,0 +1,43 @@
package com.puppycrawl.tools.checkstyle.checks;
public class InputStringLiteralEquality
{
void foo(String name)
{
if (name == "Lars")
{
// flagged, should use equals
}
if ("Oleg" == name)
{
// flagged, should use equals
}
if ("Oliver" == "Oliver")
{
// doesn't make much sense because this can be evaluated
// to true at compile time, but is flagged anyway
}
String compare = "Rick";
if (name == compare)
{
// currently not flagged.
//
// Implementing this is very complicated, we would need
// - type info on the == operands
// - prevent false alarms where the user explicitly wants
// to compare object identities
//
// My current feeling is that we should leave finding
// this one to manual code inspections. After all MCI is
// what some of us get paid for :-)
}
if ("Rick".toUpperCase() == "Rick".toLowerCase())
{
// completly dynamic, don't flag
}
}
}

View File

@ -0,0 +1,36 @@
// someexamples of 1.5 extensions
package com.puppycrawl.tools.checkstyle.checks.coding;
@interface MyAnnotation1 {
String name();
int version();
}
@MyAnnotation1(name = "ABC", version = 1)
public class Input15Extensions
{
}
enum Enum2
{
A, B, C;
Enum2() {}
public String toString() {
return ""; //some custom implementation
}
}
interface TestRequireThisEnum
{
enum DAY_OF_WEEK
{
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
}
}

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.coding;
package com.puppycrawl.tools.checkstyle.checks.coding;
public class InputClone
{/* class body */
public InputClone() throws CloneNotSupportedException

View File

@ -0,0 +1,22 @@
package com.puppycrawl.tools.checkstyle.checks.coding;
public class InputMissingSwitchDefault {
public void foo() {
int i = 1;
switch (i) {
case 1: i++; break;
case 2: i--; break;
default: return;
}
}
}
class bad_test {
public void foo() {
int i = 1;
switch (i) {
case 1: i++; break;
case 2: i--; break;
}
}
}

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.coding;
package com.puppycrawl.tools.checkstyle.checks.coding;
import java.awt.Toolkit;
import java.io.ByteArrayInputStream;

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.coding;
package com.puppycrawl.tools.checkstyle.checks.coding;
public class InputRequireThis2 {
private final int number = 1;

View File

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

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.coding;
package com.puppycrawl.tools.checkstyle.checks.coding;
/**
* Input file for the StringLiteralEqualityCheck

View File

@ -0,0 +1,50 @@
package com.puppycrawl.tools.checkstyle.checks.design;
public class InputClone
{/* class body */
public InputClone() throws CloneNotSupportedException
{ //constructor body
super.equals(new String());
super.clone();
}
public Object clone() throws CloneNotSupportedException
{
return super.clone();
}
public void method() throws CloneNotSupportedException
{
super.clone();
}
{
super.clone();
}
}
class NoSuperClone
{
}
class InnerClone
{
}
class CloneWithTypeArguments<T> extends CloneWithTypeArgumentsAndNoSuper<T>
{
}
class CloneWithTypeArgumentsAndNoSuper<T>
{
}
class MyClassWithGenericSuperMethod
{
}
class AnotherClass {
}
class NativeTest {
public native Object clone();
}