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

Fix some Sonar or/and "IDEA inspect code" issues (partly) #2689

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public abstract class MatchResult implements Comparable<MatchResult> {
Expand Down Expand Up @@ -111,6 +112,6 @@ public int compareTo(MatchResult other) {
return Double.compare(other.getDistance(), getDistance());
}

public static final java.util.function.Predicate<WeightedMatchResult> ARE_EXACT_MATCH =
public static final Predicate<WeightedMatchResult> ARE_EXACT_MATCH =
WeightedMatchResult::isExactMatch;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2023 Thomas Akehurst
* Copyright (C) 2017-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,7 +35,7 @@ public String render(Diff diff) {

public static String junitStyleDiffMessage(Object expected, Object actual) {
return String.format(
" expected:<\n%s> but was:<\n%s>",
" expected:<%n%s> but was:<%n%s>",
Strings.normaliseLineBreaks(expected.toString()),
Strings.normaliseLineBreaks(actual.toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void writeBlankLine(StringBuilder sb) {
}

private void writeSingleLine(StringBuilder sb, String left, String right, String message) {
sb.append("").append(rightPad(left, getMiddle() + 1, " ")).append("|");
sb.append(rightPad(left, getMiddle() + 1, " ")).append("|");

if (isNotEmpty(right)) {
sb.append(" ");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Thomas Akehurst
* Copyright (C) 2020-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,17 +21,17 @@

import org.junit.jupiter.api.Test;

public class ArrayFunctionsTest {
class ArrayFunctionsTest {

private final Integer[] empty = new Integer[0];

@Test
public void concatEmptyAndEmpty() {
void concatEmptyAndEmpty() {
assertArrayEquals(empty, concat(empty, empty));
}

@Test
public void concatNonEmptyAndEmpty() {
void concatNonEmptyAndEmpty() {
Integer[] first = {1, 2};

Integer[] result = concat(first, empty);
Expand All @@ -42,7 +42,7 @@ public void concatNonEmptyAndEmpty() {
}

@Test
public void concatEmptyAndNonEmpty() {
void concatEmptyAndNonEmpty() {
Integer[] second = {1, 2};

Integer[] result = concat(empty, second);
Expand All @@ -53,7 +53,7 @@ public void concatEmptyAndNonEmpty() {
}

@Test
public void concatNonEmptyAndNonEmpty() {
void concatNonEmptyAndNonEmpty() {
Integer[] first = {1, 2};
Integer[] second = {3, 4};

Expand All @@ -66,18 +66,18 @@ public void concatNonEmptyAndNonEmpty() {
}

@Test
public void prependNullAndEmpty() {
void prependNullAndEmpty() {
assertArrayEquals(new Integer[] {null}, prepend(null, empty));
}

@Test
public void prependSomeAndEmpty() {
void prependSomeAndEmpty() {
Integer[] result = prepend(1, empty);
assertArrayEquals(new Integer[] {1}, result);
}

@Test
public void prependNullAndNonEmpty() {
void prependNullAndNonEmpty() {
Integer[] second = {1, 2};

Integer[] result = prepend(null, second);
Expand All @@ -88,7 +88,7 @@ public void prependNullAndNonEmpty() {
}

@Test
public void prependSomeAndNonEmpty() {
void prependSomeAndNonEmpty() {
Integer[] second = {2, 3};

Integer[] result = prepend(1, second);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2023 Thomas Akehurst
* Copyright (C) 2014-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
Expand All @@ -31,23 +32,21 @@
import java.util.List;
import org.junit.jupiter.api.Test;

public class ClasspathFileSourceTest {
class ClasspathFileSourceTest {

ClasspathFileSource classpathFileSource;

@SuppressWarnings("unchecked")
@Test
public void listsFilesRecursivelyFromJar() {
void listsFilesRecursivelyFromJar() {
initForJar();

List<TextFile> files = classpathFileSource.listFilesRecursively();

assertThat(files, hasItems(fileNamed("pom.properties"), fileNamed("pom.xml")));
}

@SuppressWarnings("unchecked")
@Test
public void listsFilesRecursivelyFromFileSystem() {
void listsFilesRecursivelyFromFileSystem() {
initForFileSystem();

List<TextFile> files = classpathFileSource.listFilesRecursively();
Expand All @@ -64,7 +63,7 @@ public void listsFilesRecursivelyFromFileSystem() {
}

@Test
public void readsBinaryFileFromJar() {
void readsBinaryFileFromJar() {
initForJar();

BinaryFile binaryFile = classpathFileSource.getBinaryFileNamed("guava/pom.xml");
Expand All @@ -73,7 +72,7 @@ public void readsBinaryFileFromJar() {
}

@Test
public void readsBinaryFileFromCustomClassLoader() throws MalformedURLException {
void readsBinaryFileFromCustomClassLoader() throws MalformedURLException {
initForCustomClassLoader();

BinaryFile binaryFile = classpathFileSource.child("__files").getBinaryFileNamed("stuff.txt");
Expand All @@ -82,7 +81,7 @@ public void readsBinaryFileFromCustomClassLoader() throws MalformedURLException
}

@Test
public void readsBinaryFileFromZip() {
void readsBinaryFileFromZip() {
classpathFileSource = new ClasspathFileSource("zippeddir");

BinaryFile binaryFile = classpathFileSource.getBinaryFileNamed("zippedfile.txt");
Expand All @@ -92,7 +91,7 @@ public void readsBinaryFileFromZip() {
}

@Test
public void readsBinaryFileFromZipWithoutMatch() {
void readsBinaryFileFromZipWithoutMatch() {
classpathFileSource = new ClasspathFileSource("zippeddir");
try {
classpathFileSource.getBinaryFileNamed("thisWillNotBeFound.txt");
Expand All @@ -106,7 +105,7 @@ public void readsBinaryFileFromZipWithoutMatch() {
}

@Test
public void readsBinaryFileFromFileSystem() {
void readsBinaryFileFromFileSystem() {
initForFileSystem();

BinaryFile binaryFile = classpathFileSource.getBinaryFileNamed("subdir/deepfile.json");
Expand All @@ -115,7 +114,7 @@ public void readsBinaryFileFromFileSystem() {
}

@Test
public void createsChildSource() {
void createsChildSource() {
initForFileSystem();

FileSource child = classpathFileSource.child("subdir");
Expand All @@ -124,20 +123,23 @@ public void createsChildSource() {
}

@Test
public void correctlyReportsExistence() {
void correctlyReportsExistence() {
assertTrue(new ClasspathFileSource("filesource/subdir").exists(), "Expected to exist");
assertTrue(
new ClasspathFileSource("META-INF/maven/com.google.guava").exists(), "Expected to exist");
assertFalse(new ClasspathFileSource("not/exist").exists(), "Expected not to exist");
}

@Test
public void failsSilentlyOnWrites() {
initForFileSystem();
classpathFileSource.deleteFile("one");
classpathFileSource.writeBinaryFile("any-bytes", new byte[] {});
classpathFileSource.writeTextFile("any-text", "things");
classpathFileSource.createIfNecessary();
void failsSilentlyOnWrites() {
assertDoesNotThrow(
() -> {
initForFileSystem();
classpathFileSource.deleteFile("one");
classpathFileSource.writeBinaryFile("any-bytes", new byte[] {});
classpathFileSource.writeTextFile("any-text", "things");
classpathFileSource.createIfNecessary();
});
}

private void initForJar() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016-2022 Thomas Akehurst
* Copyright (C) 2016-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,10 +23,10 @@
import com.github.tomakehurst.wiremock.http.ContentTypeHeader;
import org.junit.jupiter.api.Test;

public class ContentTypesTest {
class ContentTypesTest {

@Test
public void detectsTextTypesCorrectlyFromFileExtension() {
void detectsTextTypesCorrectlyFromFileExtension() {
assertTrue(ContentTypes.determineIsTextFromExtension("txt"));
assertTrue(ContentTypes.determineIsTextFromExtension("json"));
assertTrue(ContentTypes.determineIsTextFromExtension("xml"));
Expand All @@ -42,7 +42,7 @@ public void detectsTextTypesCorrectlyFromFileExtension() {
}

@Test
public void detectsTextTypesCorrectlyFromMimeType() {
void detectsTextTypesCorrectlyFromMimeType() {
assertTrue(ContentTypes.determineIsTextFromMimeType("text/plain"));
assertTrue(ContentTypes.determineIsTextFromMimeType("text/html"));
assertTrue(ContentTypes.determineIsTextFromMimeType("application/json"));
Expand All @@ -60,7 +60,7 @@ public void detectsTextTypesCorrectlyFromMimeType() {
}

@Test
public void detectsTextTypesCorrectlyFromExtensionOrMimeType() {
void detectsTextTypesCorrectlyFromExtensionOrMimeType() {
assertTrue(ContentTypes.determineIsText("txt", "text/plain"));
assertTrue(ContentTypes.determineIsText("xml", ""));
assertTrue(ContentTypes.determineIsText("json", null));
Expand All @@ -70,7 +70,7 @@ public void detectsTextTypesCorrectlyFromExtensionOrMimeType() {
}

@Test
public void correctlyDeterminesFileExtensionWhenDotsInPath() {
void correctlyDeterminesFileExtensionWhenDotsInPath() {
String fileExtension =
ContentTypes.determineFileExtension(
"http://some.host/path.with.dots/and/several/segments",
Expand All @@ -81,7 +81,7 @@ public void correctlyDeterminesFileExtensionWhenDotsInPath() {
}

@Test
public void correctlyDeterminesFileExtensionFromUrl() {
void correctlyDeterminesFileExtensionFromUrl() {
String fileExtension =
ContentTypes.determineFileExtension(
"http://some.host/path.with.dots/image.png", ContentTypeHeader.absent(), new byte[] {});
Expand Down