Skip to content

Commit

Permalink
Start checkstyle setup
Browse files Browse the repository at this point in the history
As suggested in #214 the checkstyle setup can be put forward step by
step in order to minimize controversy. The start contains a rule to
enforce spaces instead of tab characters which are already used in
roughly 99.99% of the source.
  • Loading branch information
krichter722 authored and tumbarumba committed Sep 3, 2019
1 parent 7f10c55 commit c5e9c50
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 25 deletions.
22 changes: 22 additions & 0 deletions build.gradle
Expand Up @@ -6,6 +6,7 @@ group = "org.hamcrest"
version = "2.2-SNAPSHOT"

subprojects {
apply plugin: 'checkstyle'
apply plugin: 'java-library'

sourceCompatibility = JavaVersion.VERSION_1_7
Expand All @@ -18,6 +19,27 @@ subprojects {
mavenCentral()
}

checkstyle {

project.ext.checkstyleVersion = '6.18'
//works with a JDK 7 version which is supposed to be supported although
//deprecated, see https://github.com/hamcrest/JavaHamcrest/pull/211 for
//the discussion about the support

sourceSets = [ project.sourceSets.main, project.sourceSets.test ]
ignoreFailures = false
configFile = file("${project.rootDir}/checkstyle.xml")

configurations {
checkstyle
}

dependencies{
assert project.hasProperty("checkstyleVersion")
checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}"
}
}

test {
testLogging {
exceptionFormat = 'full'
Expand Down
11 changes: 11 additions & 0 deletions checkstyle.xml
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<!-- Checks that there are no tab characters ('\t') in the source code. -->
<module name="FileTabCharacter">
<!-- Report on each line in each file -->
<property name="eachLine" value="true"/>
</module>
</module>
Expand Up @@ -44,7 +44,7 @@ public static <E> Matcher<Collection<? extends E>> hasSize(Matcher<? super Integ
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <E> Matcher<Collection<? extends E>> hasSize(int size) {
return (Matcher)IsCollectionWithSize.hasSize(equalTo(size));
return (Matcher)IsCollectionWithSize.hasSize(equalTo(size));
}

}
Expand Up @@ -129,7 +129,7 @@ public static <E> Matcher<Iterable<? extends E>> contains(Matcher<? super E>...
// required for JDK 1.6
//noinspection RedundantTypeArguments
final List<Matcher<? super E>> nullSafeWithExplicitTypeMatchers = NullSafety.<E>nullSafe(itemMatchers);
return contains(nullSafeWithExplicitTypeMatchers);
return contains(nullSafeWithExplicitTypeMatchers);
}

/**
Expand Down
Expand Up @@ -55,7 +55,7 @@ public void testHasAReadableDescription() {
}

public void testCanHandleNullMatchers() {
assertMatches(contains(null, null), asList(null, null));
assertMatches(contains(null, null), asList(null, null));
}

public static class WithValue {
Expand Down
20 changes: 10 additions & 10 deletions hamcrest/src/test/java/org/hamcrest/object/HasToStringTest.java
Expand Up @@ -26,30 +26,30 @@ public String toString() {

@Test public void
matchesWhenUtilisingANestedMatcher() {
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));

assertMatches(matcher, TEST_OBJECT);
assertDoesNotMatch(matcher, new Object());
assertMatches(matcher, TEST_OBJECT);
assertDoesNotMatch(matcher, new Object());
}

@Test public void
matchesWhenUsingShortcutForHasToStringEqualTo() {
final Matcher<Object> matcher = hasToString(TO_STRING_RESULT);
assertMatches(matcher, TEST_OBJECT);
assertDoesNotMatch(matcher, new Object());
final Matcher<Object> matcher = hasToString(TO_STRING_RESULT);
assertMatches(matcher, TEST_OBJECT);
assertDoesNotMatch(matcher, new Object());
}

@Test public void
describesItself() {
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));
assertDescription("with toString() \"toString result\"", matcher);
}

@Test public void
describesAMismatch() {
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));
String expectedMismatchString = "toString() was \"Cheese\"";
final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT));
String expectedMismatchString = "toString() was \"Cheese\"";
assertMismatchDescription(expectedMismatchString, matcher, "Cheese");
}
}
Expand Up @@ -19,26 +19,26 @@ public final class IsEqualIgnoringCaseTest {
@Test public void
ignoresCaseOfCharsInString() {
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
assertMatches(matcher, "HELLO");
assertMatches(matcher, "hello");
assertMatches(matcher, "HelLo");
assertDoesNotMatch(matcher, "bye");
assertDoesNotMatch(matcher, "bye");
}

@Test public void
mismatchesIfAdditionalWhitespaceIsPresent() {
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
assertDoesNotMatch(matcher, "hello ");
assertDoesNotMatch(matcher, " hello");
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
assertDoesNotMatch(matcher, "hello ");
assertDoesNotMatch(matcher, " hello");
}

@Test public void
mismatchesNull() {
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
assertDoesNotMatch(matcher, null);
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
assertDoesNotMatch(matcher, null);
}

@Test(expected=IllegalArgumentException.class) public void
Expand All @@ -49,14 +49,14 @@ public final class IsEqualIgnoringCaseTest {

@Test public void
describesItself() {
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
assertDescription("a string equal to \"heLLo\" ignoring case", matcher);
}

@Test public void
describesAMismatch() {
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
String expectedMismatchString = "was \"Cheese\"";
final Matcher<String> matcher = equalToIgnoringCase("heLLo");
String expectedMismatchString = "was \"Cheese\"";
assertMismatchDescription(expectedMismatchString, matcher, "Cheese");
}
}

0 comments on commit c5e9c50

Please sign in to comment.