Skip to content

Commit

Permalink
Fix sonar findings
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Nov 15, 2024
1 parent 8dc69e7 commit ebec0f5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/itsallcode/matcher/MismatchReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/itsallcode/matcher/auto/AutoConfigBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class AutoConfigBuilder<T> {

MatcherConfig<T> 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();
Expand Down Expand Up @@ -178,11 +178,11 @@ private static <T> Matcher<T> createOptionalMatcher(final T expected) {
return (Matcher<T>) 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);
}
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -101,8 +104,4 @@ protected void describeMismatchSafely(final Optional<T> item, final Description
}
}
}

// This is an utility class that must not be instantiated.
private OptionalMatchers() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public <P> Builder<B> addIterableProperty(final String propertyName,
return addPropertyInternal(propertyName, listMatcher, propertyAccessor);
}

private <P> Matcher<Iterable<? extends P>> createListMatcher(final Function<P, Matcher<P>> matcherBuilder,
private static <P> Matcher<Iterable<? extends P>> createListMatcher(
final Function<P, Matcher<P>> matcherBuilder,
final Iterable<? extends P> expectedPropertyValue) {
if (expectedPropertyValue == null) {
return createNullIterableMatcher();
Expand All @@ -135,7 +136,7 @@ private <P> Matcher<Iterable<? extends P>> createListMatcher(final Function<P, M
}

@SuppressWarnings({ "unchecked", "rawtypes" })
private <P> Matcher<Iterable<? extends P>> createNullIterableMatcher() {
private static <P> Matcher<Iterable<? extends P>> createNullIterableMatcher() {
return new NullIterableMatcher();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ abstract class DemoModelMatcherTest extends MatcherTestBase<DemoModel> {
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
Expand Down

0 comments on commit ebec0f5

Please sign in to comment.