Skip to content

Commit

Permalink
Issue #2161: unify test input locations for whitespace package
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach authored and romani committed Oct 16, 2015
1 parent f0f26b9 commit aee8f82
Show file tree
Hide file tree
Showing 32 changed files with 134 additions and 68 deletions.
Expand Up @@ -24,6 +24,9 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.IOException;

import org.junit.Before;
import org.junit.Test;

Expand All @@ -40,6 +43,12 @@ public void setUp() {
checkConfig = createCheckConfig(EmptyForInitializerPadCheck.class);
}

@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}

@Test
public void testGetRequiredTokens() {
EmptyForInitializerPadCheck checkObj = new EmptyForInitializerPadCheck();
Expand Down
Expand Up @@ -23,6 +23,9 @@
import static com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyForIteratorPadCheck.WS_NOT_FOLLOWED;
import static org.junit.Assert.assertArrayEquals;

import java.io.File;
import java.io.IOException;

import org.junit.Before;
import org.junit.Test;

Expand All @@ -39,6 +42,12 @@ public void setUp() {
checkConfig = createCheckConfig(EmptyForIteratorPadCheck.class);
}

@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}

@Test
public void testGetRequiredTokens() {
EmptyForIteratorPadCheck checkObj = new EmptyForIteratorPadCheck();
Expand Down
Expand Up @@ -23,6 +23,9 @@
import static com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck.MSG_SHOULD_BE_SEPARATED;
import static org.junit.Assert.assertArrayEquals;

import java.io.File;
import java.io.IOException;

import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;

Expand All @@ -32,6 +35,11 @@

public class EmptyLineSeparatorCheckTest
extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}

@Test
public void testGetRequiredTokens() {
Expand All @@ -50,7 +58,7 @@ public void testDefault() throws Exception {
"39: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "STATIC_INIT"),
"77: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INTERFACE_DEF"),
};
verify(checkConfig, getPath("whitespace/InputEmptyLineSeparatorCheck.java"), expected);
verify(checkConfig, getPath("InputEmptyLineSeparatorCheck.java"), expected);
}

@Test
Expand All @@ -65,7 +73,7 @@ public void testAllowNoEmptyLineBetweenFields() throws Exception {
"39: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "STATIC_INIT"),
"77: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "INTERFACE_DEF"),
};
verify(checkConfig, getPath("whitespace/InputEmptyLineSeparatorCheck.java"), expected);
verify(checkConfig, getPath("InputEmptyLineSeparatorCheck.java"), expected);
}

@Test
Expand All @@ -74,7 +82,7 @@ public void testHeader() throws Exception {
final String[] expected = {
"19: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "package"),
};
verify(checkConfig, getPath("whitespace/InputEmptyLineSeparatorCheckHeader.java"), expected);
verify(checkConfig, getPath("InputEmptyLineSeparatorCheckHeader.java"), expected);
}

@Test
Expand All @@ -88,15 +96,15 @@ public void testMultipleEmptyLinesBetweenClassMembers() throws Exception {
"38: " + getCheckMessage(MSG_MULTIPLE_LINES, "VARIABLE_DEF"),
"43: " + getCheckMessage(MSG_MULTIPLE_LINES, "METHOD_DEF"),
};
verify(checkConfig, getPath("whitespace/InputEmptyLineSeparatorCheckMultipleEmptyLines.java"), expected);
verify(checkConfig, getPath("InputEmptyLineSeparatorCheckMultipleEmptyLines.java"), expected);
}

@Test
public void testFormerArrayIndexOutOfBounds() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(EmptyLineSeparatorCheck.class);
checkConfig.addAttribute("allowMultipleEmptyLines", "false");
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("whitespace/InputEmptyLineSeparatorFormerException.java"), expected);
verify(checkConfig, getPath("InputEmptyLineSeparatorFormerException.java"), expected);
}

@Test
Expand All @@ -105,7 +113,7 @@ public void testAllowMultipleFieldInClass() throws Exception {
checkConfig.addAttribute("allowMultipleEmptyLines", "false");
checkConfig.addAttribute("allowNoEmptyLineBetweenFields", "true");
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("whitespace/InputEmptyLineSeparatorMultipleFieldsInClass.java"), expected);
verify(checkConfig, getPath("InputEmptyLineSeparatorMultipleFieldsInClass.java"), expected);
}

@Test
Expand All @@ -115,7 +123,7 @@ public void testAllowMultipleImportSeparatedFromPackage() throws Exception {
final String[] expected = {
"1: " + getCheckMessage(MSG_SHOULD_BE_SEPARATED, "import"),
};
verify(checkConfig, getPath("whitespace/InputEmptyLineSeparatorMultipleImportEmptyClass.java"), expected);
verify(checkConfig, getPath("InputEmptyLineSeparatorMultipleImportEmptyClass.java"), expected);
}

