From c5e9c506cfcc12e6a075dc38ba1f4e376c56ed45 Mon Sep 17 00:00:00 2001 From: Karl-Philipp Richter Date: Wed, 8 Aug 2018 17:50:25 +0200 Subject: [PATCH] Start checkstyle setup 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. --- build.gradle | 22 +++++++++++++++++ checkstyle.xml | 11 +++++++++ .../collection/IsCollectionWithSize.java | 2 +- .../IsIterableContainingInOrder.java | 2 +- .../IsIterableContainingInOrderTest.java | 2 +- .../org/hamcrest/object/HasToStringTest.java | 20 ++++++++-------- .../text/IsEqualIgnoringCaseTest.java | 24 +++++++++---------- 7 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 checkstyle.xml diff --git a/build.gradle b/build.gradle index 306f2488..a5b59090 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,7 @@ group = "org.hamcrest" version = "2.2-SNAPSHOT" subprojects { + apply plugin: 'checkstyle' apply plugin: 'java-library' sourceCompatibility = JavaVersion.VERSION_1_7 @@ -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' diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 00000000..c1dbabf3 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsCollectionWithSize.java b/hamcrest/src/main/java/org/hamcrest/collection/IsCollectionWithSize.java index f12f57c4..f79afdc6 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsCollectionWithSize.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsCollectionWithSize.java @@ -44,7 +44,7 @@ public static Matcher> hasSize(Matcher Matcher> hasSize(int size) { - return (Matcher)IsCollectionWithSize.hasSize(equalTo(size)); + return (Matcher)IsCollectionWithSize.hasSize(equalTo(size)); } } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java index 221bd47b..ed62aa29 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java @@ -129,7 +129,7 @@ public static Matcher> contains(Matcher... // required for JDK 1.6 //noinspection RedundantTypeArguments final List> nullSafeWithExplicitTypeMatchers = NullSafety.nullSafe(itemMatchers); - return contains(nullSafeWithExplicitTypeMatchers); + return contains(nullSafeWithExplicitTypeMatchers); } /** diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java index 14ae6f58..e71abbfd 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java @@ -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 { diff --git a/hamcrest/src/test/java/org/hamcrest/object/HasToStringTest.java b/hamcrest/src/test/java/org/hamcrest/object/HasToStringTest.java index 5c75ae7d..122e19b5 100644 --- a/hamcrest/src/test/java/org/hamcrest/object/HasToStringTest.java +++ b/hamcrest/src/test/java/org/hamcrest/object/HasToStringTest.java @@ -26,30 +26,30 @@ public String toString() { @Test public void matchesWhenUtilisingANestedMatcher() { - final Matcher matcher = hasToString(equalTo(TO_STRING_RESULT)); + final Matcher 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 matcher = hasToString(TO_STRING_RESULT); - - assertMatches(matcher, TEST_OBJECT); - assertDoesNotMatch(matcher, new Object()); + final Matcher matcher = hasToString(TO_STRING_RESULT); + + assertMatches(matcher, TEST_OBJECT); + assertDoesNotMatch(matcher, new Object()); } @Test public void describesItself() { - final Matcher matcher = hasToString(equalTo(TO_STRING_RESULT)); + final Matcher matcher = hasToString(equalTo(TO_STRING_RESULT)); assertDescription("with toString() \"toString result\"", matcher); } @Test public void describesAMismatch() { - final Matcher matcher = hasToString(equalTo(TO_STRING_RESULT)); - String expectedMismatchString = "toString() was \"Cheese\""; + final Matcher matcher = hasToString(equalTo(TO_STRING_RESULT)); + String expectedMismatchString = "toString() was \"Cheese\""; assertMismatchDescription(expectedMismatchString, matcher, "Cheese"); } } diff --git a/hamcrest/src/test/java/org/hamcrest/text/IsEqualIgnoringCaseTest.java b/hamcrest/src/test/java/org/hamcrest/text/IsEqualIgnoringCaseTest.java index 6ca6375c..b2b73917 100644 --- a/hamcrest/src/test/java/org/hamcrest/text/IsEqualIgnoringCaseTest.java +++ b/hamcrest/src/test/java/org/hamcrest/text/IsEqualIgnoringCaseTest.java @@ -19,26 +19,26 @@ public final class IsEqualIgnoringCaseTest { @Test public void ignoresCaseOfCharsInString() { final Matcher matcher = equalToIgnoringCase("heLLo"); - + assertMatches(matcher, "HELLO"); assertMatches(matcher, "hello"); assertMatches(matcher, "HelLo"); - assertDoesNotMatch(matcher, "bye"); + assertDoesNotMatch(matcher, "bye"); } @Test public void mismatchesIfAdditionalWhitespaceIsPresent() { - final Matcher matcher = equalToIgnoringCase("heLLo"); - - assertDoesNotMatch(matcher, "hello "); - assertDoesNotMatch(matcher, " hello"); + final Matcher matcher = equalToIgnoringCase("heLLo"); + + assertDoesNotMatch(matcher, "hello "); + assertDoesNotMatch(matcher, " hello"); } @Test public void mismatchesNull() { - final Matcher matcher = equalToIgnoringCase("heLLo"); - - assertDoesNotMatch(matcher, null); + final Matcher matcher = equalToIgnoringCase("heLLo"); + + assertDoesNotMatch(matcher, null); } @Test(expected=IllegalArgumentException.class) public void @@ -49,14 +49,14 @@ public final class IsEqualIgnoringCaseTest { @Test public void describesItself() { - final Matcher matcher = equalToIgnoringCase("heLLo"); + final Matcher matcher = equalToIgnoringCase("heLLo"); assertDescription("a string equal to \"heLLo\" ignoring case", matcher); } @Test public void describesAMismatch() { - final Matcher matcher = equalToIgnoringCase("heLLo"); - String expectedMismatchString = "was \"Cheese\""; + final Matcher matcher = equalToIgnoringCase("heLLo"); + String expectedMismatchString = "was \"Cheese\""; assertMismatchDescription(expectedMismatchString, matcher, "Cheese"); } }