diff --git a/src/main/java/org/itsallcode/matcher/MismatchReporter.java b/src/main/java/org/itsallcode/matcher/MismatchReporter.java index 488a523..6723402 100644 --- a/src/main/java/org/itsallcode/matcher/MismatchReporter.java +++ b/src/main/java/org/itsallcode/matcher/MismatchReporter.java @@ -9,7 +9,7 @@ * does not match, the overall state is 'not matching'. Additionally it builds a * description of the mismatch. */ -public class MismatchReporter { +public final class MismatchReporter { private final Description mismatchDescription; private boolean firstMismatch = true; private boolean matches = true; diff --git a/src/main/java/org/itsallcode/matcher/auto/AutoConfigBuilder.java b/src/main/java/org/itsallcode/matcher/auto/AutoConfigBuilder.java index 7d2a35e..86c6ec2 100644 --- a/src/main/java/org/itsallcode/matcher/auto/AutoConfigBuilder.java +++ b/src/main/java/org/itsallcode/matcher/auto/AutoConfigBuilder.java @@ -55,11 +55,11 @@ class AutoConfigBuilder { MatcherConfig build() { Arrays.stream(expected.getClass().getMethods()) // - .filter(this::isNotIgnored) // + .filter(AutoConfigBuilder::isNotIgnored) // .filter(this::isGetterMethodName) // - .filter(this::isGetterMethodSignature) // + .filter(AutoConfigBuilder::isGetterMethodSignature) // .sorted(Comparator.comparing(this::hasSimpleReturnType).reversed() // - .thenComparing(this::hasArrayReturnType) // + .thenComparing(AutoConfigBuilder::hasArrayReturnType) // .thenComparing(Method::getName)) // .forEach(this::addConfigForGetter); return configBuilder.build(); @@ -178,11 +178,11 @@ private static Matcher createOptionalMatcher(final T expected) { return (Matcher) OptionalMatchers.isPresentAnd(AutoMatcher.equalTo(expectedOptional.get())); } - private boolean isNotIgnored(final Method method) { + private static boolean isNotIgnored(final Method method) { return !IGNORED_METHOD_NAMES.contains(method.getName()); } - private boolean isGetterMethodSignature(final Method method) { + private static boolean isGetterMethodSignature(final Method method) { return method.getParameterCount() == 0 // && !method.getReturnType().equals(Void.TYPE); } @@ -202,7 +202,7 @@ private void addConfigForGetter(final Method method) { configBuilder.addProperty(propertyName, createGetter(method), AutoMatcher::equalTo); } - private boolean hasArrayReturnType(final Method method) { + private static boolean hasArrayReturnType(final Method method) { return method.getReturnType().isArray(); } diff --git a/src/main/java/org/itsallcode/matcher/auto/OptionalMatchers.java b/src/main/java/org/itsallcode/matcher/auto/OptionalMatchers.java index 741c93d..653353d 100644 --- a/src/main/java/org/itsallcode/matcher/auto/OptionalMatchers.java +++ b/src/main/java/org/itsallcode/matcher/auto/OptionalMatchers.java @@ -18,7 +18,10 @@ * * @author npathai, sweiler */ -class OptionalMatchers { +final class OptionalMatchers { + // This is an utility class that must not be instantiated. + private OptionalMatchers() { + } /** * Creates a matcher that matches when the examined {@code Optional} contains no @@ -101,8 +104,4 @@ protected void describeMismatchSafely(final Optional item, final Description } } } - - // This is an utility class that must not be instantiated. - private OptionalMatchers() { - } } diff --git a/src/main/java/org/itsallcode/matcher/config/MatcherConfig.java b/src/main/java/org/itsallcode/matcher/config/MatcherConfig.java index dd4259a..18fa7c2 100644 --- a/src/main/java/org/itsallcode/matcher/config/MatcherConfig.java +++ b/src/main/java/org/itsallcode/matcher/config/MatcherConfig.java @@ -120,7 +120,8 @@ public

Builder addIterableProperty(final String propertyName, return addPropertyInternal(propertyName, listMatcher, propertyAccessor); } - private

Matcher> createListMatcher(final Function> matcherBuilder, + private static

Matcher> createListMatcher( + final Function> matcherBuilder, final Iterable expectedPropertyValue) { if (expectedPropertyValue == null) { return createNullIterableMatcher(); @@ -135,7 +136,7 @@ private

Matcher> createListMatcher(final Function Matcher> createNullIterableMatcher() { + private static

Matcher> createNullIterableMatcher() { return new NullIterableMatcher(); } diff --git a/src/test/java/org/itsallcode/matcher/model/DemoModelMatcherTest.java b/src/test/java/org/itsallcode/matcher/model/DemoModelMatcherTest.java index 6d4c98f..2d1e2fb 100644 --- a/src/test/java/org/itsallcode/matcher/model/DemoModelMatcherTest.java +++ b/src/test/java/org/itsallcode/matcher/model/DemoModelMatcherTest.java @@ -26,11 +26,12 @@ abstract class DemoModelMatcherTest extends MatcherTestBase { static final String ATTR2 = "attrValue2"; static final String ATTR3 = "attrValue3"; - static String SIMPLE_MODEL_DESCRIPTION = "{id=<" + ID1 + ">, longVal=null, name=\"" + NAME1 + static final String SIMPLE_MODEL_DESCRIPTION = "{id=<" + ID1 + ">, longVal=null, name=\"" + NAME1 + "\", attr=null, children=null, stringArray=null}"; static final String CHILD1 = "{id=<" + ID2 + ">, longVal=null, name=\"" + NAME2 + "\", attr={value=\"" + ATTR2 + "\"}, children=an empty iterable, stringArray=null}"; - static String COMPLEX_MODEL_DESCRIPTION = "{id=<" + ID1 + ">, longVal=null, name=\"" + NAME1 + "\", attr={value=\"" + static final String COMPLEX_MODEL_DESCRIPTION = "{id=<" + ID1 + ">, longVal=null, name=\"" + NAME1 + + "\", attr={value=\"" + ATTR1 + "\"}, children=iterable containing [" + CHILD1 + "], stringArray=null}"; @Test