Issue #2557: made tests only cover one subject

This commit is contained in:
rnveach 2015-11-08 16:55:37 -05:00 committed by Roman Ivanov
parent 5f5fc6da1a
commit 36206fcfd0
6 changed files with 252 additions and 129 deletions

View File

@ -20,24 +20,18 @@
package com.google.checkstyle.test.chapter4formatting.rule412nonemptyblocks;
import static com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck.MSG_KEY_LINE_PREVIOUS;
import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_ALONE;
import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_NEW;
import java.io.File;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.checkstyle.test.base.BaseCheckTestSupport;
import com.google.checkstyle.test.base.ConfigurationBuilder;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.api.Configuration;
import com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck;
import com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck;
import com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyOption;
public class LeftCurlyRightCurlyTest extends BaseCheckTestSupport {
public class LeftCurlyTest extends BaseCheckTestSupport {
private static ConfigurationBuilder builder;
@ -111,35 +105,4 @@ public class LeftCurlyRightCurlyTest extends BaseCheckTestSupport {
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(checkConfig, filePath, expected, warnList);
}
@Test
public void rightCurlyTestAlone() throws Exception {
final DefaultConfiguration newCheckConfig = createCheckConfig(RightCurlyCheck.class);
newCheckConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
newCheckConfig.addAttribute("tokens", "CLASS_DEF, METHOD_DEF, CTOR_DEF");
final String[] expected = {
"97:5: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_ALONE, "}", 5),
"97:6: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_NEW, "}", 6),
"108:5: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_ALONE, "}", 5),
"108:6: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_NEW, "}", 6),
"122:6: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_NEW, "}", 6),
};
final String filePath = builder.getFilePath("InputRightCurlyOther");
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(newCheckConfig, filePath, expected, warnList);
}
@Test
public void rightCurlyTestSame() throws Exception {
final DefaultConfiguration newCheckConfig = createCheckConfig(RightCurlyCheck.class);
newCheckConfig.addAttribute("option", RightCurlyOption.SAME.toString());
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
final String filePath = builder.getFilePath("InputRightCurlySame");
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(newCheckConfig, filePath, expected, warnList);
}
}

View File

@ -0,0 +1,76 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2015 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.google.checkstyle.test.chapter4formatting.rule412nonemptyblocks;
import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_ALONE;
import static com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck.MSG_KEY_LINE_NEW;
import java.io.File;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.checkstyle.test.base.BaseCheckTestSupport;
import com.google.checkstyle.test.base.ConfigurationBuilder;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck;
import com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyOption;
public class RightCurlyTest extends BaseCheckTestSupport {
private static ConfigurationBuilder builder;
@BeforeClass
public static void setConfigurationBuilder() {
builder = new ConfigurationBuilder(new File("src/it/"));
}
@Test
public void rightCurlyTestAlone() throws Exception {
final DefaultConfiguration newCheckConfig = createCheckConfig(RightCurlyCheck.class);
newCheckConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
newCheckConfig.addAttribute("tokens", "CLASS_DEF, METHOD_DEF, CTOR_DEF");
final String[] expected = {
"97:5: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_ALONE, "}", 5),
"97:6: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_NEW, "}", 6),
"108:5: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_ALONE, "}", 5),
"108:6: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_NEW, "}", 6),
"122:6: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_NEW, "}", 6),
};
final String filePath = builder.getFilePath("InputRightCurlyOther");
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(newCheckConfig, filePath, expected, warnList);
}
@Test
public void rightCurlyTestSame() throws Exception {
final DefaultConfiguration newCheckConfig = createCheckConfig(RightCurlyCheck.class);
newCheckConfig.addAttribute("option", RightCurlyOption.SAME.toString());
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
final String filePath = builder.getFilePath("InputRightCurlySame");
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(newCheckConfig, filePath, expected, warnList);
}
}

View File

@ -0,0 +1,114 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2015 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.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace;
import java.io.File;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.checkstyle.test.base.BaseCheckTestSupport;
import com.google.checkstyle.test.base.ConfigurationBuilder;
import com.puppycrawl.tools.checkstyle.api.Configuration;
public class GenericWhitespaceTest extends BaseCheckTestSupport {
private static ConfigurationBuilder builder;
@BeforeClass
public static void setConfigurationBuilder() {
builder = new ConfigurationBuilder(new File("src/it/"));
}
@Test
public void whitespaceAroundGenericsTest() throws Exception {
final String msgPreceded = "ws.preceded";
final String msgFollowed = "ws.followed";
final Configuration checkConfig = builder.getCheckConfig("GenericWhitespace");
final String[] expected = {
"12:16: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"12:18: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"12:36: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"12:38: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"12:47: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"12:49: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
"12:49: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"14:32: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"14:34: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"14:45: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"15:32: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"15:34: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"15:45: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"20:38: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"20:40: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"20:61: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
};
final String filePath = builder.getFilePath("WhitespaceAroundInput_Generics");
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(checkConfig, filePath, expected, warnList);
}
@Test
public void genericWhitespaceTest() throws Exception {
final String msgPreceded = "ws.preceded";
final String msgFollowed = "ws.followed";
final String msgNotPreceded = "ws.notPreceded";
final String msgIllegalFollow = "ws.illegalFollow";
final Configuration checkConfig = builder.getCheckConfig("GenericWhitespace");
final String[] expected = {
"16:13: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"16:15: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"16:23: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"16:43: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"16:45: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"16:53: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"17:13: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"17:15: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"17:20: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"17:22: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"17:30: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"17:32: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
"17:32: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"17:52: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"17:54: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"17:59: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"17:61: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"17:69: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"17:71: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
"17:71: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"30:17: " + getCheckMessage(checkConfig.getMessages(), msgNotPreceded, "<"),
"30:21: " + getCheckMessage(checkConfig.getMessages(), msgIllegalFollow, ">"),
"42:21: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"42:30: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
"60:60: " + getCheckMessage(checkConfig.getMessages(), msgNotPreceded, "&"),
"63:60: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
};
final String filePath = builder.getFilePath("GenericWhitespaceInput");
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(checkConfig, filePath, expected, warnList);
}
}

