Skip to content

Commit

Permalink
#526 Refactored code in CheckstyleValidatorTest
Browse files Browse the repository at this point in the history
  • Loading branch information
prahladyeri committed Dec 22, 2015
1 parent 94af27c commit a43f4d7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,69 +230,25 @@ public void acceptsConstructorParametersNamedJustLikeFields()
* CheckstyleValidator will fail if Windows EOL-s are used.
* @throws Exception If something wrong happens inside
*/
@Test(expected = ValidationException.class)
@Test
public void passesWindowsEndsOfLineWithoutException() throws Exception {
final Environment.Mock mock = new Environment.Mock();
final File license = this.rule.savePackageInfo(
new File(mock.basedir(), CheckstyleValidatorTest.DIRECTORY)
).withLines(new String[] {"Hello.", "", "World."})
.withEol("\r\n")
.file();
final String content =
// @checkstyle StringLiteralsConcatenation (12 lines)
"/**\r\n"
+ " * Hello.\r\n"
+ " *\r\n"
+ " * World.\r\n"
+ " */\r\n"
+ "package foo;\r\n"
+ "/**\r\n"
+ " * Simple class.\r\n"
+ " * @version $Id $\r\n"
+ " * @author John Doe (john@qulice.com)\r\n"
+ " */\r\n"
+ "public class Main { }\r\n";
final Environment env = mock.withParam(
CheckstyleValidatorTest.LICENSE_PROP,
this.toURL(license)
).withFile("src/main/java/foo/Main.java", content);
new CheckstyleValidator().validate(env);
this.validateCheckstyle(
"MainWindows.java", false,
Matchers.containsString(CheckstyleValidatorTest.NO_VIOLATIONS)
);
}

/**
* Fail validation with Windows-style formatting of the license and
* Linux-style formatting of the sources.
* @throws Exception If something wrong happens inside
*/
@Test(expected = ValidationException.class)
@Test
public void testWindowsEndsOfLineWithLinuxSources() throws Exception {
final Environment.Mock mock = new Environment.Mock();
final File license = this.rule.savePackageInfo(
new File(mock.basedir(), CheckstyleValidatorTest.DIRECTORY)
).withLines(new String[] {"Welcome.", "", "Friend."})
.withEol("\r\n")
.file();
final String content =
// @checkstyle MultipleStringLiterals (11 lines)
"/**\n"
+ " * Welcome.\n"
+ " *\n"
+ " * Friend.\n"
+ " */\n"
+ "package foo;\n"
+ "/**\n"
+ " * Just a simple class.\n"
+ " * @version $Id $\n"
+ " * @author Alex Doe (alex@qulice.com)\n"
+ " */\n"
+ "public class Bar { }" + System.getProperty("line.separator");
final Environment env = mock
.withFile("src/main/java/foo/Bar.java", content)
.withParam(
CheckstyleValidatorTest.LICENSE_PROP,
this.toURL(license)
);
new CheckstyleValidator().validate(env);
this.validateCheckstyle(
"Bar.java", false,
Matchers.containsString(CheckstyleValidatorTest.NO_VIOLATIONS)
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Welcome.
*
* Friend.
*/
package foo;
/**
* Just a simple class.
* @version $Id $
* @author Alex Doe (alex@qulice.com)
*/
public class Bar { }

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Hello.
*
* World.
*/
package foo;
/**
* Simple class.
* @version $Id $
* @author John Doe (john@qulice.com)
*/
public class MainWindows { }

0 comments on commit a43f4d7

Please sign in to comment.