Skip to content

Commit

Permalink
Merge 2bbde1f into 029831f
Browse files Browse the repository at this point in the history
  • Loading branch information
sdudoladov committed Mar 28, 2016
2 parents 029831f + 2bbde1f commit b60f34f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* <b>Default configuration:</b>
* <pre>
* &ltmodule name="ConstructorWithoutParamsCheck"&gt
* &ltproperty name="classNameFormat" value=".*Exception"/&gt
* &ltproperty name="classNameFormat" value=".*Exception$"/&gt
* &ltproperty name="ignoredClassNameFormat" value="UnsupportedOperationException"/&gt
* &lt/module&gt
* </pre>
Expand Down Expand Up @@ -104,7 +104,7 @@ public class ConstructorWithoutParamsCheck extends Check {
/**
* The format string of the regexp for a check to apply to.
*/
private String classNameFormat = ".*Exception";
private String classNameFormat = ".*Exception$";

/**
* The format string of the regexp of class names to ignore.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public void testDefaultConfigProhibitsExceptionsWithoutParams() throws Exception
public void testUserDefinedConfigProhibitsCustomClasses() throws Exception {
defaultConfig.addAttribute("classNameFormat", "Clazz[1-9]");
defaultConfig.addAttribute("ignoredClassNameFormat", "Clazz4");
String[] expectedViolationMsg = {"60:27: " + getCheckMessage(MSG_KEY, "Clazz1"),
"63:27: " + getCheckMessage(MSG_KEY, "Clazz2")};
verify( defaultConfig , getPath("InputConstructorWithoutParamsCheck.java"), expectedViolationMsg);
String[] expectedViolationMsg = {"64:27: " + getCheckMessage(MSG_KEY, "Clazz1"),
"67:27: " + getCheckMessage(MSG_KEY, "Clazz2")};
verify(defaultConfig , getPath("InputConstructorWithoutParamsCheck.java"), expectedViolationMsg);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@

public class InputConstructorWithoutParamsCheck {

public static void inputToTestDefaultConfig() {
public void inputToTestDefaultConfig() {

// the default prohibits constructors without parameters if a class name matches ".*Exception"
// the default config prohibits constructors without parameters if a class name matches ".*Exception$"
final RuntimeException ex = new RuntimeException(); // violation expected

// the default ignores UnsupportedOperationException
// the default config applies only to classes that have the word "Exception" at the end of the class name
final MockExceptionHandler mockExceptionHandler = new MockExceptionHandler(); // no violation expected

// the default config ignores UnsupportedOperationException
final UnsupportedOperationException ex2 = new UnsupportedOperationException(); // no violation expected

// the check allows empty String parameters
Expand All @@ -46,9 +49,10 @@ public static void inputToTestDefaultConfig() {
// hence it is not a violation, even though it matches the regexp in the default config
final Exception[] arrayOfExceptions = new Exception[1]; // no violation expected

// ELIST may occur within array declaration, e.g. in size()
// ELIST may occur within array declaration, e.g., in size()
final List<Exception> dummyList = Arrays.asList(arrayOfExceptions);
final Exception[] arrayOfExceptions2 = new Exception[dummyList.size()]; // no violation expected

}

public void inputToTestCustomConfig() {
Expand Down Expand Up @@ -103,4 +107,8 @@ class Clazz4 {

}

class MockExceptionHandler {

}

}

0 comments on commit b60f34f

Please sign in to comment.