From ffa4dbb40f4ade50a0aaef345e232afb15d9ed4d Mon Sep 17 00:00:00 2001 From: Kirill Peshin Date: Thu, 18 Apr 2024 20:56:18 +0300 Subject: [PATCH] Fix some Sonar or/and "IDEA inspect code" issues (partly) --- .../wiremock/matching/MatchResult.java | 3 +- .../diff/JUnitStyleDiffRenderer.java | 4 +- .../diff/PlainTextDiffRenderer.java | 2 +- .../wiremock/common/ArrayFunctionsTest.java | 20 +++++----- .../common/ClasspathFileSourceTest.java | 40 ++++++++++--------- .../wiremock/common/ContentTypesTest.java | 14 +++---- .../wiremock/common/DateTimeOffsetTest.java | 32 +++++++-------- .../wiremock/common/DateTimeParserTest.java | 16 ++++---- .../common/DateTimeTruncationTest.java | 26 ++++++------ .../wiremock/common/DatesTest.java | 4 +- .../wiremock/common/FilenameMakerTest.java | 20 +++++----- .../wiremock/common/JettySettingsTest.java | 8 ++-- .../wiremock/common/url/PathTemplateTest.java | 36 ++++++++--------- .../wiremock/common/xml/XmlTest.java | 18 ++++----- .../wiremock/verification/diff/DiffTest.java | 2 +- 15 files changed, 124 insertions(+), 121 deletions(-) diff --git a/src/main/java/com/github/tomakehurst/wiremock/matching/MatchResult.java b/src/main/java/com/github/tomakehurst/wiremock/matching/MatchResult.java index 98a7576490..995913e296 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/matching/MatchResult.java +++ b/src/main/java/com/github/tomakehurst/wiremock/matching/MatchResult.java @@ -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 { @@ -111,6 +112,6 @@ public int compareTo(MatchResult other) { return Double.compare(other.getDistance(), getDistance()); } - public static final java.util.function.Predicate ARE_EXACT_MATCH = + public static final Predicate ARE_EXACT_MATCH = WeightedMatchResult::isExactMatch; } diff --git a/src/main/java/com/github/tomakehurst/wiremock/verification/diff/JUnitStyleDiffRenderer.java b/src/main/java/com/github/tomakehurst/wiremock/verification/diff/JUnitStyleDiffRenderer.java index 7d2beb6916..8f2dda0c6c 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/verification/diff/JUnitStyleDiffRenderer.java +++ b/src/main/java/com/github/tomakehurst/wiremock/verification/diff/JUnitStyleDiffRenderer.java @@ -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. @@ -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())); } diff --git a/src/main/java/com/github/tomakehurst/wiremock/verification/diff/PlainTextDiffRenderer.java b/src/main/java/com/github/tomakehurst/wiremock/verification/diff/PlainTextDiffRenderer.java index d1cf796f2a..2b70d8fc5b 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/verification/diff/PlainTextDiffRenderer.java +++ b/src/main/java/com/github/tomakehurst/wiremock/verification/diff/PlainTextDiffRenderer.java @@ -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(" "); diff --git a/src/test/java/com/github/tomakehurst/wiremock/common/ArrayFunctionsTest.java b/src/test/java/com/github/tomakehurst/wiremock/common/ArrayFunctionsTest.java index 1a87d7c1e2..117e73a206 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/common/ArrayFunctionsTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/common/ArrayFunctionsTest.java @@ -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. @@ -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); @@ -42,7 +42,7 @@ public void concatNonEmptyAndEmpty() { } @Test - public void concatEmptyAndNonEmpty() { + void concatEmptyAndNonEmpty() { Integer[] second = {1, 2}; Integer[] result = concat(empty, second); @@ -53,7 +53,7 @@ public void concatEmptyAndNonEmpty() { } @Test - public void concatNonEmptyAndNonEmpty() { + void concatNonEmptyAndNonEmpty() { Integer[] first = {1, 2}; Integer[] second = {3, 4}; @@ -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); @@ -88,7 +88,7 @@ public void prependNullAndNonEmpty() { } @Test - public void prependSomeAndNonEmpty() { + void prependSomeAndNonEmpty() { Integer[] second = {2, 3}; Integer[] result = prepend(1, second); diff --git a/src/test/java/com/github/tomakehurst/wiremock/common/ClasspathFileSourceTest.java b/src/test/java/com/github/tomakehurst/wiremock/common/ClasspathFileSourceTest.java index 4dea08fe13..ed916b5faa 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/common/ClasspathFileSourceTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/common/ClasspathFileSourceTest.java @@ -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. @@ -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; @@ -31,13 +32,12 @@ 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 files = classpathFileSource.listFilesRecursively(); @@ -45,9 +45,8 @@ public void listsFilesRecursivelyFromJar() { assertThat(files, hasItems(fileNamed("pom.properties"), fileNamed("pom.xml"))); } - @SuppressWarnings("unchecked") @Test - public void listsFilesRecursivelyFromFileSystem() { + void listsFilesRecursivelyFromFileSystem() { initForFileSystem(); List files = classpathFileSource.listFilesRecursively(); @@ -64,7 +63,7 @@ public void listsFilesRecursivelyFromFileSystem() { } @Test - public void readsBinaryFileFromJar() { + void readsBinaryFileFromJar() { initForJar(); BinaryFile binaryFile = classpathFileSource.getBinaryFileNamed("guava/pom.xml"); @@ -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"); @@ -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"); @@ -92,7 +91,7 @@ public void readsBinaryFileFromZip() { } @Test - public void readsBinaryFileFromZipWithoutMatch() { + void readsBinaryFileFromZipWithoutMatch() { classpathFileSource = new ClasspathFileSource("zippeddir"); try { classpathFileSource.getBinaryFileNamed("thisWillNotBeFound.txt"); @@ -106,7 +105,7 @@ public void readsBinaryFileFromZipWithoutMatch() { } @Test - public void readsBinaryFileFromFileSystem() { + void readsBinaryFileFromFileSystem() { initForFileSystem(); BinaryFile binaryFile = classpathFileSource.getBinaryFileNamed("subdir/deepfile.json"); @@ -115,7 +114,7 @@ public void readsBinaryFileFromFileSystem() { } @Test - public void createsChildSource() { + void createsChildSource() { initForFileSystem(); FileSource child = classpathFileSource.child("subdir"); @@ -124,7 +123,7 @@ 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"); @@ -132,12 +131,15 @@ public void correctlyReportsExistence() { } @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() { diff --git a/src/test/java/com/github/tomakehurst/wiremock/common/ContentTypesTest.java b/src/test/java/com/github/tomakehurst/wiremock/common/ContentTypesTest.java index a98fec5f1b..39b858f7a6 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/common/ContentTypesTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/common/ContentTypesTest.java @@ -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. @@ -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")); @@ -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")); @@ -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)); @@ -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", @@ -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[] {}); diff --git a/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeOffsetTest.java b/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeOffsetTest.java index 5c8797ca18..46453a5ed6 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeOffsetTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeOffsetTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Thomas Akehurst + * Copyright (C) 2018-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. @@ -25,78 +25,78 @@ import java.util.Date; import org.junit.jupiter.api.Test; -public class DateTimeOffsetTest { +class DateTimeOffsetTest { @Test - public void parsesSecondsOffset() { + void parsesSecondsOffset() { DateTimeOffset offset = DateTimeOffset.fromString("7 seconds"); assertThat(offset.getAmountUnit(), is(DateTimeUnit.SECONDS)); assertThat(offset.getAmount(), is(7)); } @Test - public void parsesMinutesOffset() { + void parsesMinutesOffset() { DateTimeOffset offset = DateTimeOffset.fromString("78 minutes"); assertThat(offset.getAmountUnit(), is(DateTimeUnit.MINUTES)); assertThat(offset.getAmount(), is(78)); } @Test - public void parsesHoursOffset() { + void parsesHoursOffset() { DateTimeOffset offset = DateTimeOffset.fromString("-12 hours"); assertThat(offset.getAmountUnit(), is(DateTimeUnit.HOURS)); assertThat(offset.getAmount(), is(-12)); } @Test - public void parsesDaysOffset() { + void parsesDaysOffset() { DateTimeOffset offset = DateTimeOffset.fromString("1 days"); assertThat(offset.getAmountUnit(), is(DateTimeUnit.DAYS)); assertThat(offset.getAmount(), is(1)); } @Test - public void parsesMonthsOffset() { + void parsesMonthsOffset() { DateTimeOffset offset = DateTimeOffset.fromString("-12 months"); assertThat(offset.getAmountUnit(), is(DateTimeUnit.MONTHS)); assertThat(offset.getAmount(), is(-12)); } @Test - public void parsesYearsOffset() { + void parsesYearsOffset() { DateTimeOffset offset = DateTimeOffset.fromString("101 years"); assertThat(offset.getAmountUnit(), is(DateTimeUnit.YEARS)); assertThat(offset.getAmount(), is(101)); } @Test - public void parsesPositiveLongForm() { + void parsesPositiveLongForm() { DateTimeOffset offset = DateTimeOffset.fromString("now +101 years"); assertThat(offset.getAmountUnit(), is(DateTimeUnit.YEARS)); assertThat(offset.getAmount(), is(101)); } @Test - public void parsesNegativeLongForm() { + void parsesNegativeLongForm() { DateTimeOffset offset = DateTimeOffset.fromString("now -5 months"); assertThat(offset.getAmountUnit(), is(DateTimeUnit.MONTHS)); assertThat(offset.getAmount(), is(-5)); } @Test - public void returnsCorrectToString() { + void returnsCorrectToString() { assertThat(DateTimeOffset.fromString("123 minutes").toString(), is("123 minutes")); assertThat(DateTimeOffset.fromString("-72 hours").toString(), is("-72 hours")); } @Test - public void canBeConstructedFromParts() { + void canBeConstructedFromParts() { assertThat(new DateTimeOffset(67, DateTimeUnit.DAYS).toString(), is("67 days")); assertThat(new DateTimeOffset(-12, DateTimeUnit.SECONDS).toString(), is("-12 seconds")); } @Test - public void shiftsZonedDateTimes() { + void shiftsZonedDateTimes() { DateTimeOffset positiveDateOffset = new DateTimeOffset(10, DateTimeUnit.DAYS); assertThat( positiveDateOffset.shift(ZonedDateTime.parse("2021-06-18T00:00:00Z")), @@ -109,7 +109,7 @@ public void shiftsZonedDateTimes() { } @Test - public void offsetsProvidedDateByConfiguredAmount() throws Exception { + void offsetsProvidedDateByConfiguredAmount() { DateTimeOffset offset = DateTimeOffset.fromString("3 days"); Date startingDate = Date.from(ZonedDateTime.parse("2018-04-16T12:01:01Z").toInstant()); Date finalDate = offset.shift(startingDate); @@ -120,12 +120,12 @@ public void offsetsProvidedDateByConfiguredAmount() throws Exception { } @Test - public void throwsExceptionWhenUnparseableStringProvided() { + void throwsExceptionWhenUnparseableStringProvided() { assertThrows(IllegalArgumentException.class, () -> DateTimeOffset.fromString("101")); } @Test - public void throwsExceptionWhenUnparseableUnitProvided() { + void throwsExceptionWhenUnparseableUnitProvided() { assertThrows(IllegalArgumentException.class, () -> DateTimeOffset.fromString("101 squillions")); } } diff --git a/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeParserTest.java b/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeParserTest.java index 5ff47d06bc..ef2f70a903 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeParserTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Thomas Akehurst + * Copyright (C) 2021-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. @@ -24,10 +24,10 @@ import java.time.format.DateTimeFormatter; import org.junit.jupiter.api.Test; -public class DateTimeParserTest { +class DateTimeParserTest { @Test - public void parsesFromDateTimeFormatter() { + void parsesFromDateTimeFormatter() { DateTimeParser parser = DateTimeParser.forFormatter(DateTimeFormatter.ISO_DATE_TIME); assertThat( parser.parseZonedDateTime("2021-06-23T11:12:13Z"), @@ -39,7 +39,7 @@ public void parsesFromDateTimeFormatter() { } @Test - public void parsesZonedFromFormatString() { + void parsesZonedFromFormatString() { DateTimeParser parser = DateTimeParser.forFormat("dd/MM/yyyy HH:mm:ss Z"); assertThat( parser.parseZonedDateTime("23/06/2021 11:22:33 +0000"), @@ -47,7 +47,7 @@ public void parsesZonedFromFormatString() { } @Test - public void parsesLocalDateTimeFromFormatString() { + void parsesLocalDateTimeFromFormatString() { DateTimeParser parser = DateTimeParser.forFormat("dd/MM/yyyy HH:mm:ss"); assertThat( parser.parseLocalDateTime("23/06/2021 11:12:13"), @@ -55,13 +55,13 @@ public void parsesLocalDateTimeFromFormatString() { } @Test - public void parsesLocalDateFromFormatString() { + void parsesLocalDateFromFormatString() { DateTimeParser parser = DateTimeParser.forFormat("dd/MM/yyyy"); assertThat(parser.parseLocalDate("23/06/2021"), is(LocalDate.parse("2021-06-23"))); } @Test - public void parsesUnix() { + void parsesUnix() { DateTimeParser parser = DateTimeParser.forFormat("unix"); assertThat( parser.parseZonedDateTime("1624447353"), is(ZonedDateTime.parse("2021-06-23T11:22:33Z"))); @@ -71,7 +71,7 @@ public void parsesUnix() { } @Test - public void parsesEpoch() { + void parsesEpoch() { DateTimeParser parser = DateTimeParser.forFormat("epoch"); assertThat( parser.parseZonedDateTime("1624447353000"), diff --git a/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeTruncationTest.java b/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeTruncationTest.java index ea2bc01d29..b4e00f7c9b 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeTruncationTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/common/DateTimeTruncationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Thomas Akehurst + * Copyright (C) 2021-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. @@ -21,79 +21,79 @@ import java.time.ZonedDateTime; import org.junit.jupiter.api.Test; -public class DateTimeTruncationTest { +class DateTimeTruncationTest { @Test - public void firstSecondOfMinute() { + void firstSecondOfMinute() { ZonedDateTime input = ZonedDateTime.parse("2021-06-18T10:11:12Z"); ZonedDateTime output = DateTimeTruncation.FIRST_SECOND_OF_MINUTE.truncate(input); assertThat(output, is(ZonedDateTime.parse("2021-06-18T10:11:00Z"))); } @Test - public void firstMinuteOfHour() { + void firstMinuteOfHour() { ZonedDateTime input = ZonedDateTime.parse("2021-06-18T10:11:12Z"); ZonedDateTime output = DateTimeTruncation.FIRST_MINUTE_OF_HOUR.truncate(input); assertThat(output, is(ZonedDateTime.parse("2021-06-18T10:00:00Z"))); } @Test - public void firstHourOfDay() { + void firstHourOfDay() { ZonedDateTime input = ZonedDateTime.parse("2021-06-18T10:11:12Z"); ZonedDateTime output = DateTimeTruncation.FIRST_HOUR_OF_DAY.truncate(input); assertThat(output, is(ZonedDateTime.parse("2021-06-18T00:00:00Z"))); } @Test - public void firstDayOfMonth() { + void firstDayOfMonth() { ZonedDateTime input = ZonedDateTime.parse("2021-06-18T10:11:12Z"); ZonedDateTime output = DateTimeTruncation.FIRST_DAY_OF_MONTH.truncate(input); assertThat(output, is(ZonedDateTime.parse("2021-06-01T00:00:00Z"))); } @Test - public void firstDayOfNextMonth() { + void firstDayOfNextMonth() { ZonedDateTime input = ZonedDateTime.parse("2021-06-18T10:11:12Z"); ZonedDateTime output = DateTimeTruncation.FIRST_DAY_OF_NEXT_MONTH.truncate(input); assertThat(output, is(ZonedDateTime.parse("2021-07-01T00:00:00Z"))); } @Test - public void lastDayOfMonth() { + void lastDayOfMonth() { ZonedDateTime input = ZonedDateTime.parse("2021-06-18T10:11:12Z"); ZonedDateTime output = DateTimeTruncation.LAST_DAY_OF_MONTH.truncate(input); assertThat(output, is(ZonedDateTime.parse("2021-06-30T00:00:00Z"))); } @Test - public void firstDayOfYear() { + void firstDayOfYear() { ZonedDateTime input = ZonedDateTime.parse("2021-06-18T10:11:12Z"); ZonedDateTime output = DateTimeTruncation.FIRST_DAY_OF_YEAR.truncate(input); assertThat(output, is(ZonedDateTime.parse("2021-01-01T00:00:00Z"))); } @Test - public void firstDayOfNextYear() { + void firstDayOfNextYear() { ZonedDateTime input = ZonedDateTime.parse("2021-06-18T10:11:12Z"); ZonedDateTime output = DateTimeTruncation.FIRST_DAY_OF_NEXT_YEAR.truncate(input); assertThat(output, is(ZonedDateTime.parse("2022-01-01T00:00:00Z"))); } @Test - public void lastDayOfYear() { + void lastDayOfYear() { ZonedDateTime input = ZonedDateTime.parse("2021-06-18T10:11:12Z"); ZonedDateTime output = DateTimeTruncation.LAST_DAY_OF_YEAR.truncate(input); assertThat(output, is(ZonedDateTime.parse("2021-12-31T00:00:00Z"))); } @Test - public void parsesFromFriendlyString() { + void parsesFromFriendlyString() { assertThat( DateTimeTruncation.fromString("last day of year"), is(DateTimeTruncation.LAST_DAY_OF_YEAR)); } @Test - public void toStringReturnsFriendlyString() { + void toStringReturnsFriendlyString() { assertThat(DateTimeTruncation.FIRST_DAY_OF_MONTH.toString(), is("first day of month")); } } diff --git a/src/test/java/com/github/tomakehurst/wiremock/common/DatesTest.java b/src/test/java/com/github/tomakehurst/wiremock/common/DatesTest.java index 4daadcd0ff..73b4febb1e 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/common/DatesTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/common/DatesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Thomas Akehurst + * Copyright (C) 2023-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. @@ -25,7 +25,7 @@ import java.util.Date; import org.junit.jupiter.api.Test; -public class DatesTest { +class DatesTest { @Test void mapsValidInputAsDate() { diff --git a/src/test/java/com/github/tomakehurst/wiremock/common/FilenameMakerTest.java b/src/test/java/com/github/tomakehurst/wiremock/common/FilenameMakerTest.java index 873d21ed1f..8509cece3e 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/common/FilenameMakerTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/common/FilenameMakerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Thomas Akehurst + * Copyright (C) 2023-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. @@ -26,7 +26,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class FilenameMakerTest { +class FilenameMakerTest { private FilenameMaker filenameMaker; @@ -36,7 +36,7 @@ public void init() { } @Test - public void generatesNameFromStubNameWhenPresent() { + void generatesNameFromStubNameWhenPresent() { StubMapping mapping = WireMock.get("/named").withName("This is a NAMED stub").willReturn(ok()).build(); @@ -46,7 +46,7 @@ public void generatesNameFromStubNameWhenPresent() { } @Test - public void generatesNameFromStubUrlWhenNameNotPresent() { + void generatesNameFromStubUrlWhenNameNotPresent() { FilenameMaker makerWithOwnFormat = new FilenameMaker("{{{method}}}-{{{url}}}.json"); StubMapping mapping = WireMock.get(urlEqualTo("/named/123/things")).willReturn(ok()).build(); @@ -54,7 +54,7 @@ public void generatesNameFromStubUrlWhenNameNotPresent() { } @Test - public void generatesNameFromStubUrlPathWhenNameNotPresent() { + void generatesNameFromStubUrlPathWhenNameNotPresent() { FilenameMaker makerWithOwnFormat = new FilenameMaker("{{{method}}}-{{{url}}}.json"); StubMapping mapping = WireMock.get(urlPathEqualTo("/named/123/things")).willReturn(ok()).build(); @@ -63,7 +63,7 @@ public void generatesNameFromStubUrlPathWhenNameNotPresent() { } @Test - public void generatesNameFromStubUrlPathTemplateWhenNameNotPresent() { + void generatesNameFromStubUrlPathTemplateWhenNameNotPresent() { FilenameMaker makerWithOwnFormat = new FilenameMaker("{{{method}}}-{{{url}}}.json"); StubMapping mapping = WireMock.get(urlPathTemplate("/named/{id}/things")).willReturn(ok()).build(); @@ -72,7 +72,7 @@ public void generatesNameFromStubUrlPathTemplateWhenNameNotPresent() { } @Test - public void generatesNameFromStubUrlPatternWhenNameNotPresent() { + void generatesNameFromStubUrlPatternWhenNameNotPresent() { FilenameMaker makerWithOwnFormat = new FilenameMaker("{{{method}}}-{{{url}}}.json"); StubMapping mapping = WireMock.get(urlMatching("/named/([0-9]*)/things")).willReturn(ok()).build(); @@ -81,7 +81,7 @@ public void generatesNameFromStubUrlPatternWhenNameNotPresent() { } @Test - public void generatesNameWhenStubUrlIsAnyAndNameNotPresent() { + void generatesNameWhenStubUrlIsAnyAndNameNotPresent() { StubMapping mapping = WireMock.get(anyUrl()).willReturn(ok()).build(); FilenameMaker makerWithOwnFormat = new FilenameMaker("{{{id}}}.json"); @@ -90,7 +90,7 @@ public void generatesNameWhenStubUrlIsAnyAndNameNotPresent() { } @Test - public void sanitizesUrlWithCharactersSafeForFilenames() { + void sanitizesUrlWithCharactersSafeForFilenames() { String output = filenameMaker.sanitizeUrl("/hello/1/2/3__!/ẮČĖ--ace/¥$$/$/and/¿?"); assertThat(output, is("hello_1_2_3___ace--ace___and")); } @@ -104,7 +104,7 @@ void generatesSanitizedFilename() { } @Test - public void truncatesWhenResultingNameOver200Chars() { + void truncatesWhenResultingNameOver200Chars() { String output = filenameMaker.sanitizeUrl( "/hello/1/2/3__!/ẮČĖ--ace/¥$$/$/andverylongstuffandverylongstuffandverylongstuffandverylongstuffandverylongstuffandverylongstuffandverylongstuffandverylongstuffandverylongstuffandverylongstuffandverylongstuffandverylongstuffandverylongstuff/¿?"); diff --git a/src/test/java/com/github/tomakehurst/wiremock/common/JettySettingsTest.java b/src/test/java/com/github/tomakehurst/wiremock/common/JettySettingsTest.java index 53463f155a..bca8694ab5 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/common/JettySettingsTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/common/JettySettingsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2023 Thomas Akehurst + * Copyright (C) 2015-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. @@ -20,13 +20,13 @@ import java.util.Optional; import org.junit.jupiter.api.Test; -public class JettySettingsTest { +class JettySettingsTest { private static final int number = 1234; private static final long longNumber = Long.MAX_VALUE; @Test - public void testBuilderWithValues() { + void testBuilderWithValues() { JettySettings.Builder builder = JettySettings.Builder.aJettySettings(); builder .withAcceptors(number) @@ -47,7 +47,7 @@ public void testBuilderWithValues() { } @Test - public void testBuilderWithNoValues() { + void testBuilderWithNoValues() { JettySettings.Builder builder = JettySettings.Builder.aJettySettings(); JettySettings jettySettings = builder.build(); diff --git a/src/test/java/com/github/tomakehurst/wiremock/common/url/PathTemplateTest.java b/src/test/java/com/github/tomakehurst/wiremock/common/url/PathTemplateTest.java index ed7f45b65d..ae6fee3b06 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/common/url/PathTemplateTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/common/url/PathTemplateTest.java @@ -29,10 +29,10 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; -public class PathTemplateTest { +class PathTemplateTest { @Test - public void extractsSinglePathParameter() { + void extractsSinglePathParameter() { PathTemplate template = new PathTemplate("/things/{id}"); PathParams pathParams = template.parse("/things/11-22-33"); @@ -41,7 +41,7 @@ public void extractsSinglePathParameter() { } @Test - public void throwsIllegalArgumentExceptionIfAttemptingParsingOnNonMatchingUrl() { + void throwsIllegalArgumentExceptionIfAttemptingParsingOnNonMatchingUrl() { assertThrows( IllegalArgumentException.class, () -> { @@ -51,28 +51,28 @@ public void throwsIllegalArgumentExceptionIfAttemptingParsingOnNonMatchingUrl() } @Test - public void matchesWhenUrlIsEquivalentToTemplate() { + void matchesWhenUrlIsEquivalentToTemplate() { PathTemplate template = new PathTemplate("/things/{id}/otherthings/{subId}"); assertThat(template.matches("/things/11-22-33/otherthings/12378"), is(true)); } @Test - public void nonMatchWhenUrlIsShorterThanTemplate() { + void nonMatchWhenUrlIsShorterThanTemplate() { PathTemplate template = new PathTemplate("/things/{id}/otherthings/{subId}"); assertThat(template.matches("/things/11-22-33/otherthings"), is(false)); } @Test - public void nonMatchWhenUrlPartIsMismatch() { + void nonMatchWhenUrlPartIsMismatch() { PathTemplate template = new PathTemplate("/things/{id}/otherthings/{subId}"); assertThat(template.matches("/things/11-22-33/other-stuff/1234"), is(false)); } @Test - public void rendersWithParameters() { + void rendersWithParameters() { PathTemplate template = new PathTemplate("/things/{id}/otherthings/{subId}"); PathParams pathParams = new PathParams().add("id", "123").add("subId", "456"); @@ -82,7 +82,7 @@ public void rendersWithParameters() { } @Test - public void rendersWithoutParameters() { + void rendersWithoutParameters() { PathTemplate template = new PathTemplate("/things/stuff"); String path = template.render(PathParams.empty()); @@ -91,7 +91,7 @@ public void rendersWithoutParameters() { } @Test - public void throwsErrorWhenNotAllParametersAreBound() { + void throwsErrorWhenNotAllParametersAreBound() { assertThrows( IllegalArgumentException.class, () -> { @@ -101,7 +101,7 @@ public void throwsErrorWhenNotAllParametersAreBound() { } @Test - public void parseWithWildcardAndOneDepthPath() { + void parseWithWildcardAndOneDepthPath() { PathTemplate template = new PathTemplate("/things/**"); PathParams pathParams = template.parse("/things/stuff"); @@ -110,7 +110,7 @@ public void parseWithWildcardAndOneDepthPath() { } @Test - public void parseWithWildcardAndTwoDepthPath() { + void parseWithWildcardAndTwoDepthPath() { PathTemplate template = new PathTemplate("/things/**"); PathParams pathParams = template.parse("/things/foo/bar"); @@ -119,7 +119,7 @@ public void parseWithWildcardAndTwoDepthPath() { } @Test - public void parseWithVariableAndWildcardAndTwoDepthPath() { + void parseWithVariableAndWildcardAndTwoDepthPath() { PathTemplate template = new PathTemplate("/things/{id}/**"); PathParams pathParams = template.parse("/things/foo/bar"); @@ -129,7 +129,7 @@ public void parseWithVariableAndWildcardAndTwoDepthPath() { } @Test - public void renderWithWildcardAndOneDepth() { + void renderWithWildcardAndOneDepth() { PathTemplate template = new PathTemplate("/things/**"); PathParams pathParams = new PathParams().add("0", "stuff"); @@ -139,7 +139,7 @@ public void renderWithWildcardAndOneDepth() { } @Test - public void renderWithWildcardAndTwoDepth() { + void renderWithWildcardAndTwoDepth() { PathTemplate template = new PathTemplate("/things/**"); PathParams pathParams = new PathParams().add("0", "foo/bar"); @@ -149,7 +149,7 @@ public void renderWithWildcardAndTwoDepth() { } @Test - public void renderWithVariableAndWildcardAndTwoDepthPath() { + void renderWithVariableAndWildcardAndTwoDepthPath() { PathTemplate template = new PathTemplate("/things/{id}/**"); PathParams pathParams = new PathParams().add("id", "foo").add("0", "bar"); @@ -159,7 +159,7 @@ public void renderWithVariableAndWildcardAndTwoDepthPath() { } @Test - public void throwsErrorWhenNotWildcardParameterIsNotBound() { + void throwsErrorWhenNotWildcardParameterIsNotBound() { assertThrows( IllegalArgumentException.class, () -> { @@ -169,7 +169,7 @@ public void throwsErrorWhenNotWildcardParameterIsNotBound() { } @Test - public void checkHashAndEquality() { + void checkHashAndEquality() { List templates = asList( "/things", @@ -191,7 +191,7 @@ public void checkHashAndEquality() { } @Test - public void checkEquality() { + void checkEquality() { List templates = asList( "/things", diff --git a/src/test/java/com/github/tomakehurst/wiremock/common/xml/XmlTest.java b/src/test/java/com/github/tomakehurst/wiremock/common/xml/XmlTest.java index 68004a69ad..726f7c1a76 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/common/xml/XmlTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/common/xml/XmlTest.java @@ -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. @@ -24,10 +24,10 @@ import org.junit.jupiter.api.condition.DisabledForJreRange; import org.junit.jupiter.api.condition.JRE; -public class XmlTest { +class XmlTest { @Test - public void findsSimpleXmlNodesByXPath() { + void findsSimpleXmlNodesByXPath() { String xml = "\n" + "\n" @@ -45,7 +45,7 @@ public void findsSimpleXmlNodesByXPath() { } @Test - public void findsNamespacedXmlNodeByXPath() { + void findsNamespacedXmlNodeByXPath() { String xml = "\n" + "\n" @@ -66,7 +66,7 @@ public void findsNamespacedXmlNodeByXPath() { } @Test - public void prettyPrintsDocument() { + void prettyPrintsDocument() { String xml = ""; XmlDocument xmlDocument = Xml.parse(xml); @@ -78,7 +78,7 @@ public void prettyPrintsDocument() { } @Test - public void prettyPrintsNodeAttributeValue() { + void prettyPrintsNodeAttributeValue() { String xml = ""; XmlDocument xmlDocument = Xml.parse(xml); @@ -88,7 +88,7 @@ public void prettyPrintsNodeAttributeValue() { } @Test - public void prettyPrintsNodeTextValue() { + void prettyPrintsNodeTextValue() { String xml = "2"; XmlDocument xmlDocument = Xml.parse(xml); @@ -98,7 +98,7 @@ public void prettyPrintsNodeTextValue() { } @Test - public void prettyPrintsNodeXml() { + void prettyPrintsNodeXml() { String xml = ""; XmlDocument xmlDocument = Xml.parse(xml); @@ -115,7 +115,7 @@ public void prettyPrintsNodeXml() { disabledReason = "SaxSource unavailable to parse undeclared namespace prefix, due to " + "IllegalAccessException: class com.github.tomakehurst.wiremock.common.xml.XmlNode cannot access class com.sun.org.apache.xalan.internal.xsltc.trax.DOM2SAX (in module java.xml) because module java.xml does not export com.sun.org.apache.xalan.internal.xsltc.trax to unnamed module @2892dae4") - public void printsNamespacedXmlWhenPrefixDeclarationNotInScope() { + void printsNamespacedXmlWhenPrefixDeclarationNotInScope() { String xml = "\n" + "\n" diff --git a/src/test/java/com/github/tomakehurst/wiremock/verification/diff/DiffTest.java b/src/test/java/com/github/tomakehurst/wiremock/verification/diff/DiffTest.java index d1a3497554..3e1c404ac1 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/verification/diff/DiffTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/verification/diff/DiffTest.java @@ -36,7 +36,7 @@ class DiffTest { void correctlyRendersJUnitStyleDiffMessage() { String diff = junitStyleDiffMessage("expected", "actual"); - assertThat(diff, is(" expected:<\nexpected> but was:<\nactual>")); + assertThat(diff, is(String.format(" expected:<%nexpected> but was:<%nactual>"))); } @Test