@Test
Expand All @@ -142,6 +150,6 @@ public void testPrePreviousLineEmptiness() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(EmptyLineSeparatorCheck.class);
checkConfig.addAttribute("allowMultipleEmptyLines", "false");
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("whitespace/InputPrePreviousLineEmptiness.java"), expected);
verify(checkConfig, getPath("InputPrePreviousLineEmptiness.java"), expected);
}
}
Expand Up @@ -26,6 +26,7 @@
import static org.junit.Assert.assertArrayEquals;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import org.apache.commons.lang3.ArrayUtils;
Expand Down Expand Up @@ -54,6 +55,18 @@ public void setUp() {
//for (final Entry<Class<?>, Integer> entry : entrySet())
}

@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}

@Override
protected String getNonCompilablePath(String filename) throws IOException {
return super.getNonCompilablePath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}

@Test
public void testGetRequiredTokens() {
GenericWhitespaceCheck checkObj = new GenericWhitespaceCheck();
Expand Down Expand Up @@ -94,22 +107,19 @@ public void testDefault() throws Exception {
"60:60: " + getCheckMessage(WS_NOT_PRECEDED, "&"),
"63:60: " + getCheckMessage(WS_FOLLOWED, ">"),
};
verify(checkConfig,
getPath("whitespace/InputGenericWhitespaceCheck.java"),
expected);
verify(checkConfig, getPath("InputGenericWhitespaceCheck.java"), expected);
}

@Test
public void testGh47() throws Exception {
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("whitespace/Gh47.java"), expected);
verify(checkConfig, getPath("Gh47.java"), expected);
}

@Test
public void testInnerClass() throws Exception {
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("whitespace/"
+ "InputGenericWhitespaceInnerClassCheck.java"), expected);
verify(checkConfig, getPath("InputGenericWhitespaceInnerClassCheck.java"), expected);
}

@Test
Expand All @@ -125,9 +135,7 @@ public void testMethodReferences2() throws Exception {
final String[] expected = {
"7:69: " + getCheckMessage(WS_FOLLOWED, ">"),
};
verify(checkConfig, new File("src/test/resources-noncompilable/com/puppycrawl/tools/"
+ "checkstyle/whitespace/"
+ "InputGenericWhitespaceMethodRef.java").getCanonicalPath(), expected);
verify(checkConfig, getNonCompilablePath("InputGenericWhitespaceMethodRef.java"), expected);
}

@Test
Expand Down
Expand Up @@ -24,6 +24,9 @@
import static com.puppycrawl.tools.checkstyle.checks.whitespace.MethodParamPadCheck.WS_PRECEDED;
import static org.junit.Assert.assertArrayEquals;

import java.io.File;
import java.io.IOException;

import org.apache.commons.lang3.ArrayUtils;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -41,6 +44,12 @@ public void setUp() {
checkConfig = createCheckConfig(MethodParamPadCheck.class);
}

@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}

@Test
public void testGetRequiredTokens() {
MethodParamPadCheck checkObj = new MethodParamPadCheck();
Expand All @@ -67,7 +76,7 @@ public void testDefault() throws Exception {
"61:36: " + getCheckMessage(WS_PRECEDED, "("),
"63:13: " + getCheckMessage(LINE_PREVIOUS, "("),
};
verify(checkConfig, getPath("whitespace/InputMethodParamPad.java"), expected);
verify(checkConfig, getPath("InputMethodParamPad.java"), expected);
}

@Test
Expand All @@ -83,7 +92,7 @@ public void testAllowLineBreaks() throws Exception {
"56:18: " + getCheckMessage(WS_PRECEDED, "("),
"61:36: " + getCheckMessage(WS_PRECEDED, "("),
};
verify(checkConfig, getPath("whitespace/InputMethodParamPad.java"), expected);
verify(checkConfig, getPath("InputMethodParamPad.java"), expected);
}

@Test
Expand Down Expand Up @@ -112,14 +121,14 @@ public void testSpaceOption() throws Exception {
"69:66: " + getCheckMessage(WS_NOT_PRECEDED, "("),
"70:57: " + getCheckMessage(WS_NOT_PRECEDED, "("),
};
verify(checkConfig, getPath("whitespace/InputMethodParamPad.java"), expected);
verify(checkConfig, getPath("InputMethodParamPad.java"), expected);
}

