Skip to content

Commit

Permalink
Small fixes for Sonar (#640)
Browse files Browse the repository at this point in the history
This commit contains small changes related to Sonar code analysis.

PR: #640
  • Loading branch information
Michael1993 committed May 24, 2022
1 parent 4b6c620 commit 6a7a129
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 18 deletions.
Expand Up @@ -250,7 +250,7 @@ private static <A extends Annotation> List<A> findOnType(Class<?> element, Class
.collect(Collectors.toList());
}

public static List<? extends Annotation> findParameterArgumentsSources(Method testMethod) {
public static List<Annotation> findParameterArgumentsSources(Method testMethod) {
return Arrays
.stream(testMethod.getParameters())
.map(PioneerAnnotationUtils::collectArgumentSources)
Expand Down
Expand Up @@ -125,7 +125,7 @@ else if (maxAttempts <= minSuccess) {
return new FailedTestRetrier(maxAttempts, minSuccess, retryingTest.onExceptions(), formatter);
}

void failed(Throwable exception) throws Throwable {
<E extends Throwable> void failed(E exception) throws E {
exceptionsSoFar++;

if (exception instanceof TestAbortedException) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/junitpioneer/jupiter/StdOut.java
Expand Up @@ -25,8 +25,8 @@ public class StdOut extends OutputStream {

private final StringWriter writer = new StringWriter();

// recreate default constructor to prevent compiler warning
public StdOut() {
// recreate default constructor to prevent compiler warning
}

@Override
Expand Down
Expand Up @@ -35,10 +35,10 @@
*/
public class ArgumentSets {

private final List<List<?>> argumentSets;
private final List<List<?>> arguments;

private ArgumentSets() {
this.argumentSets = new ArrayList<>();
this.arguments = new ArrayList<>();
}

private ArgumentSets(Collection<?> arguments) {
Expand All @@ -47,7 +47,7 @@ private ArgumentSets(Collection<?> arguments) {
}

private ArgumentSets add(Collection<?> arguments) {
argumentSets.add(new ArrayList<>(arguments));
this.arguments.add(new ArrayList<>(arguments));
return this;
}

Expand Down Expand Up @@ -149,7 +149,7 @@ public final <T> ArgumentSets argumentsForNextParameter(Stream<T> arguments) {
}

List<List<?>> getArguments() {
return argumentSets;
return arguments;
}

}
Expand Up @@ -40,7 +40,7 @@ public Stream<Object> provideArguments(ExtensionContext context, Parameter param
}

private Stream<Node> provideNodes(ExtensionContext context) {
return provideNodes(context, JsonConverterProvider.getJsonConverter(context));
return provideNodes(context, JsonConverterProvider.getJsonConverter());
}

protected abstract Stream<Node> provideNodes(ExtensionContext context, JsonConverter jsonConverter);
Expand Down
Expand Up @@ -39,7 +39,6 @@ class JacksonJsonConverter implements JsonConverter {
@Override
public Node toNode(InputStream stream) {
try {
ObjectMapper objectMapper = getObjectMapper(false);
JsonNode jsonNode = objectMapper.readTree(stream);
return new JacksonNode(objectMapper, jsonNode);
}
Expand Down
Expand Up @@ -39,7 +39,7 @@ public boolean isArray() {

@Override
public Stream<Node> elements() {
return StreamSupport.stream(node.spliterator(), false).map(node -> new JacksonNode(objectMapper, node));
return StreamSupport.stream(node.spliterator(), false).map(element -> new JacksonNode(objectMapper, element));
}

@Override
Expand Down
Expand Up @@ -10,24 +10,22 @@

package org.junitpioneer.jupiter.json;

import org.junit.jupiter.api.extension.ExtensionContext;

class JsonConverterProvider {

private static final boolean jacksonPresent = isClassPresent("com.fasterxml.jackson.databind.ObjectMapper");
private static final boolean JACKSON_PRESENT = isJacksonObjectMapperClassPresent();

static boolean isClassPresent(String className) {
static boolean isJacksonObjectMapperClassPresent() {
try {
JsonConverterProvider.class.getClassLoader().loadClass(className);
JsonConverterProvider.class.getClassLoader().loadClass("com.fasterxml.jackson.databind.ObjectMapper");
return true;
}
catch (Throwable e) {
catch (Exception e) {
return false;
}
}

static JsonConverter getJsonConverter(ExtensionContext context) {
if (jacksonPresent) {
static JsonConverter getJsonConverter() {
if (JACKSON_PRESENT) {
return JacksonJsonConverter.getConverter();
}

Expand Down
@@ -0,0 +1,24 @@
/*
* Copyright 2016-2022 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v20.html
*/

package org.junitpioneer.jupiter.json;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

class NoJsonParserConfiguredExceptionTest {

@Test
void shouldBeUnchecked() {
assertThat(new NoJsonParserConfiguredException()).isInstanceOf(RuntimeException.class);
}

}

0 comments on commit 6a7a129

Please sign in to comment.