Skip to content

Commit

Permalink
#432 added test to confirm default methods work
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyk authored and krzyk committed Sep 10, 2015
1 parent d9dd0ec commit c1dc1e0
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion qulice-checkstyle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<artifactId>qulice-maven-plugin</artifactId>
<configuration>
<excludes combine.children="append">
<exclude>checkstyle:/src/test/resources/com/qulice/checkstyle/ChecksTest/.*</exclude>
<exclude>checkstyle:/src/test/resources/com/qulice/checkstyle/.*</exclude>
<exclude>pmd:.*/src/test/resources/.*</exclude>
<exclude>xml:/src/main/resources/com/qulice/checkstyle/checks.xml</exclude>
<exclude>xml:/src/test/resources/com/qulice/checkstyle/ChecksTest/.*</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.qulice.spi.ValidationException;
import java.io.File;
import java.io.StringWriter;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.WriterAppender;
import org.hamcrest.MatcherAssert;
Expand All @@ -59,6 +60,11 @@ public final class CheckstyleValidatorTest {
*/
private static final String DIRECTORY = "src/main/java/foo";

/**
* License text.
*/
private static final String LICENSE = "Hello.";

/**
* License rule.
* @checkstyle VisibilityModifierCheck (5 lines)
Expand Down Expand Up @@ -100,7 +106,7 @@ 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[] {"Hello."})
).withLines(new String[] {CheckstyleValidatorTest.LICENSE})
.withEol("\n")
.file();
final String content = Joiner.on("\n").join(
Expand Down Expand Up @@ -146,6 +152,38 @@ public void acceptsInstanceMethodReferences() throws Exception {
);
}

/**
* CheckstyleValidator can accept default methods with final modifiers.
* @throws Exception In case of error
*/
@Test
public void acceptsDefaultMethodsWithFinalModifiers() 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 Environment env = mock.withParam(
CheckstyleValidatorTest.LICENSE_PROP,
this.toURL(license)
)
.withFile(
"src/main/java/foo/DefaultMethods.java",
IOUtils.toString(
this.getClass().getResourceAsStream("DefaultMethods.java")
)
);
new CheckstyleValidator().validate(env);
MatcherAssert.assertThat(
writer.toString(),
Matchers.containsString("No Checkstyle violations found")
);
}

/**
* CheckstyleValidator will fail if Windows EOL-s are used.
* @throws Exception If something wrong happens inside
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Hello.
*/
package foo;

import java.util.List;
import java.util.function.Consumer;

/**
* Simple.
* @version $Id $
* @author John Smith (john@example.com)
*/
public interface DefaultMethods {
/**
* Some data.
* @return Some data.
*/
List<String> data();

/**
* Some default method.
* @param action Value to print
*/
default void forEach(final Consumer<String> action) {
for (final String blah : this.data()) {
action.accept(blah);
}
}
}

0 comments on commit c1dc1e0

Please sign in to comment.