Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Dec 22, 2015
2 parents 85d4010 + ece35ec commit 5bf0264
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/
package com.qulice.checkstyle;

import com.google.common.base.Joiner;
import com.qulice.spi.Environment;
import com.qulice.spi.ValidationException;
import java.io.File;
Expand Down Expand Up @@ -114,52 +113,9 @@ public void catchesCheckstyleViolationsInLicense() throws Exception {
*/
@Test
public void acceptsInstanceMethodReferences() throws Exception {
final Environment.Mock mock = new Environment.Mock();
final File license = this.rule.savePackageInfo(
new File(mock.basedir(), CheckstyleValidatorTest.DIRECTORY)
).withLines(new String[] {CheckstyleValidatorTest.LICENSE})
.withEol("\n")
.file();
final String content = Joiner.on("\n").join(
"/**",
" * Hello.",
" */",
"package foo;",
"/**",
" * Simple.",
" * @version $Id $",
" * @author John Smith (john@example.com)",
" */",
"public final class Main {",
" /**",
" * Start. Check fails in this method.",
" */",
" private void start() {",
" Collections.singletonList(\"1\")",
" .forEach(this::doSomething);",
" }",
" /**",
" * Method to be referenced.",
" * @param value Value to print",
" */",
" private void doSomething(final String value) {",
" System.out.println(value);",
" }",
"}",
""
);
final StringWriter writer = new StringWriter();
org.apache.log4j.Logger.getRootLogger().addAppender(
new WriterAppender(new SimpleLayout(), writer)
);
final Environment env = mock.withParam(
CheckstyleValidatorTest.LICENSE_PROP,
this.toURL(license)
).withFile("src/main/java/foo/Main.java", content);
new CheckstyleValidator().validate(env);
MatcherAssert.assertThat(
writer.toString(),
Matchers.containsString(CheckstyleValidatorTest.NO_VIOLATIONS)
this.validateCheckstyle(
"InstanceMethodRef.java", true,
Matchers.containsString(CheckstyleValidatorTest.NO_VIOLATIONS)
);
}

Expand All @@ -171,35 +127,8 @@ public void acceptsInstanceMethodReferences() throws Exception {
@Test
public void reportsErrorWhenParameterObjectIsNotDocumented()
throws Exception {
final Environment.Mock mock = new Environment.Mock();
final File license = this.rule.savePackageInfo(
new File(mock.basedir(), CheckstyleValidatorTest.DIRECTORY)
).withLines(new String[] {CheckstyleValidatorTest.LICENSE})
.withEol("\n").file();
final StringWriter writer = new StringWriter();
org.apache.log4j.Logger.getRootLogger().addAppender(
new WriterAppender(new SimpleLayout(), writer)
);
final String name = "ParametrizedClass.java";
final Environment env = mock.withParam(
CheckstyleValidatorTest.LICENSE_PROP,
this.toURL(license)
)
.withFile(
String.format("src/main/java/foo/%s", name),
IOUtils.toString(
this.getClass().getResourceAsStream(name)
)
);
boolean valid = true;
try {
new CheckstyleValidator().validate(env);
} catch (final ValidationException ex) {
valid = false;
}
MatcherAssert.assertThat(valid, Matchers.is(false));
MatcherAssert.assertThat(
writer.toString(),
this.validateCheckstyle(
"ParametrizedClass.java", false,
Matchers.containsString(
"Type Javadoc comment is missing an @param <T> tag."
)
Expand Down Expand Up @@ -316,69 +245,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(
"WindowsEol.java", false,
Matchers.containsString("LICENSE found")
);
}

/**
* 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(
"WindowsEolLinux.java", false,
Matchers.containsString("LICENSE found")
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Hello.
*/
package foo;
/**
* Simple.
* @version $Id $
* @author John Smith (john@example.com)
*/
public final class InstanceMethodRef {
/**
* Start. Check fails in this method.
*/
private void start() {
Collections.singletonList("1")
.forEach(this::doSomething);
}
/**
* Method to be referenced.
* @param value Value to print
*/
private void doSomething(final String value) {
System.out.println(value);
}
}

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 WindowsEol { }

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 WindowsEolLinux { }

0 comments on commit 5bf0264

Please sign in to comment.