Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just some code smell cleanups to appease Sonar #640

Merged
merged 6 commits into from May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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<?>> parameterSets;

private ArgumentSets() {
this.argumentSets = new ArrayList<>();
this.parameterSets = 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.parameterSets.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 parameterSets;
Michael1993 marked this conversation as resolved.
Show resolved Hide resolved
}

}
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(n -> new JacksonNode(objectMapper, n));
Michael1993 marked this conversation as resolved.
Show resolved Hide resolved
}

@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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really worth a test? 🫣

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. What else could we do?

assertThat(new NoJsonParserConfiguredException()).isInstanceOf(RuntimeException.class);
}

}