@Test
public void test1322879() throws Exception {
checkConfig.addAttribute("option", PadOption.SPACE.toString());
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("whitespace/InputWhitespaceAround.java"),
verify(checkConfig, getPath("InputWhitespaceAround.java"),
expected);
}

Expand Down
Expand Up @@ -21,6 +21,9 @@

import static com.puppycrawl.tools.checkstyle.checks.whitespace.NoLineWrapCheck.MSG_KEY;

import java.io.File;
import java.io.IOException;

import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;

Expand All @@ -29,11 +32,17 @@

public class NoLineWrapCheckTest
extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}

@Test
public void testCaseWithoutLineWrapping() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(NoLineWrapCheck.class);
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("whitespace/NoLineWrapGoodInput.java"), expected);
verify(checkConfig, getPath("NoLineWrapGoodInput.java"), expected);
}

@Test
Expand All @@ -43,7 +52,7 @@ public void testDefaultTokensLineWrapping() throws Exception {
"1: " + getCheckMessage(MSG_KEY, "package"),
"6: " + getCheckMessage(MSG_KEY, "import"),
};
verify(checkConfig, getPath("whitespace/NoLineWrapBadInput.java"), expected);
verify(checkConfig, getPath("NoLineWrapBadInput.java"), expected);
}

@Test
Expand All @@ -57,6 +66,6 @@ public void testCustomTokensLineWrapping()
"13: " + getCheckMessage(MSG_KEY, "METHOD_DEF"),
"20: " + getCheckMessage(MSG_KEY, "ENUM_DEF"),
};
verify(checkConfig, getPath("whitespace/NoLineWrapBadInput.java"), expected);
verify(checkConfig, getPath("NoLineWrapBadInput.java"), expected);
}
}
Expand Up @@ -22,6 +22,9 @@
import static com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck.LINE_NEW;
import static com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck.LINE_PREVIOUS;

import java.io.File;
import java.io.IOException;

import org.junit.Before;
import org.junit.Test;

Expand All @@ -37,6 +40,12 @@ public void setUp() {
checkConfig = createCheckConfig(OperatorWrapCheck.class);
}

@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}

@Test
public void testDefault()
throws Exception {
Expand All @@ -45,7 +54,7 @@ public void testDefault()
"16:15: " + getCheckMessage(LINE_NEW, "-"),
"24:18: " + getCheckMessage(LINE_NEW, "&&"),
"39:30: " + getCheckMessage(LINE_NEW, "&"),
"52:29: " + getCheckMessage(LINE_NEW, "&"),
"52:30: " + getCheckMessage(LINE_NEW, "&"),
};
verify(checkConfig, getPath("InputOpWrap.java"), expected);
}
Expand Down
Expand Up @@ -109,7 +109,7 @@ public void testDefaultForIterator()
"48:27: " + getCheckMessage(WS_PRECEDED, ")"),
"51:26: " + getCheckMessage(WS_PRECEDED, ")"),
};
verify(checkConfig, getPath("InputForWhitespace.java"), expected);
verify(checkConfig, getPath("checks/whitespace/InputForWhitespace.java"), expected);
}

@Test
Expand All @@ -129,7 +129,7 @@ public void testSpaceEmptyForIterator()
"27:14: " + getCheckMessage(WS_NOT_FOLLOWED, "("),
"32:14: " + getCheckMessage(WS_NOT_FOLLOWED, "("),
};
verify(checkConfig, getPath("InputForWhitespace.java"), expected);
verify(checkConfig, getPath("checks/whitespace/InputForWhitespace.java"), expected);
}

@Test
Expand Down
Expand Up @@ -22,6 +22,9 @@
import static com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck.LINE_NEW;
import static com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck.LINE_PREVIOUS;

import java.io.File;
import java.io.IOException;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -39,6 +42,12 @@ public void setUp() {
checkConfig = createCheckConfig(SeparatorWrapCheck.class);
}

@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}

@Test
public void testDot()
throws Exception {
Expand All @@ -47,7 +56,7 @@ public void testDot()
final String[] expected = {
"31:10: " + getCheckMessage(LINE_NEW, "."),
};
verify(checkConfig, getPath("whitespace/InputSeparatorWrap.java"), expected);
verify(checkConfig, getPath("InputSeparatorWrap.java"), expected);
}

@Test
Expand All @@ -57,7 +66,7 @@ public void testComma() throws Exception {
final String[] expected = {
"39:17: " + getCheckMessage(LINE_PREVIOUS, ","),
};
verify(checkConfig, getPath("whitespace/InputSeparatorWrap.java"), expected);
verify(checkConfig, getPath("InputSeparatorWrap.java"), expected);
}

@Test
Expand Down

0 comments on commit aee8f82

Please sign in to comment.