View File

@ -74,38 +74,6 @@ public class WhitespaceAroundTest extends BaseCheckTestSupport {
verify(checkConfig, filePath, expected, warnList);
}
@Test
public void whitespaceAroundGenericsTest() throws Exception {
final String msgPreceded = "ws.preceded";
final String msgFollowed = "ws.followed";
final Configuration checkConfig = builder.getCheckConfig("GenericWhitespace");
final String[] expected = {
"12:16: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"12:18: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"12:36: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"12:38: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"12:47: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"12:49: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
"12:49: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"14:32: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"14:34: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"14:45: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"15:32: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"15:34: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"15:45: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"20:38: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"20:40: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"20:61: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
};
final String filePath = builder.getFilePath("WhitespaceAroundInput_Generics");
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(checkConfig, filePath, expected, warnList);
}
@Test
public void whitespaceAroundEmptyTypesCyclesTest() throws Exception {
@ -117,47 +85,4 @@ public class WhitespaceAroundTest extends BaseCheckTestSupport {
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(checkConfig, filePath, expected, warnList);
}
@Test
public void genericWhitespaceTest() throws Exception {
final String msgPreceded = "ws.preceded";
final String msgFollowed = "ws.followed";
final String msgNotPreceded = "ws.notPreceded";
final String msgIllegalFollow = "ws.illegalFollow";
final Configuration checkConfig = builder.getCheckConfig("GenericWhitespace");
final String[] expected = {
"16:13: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"16:15: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"16:23: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"16:43: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"16:45: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"16:53: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"17:13: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"17:15: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"17:20: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"17:22: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"17:30: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"17:32: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
"17:32: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"17:52: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"17:54: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"17:59: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"17:61: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
"17:69: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"17:71: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
"17:71: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
"30:17: " + getCheckMessage(checkConfig.getMessages(), msgNotPreceded, "<"),
"30:21: " + getCheckMessage(checkConfig.getMessages(), msgIllegalFollow, ">"),
"42:21: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
"42:30: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
"60:60: " + getCheckMessage(checkConfig.getMessages(), msgNotPreceded, "&"),
"63:60: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
};
final String filePath = builder.getFilePath("GenericWhitespaceInput");
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(checkConfig, filePath, expected, warnList);
}
}

View File

@ -0,0 +1,60 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2015 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.google.checkstyle.test.chapter5naming.rule528typevariablenames;
import java.io.File;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.checkstyle.test.base.BaseCheckTestSupport;
import com.google.checkstyle.test.base.ConfigurationBuilder;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.Configuration;
public class ClassTypeParameterNameTest extends BaseCheckTestSupport {
private static final String MSG_KEY = "name.invalidPattern";
private static ConfigurationBuilder builder;
private static Configuration configuration;
private static String format;
@BeforeClass
public static void setConfigurationBuilder() throws CheckstyleException {
builder = new ConfigurationBuilder(new File("src/it/"));
configuration = builder.getCheckConfig("ClassTypeParameterName");
format = configuration.getAttribute("format");
}
@Test
public void testClassDefault() throws Exception {
final String[] expected = {
"5:31: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "t", format),
"13:14: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "foo", format),
"27:24: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "$foo", format),
};
final String filePath = builder.getFilePath("ClassTypeParameterNameInput");
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(configuration, filePath, expected, warnList);
}
}

View File

@ -29,7 +29,7 @@ import com.google.checkstyle.test.base.ConfigurationBuilder;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.Configuration;
public class ClassMethodTypeParameterNameTest extends BaseCheckTestSupport {
public class MethodTypeParameterNameTest extends BaseCheckTestSupport {
private static final String MSG_KEY = "name.invalidPattern";
private static ConfigurationBuilder builder;
@ -43,21 +43,6 @@ public class ClassMethodTypeParameterNameTest extends BaseCheckTestSupport {
format = configuration.getAttribute("format");
}
@Test
public void testClassDefault() throws Exception {
final String[] expected = {
"5:31: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "t", format),
"13:14: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "foo", format),
"27:24: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "$foo", format),
};
final String filePath = builder.getFilePath("ClassTypeParameterNameInput");
final Integer[] warnList = builder.getLinesWithWarn(filePath);
verify(configuration, filePath, expected, warnList);
}
@Test
public void testMethodDefault() throws Exception {