diff --git a/src/test/java/com/github/packageurl/PackageURLBuilderTest.java b/src/test/java/com/github/packageurl/PackageURLBuilderTest.java index 4dda8a9..887972d 100644 --- a/src/test/java/com/github/packageurl/PackageURLBuilderTest.java +++ b/src/test/java/com/github/packageurl/PackageURLBuilderTest.java @@ -72,7 +72,7 @@ void packageURLBuilder( builder.withSubpath(subpath); } if (invalid) { - assertThrows(MalformedPackageURLException.class, builder::build); + assertThrows(MalformedPackageURLException.class, builder::build, "Build should fail due to " + description); } else { assertEquals(parameters.getType(), builder.getType(), "type"); assertEquals(parameters.getNamespace(), builder.getNamespace(), "namespace"); @@ -109,13 +109,11 @@ void packageURLBuilderException1Null() throws MalformedPackageURLException { void packageURLBuilderException2() { assertThrowsExactly( MalformedPackageURLException.class, - () -> { - PackageURLBuilder.aPackageURL() - .withType("type") - .withNamespace("invalid//namespace") - .withName("name") - .build(); - }, + () -> PackageURLBuilder.aPackageURL() + .withType("type") + .withNamespace("invalid//namespace") + .withName("name") + .build(), "Build should fail due to invalid namespace"); } @@ -123,13 +121,11 @@ void packageURLBuilderException2() { void packageURLBuilderException3() { assertThrowsExactly( MalformedPackageURLException.class, - () -> { - PackageURLBuilder.aPackageURL() - .withType("typ^e") - .withSubpath("invalid/name%2Fspace") - .withName("name") - .build(); - }, + () -> PackageURLBuilder.aPackageURL() + .withType("typ^e") + .withSubpath("invalid/name%2Fspace") + .withName("name") + .build(), "Build should fail due to invalid subpath"); } @@ -137,12 +133,10 @@ void packageURLBuilderException3() { void packageURLBuilderException4() { assertThrowsExactly( MalformedPackageURLException.class, - () -> { - PackageURLBuilder.aPackageURL() - .withType("0_type") - .withName("name") - .build(); - }, + () -> PackageURLBuilder.aPackageURL() + .withType("0_type") + .withName("name") + .build(), "Build should fail due to invalid type"); } @@ -150,13 +144,11 @@ void packageURLBuilderException4() { void packageURLBuilderException5() { assertThrowsExactly( MalformedPackageURLException.class, - () -> { - PackageURLBuilder.aPackageURL() - .withType("ype") - .withName("name") - .withQualifier("0_key", "value") - .build(); - }, + () -> PackageURLBuilder.aPackageURL() + .withType("ype") + .withName("name") + .withQualifier("0_key", "value") + .build(), "Build should fail due to invalid qualifier key"); } @@ -164,13 +156,11 @@ void packageURLBuilderException5() { void packageURLBuilderException6() { assertThrowsExactly( MalformedPackageURLException.class, - () -> { - PackageURLBuilder.aPackageURL() - .withType("ype") - .withName("name") - .withQualifier("", "value") - .build(); - }, + () -> PackageURLBuilder.aPackageURL() + .withType("ype") + .withName("name") + .withQualifier("", "value") + .build(), "Build should fail due to invalid qualifier key"); } diff --git a/src/test/java/com/github/packageurl/PackageURLTest.java b/src/test/java/com/github/packageurl/PackageURLTest.java index 5577773..71d42ea 100644 --- a/src/test/java/com/github/packageurl/PackageURLTest.java +++ b/src/test/java/com/github/packageurl/PackageURLTest.java @@ -29,7 +29,6 @@ import java.io.IOException; import java.util.Locale; -import java.util.Map; import java.util.stream.Stream; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterAll; @@ -63,8 +62,7 @@ static void resetLocale() { @Test void validPercentEncoding() throws MalformedPackageURLException { - PackageURL purl = - new PackageURL("maven", "com.google.summit", "summit-ast", "2.2.0\n", (Map) null, null); + PackageURL purl = new PackageURL("maven", "com.google.summit", "summit-ast", "2.2.0\n", null, null); assertEquals("pkg:maven/com.google.summit/summit-ast@2.2.0%0A", purl.toString()); PackageURL purl2 = new PackageURL("pkg:nuget/%D0%9Cicros%D0%BEft.%D0%95ntit%D1%83Fram%D0%B5work%D0%A1%D0%BEr%D0%B5"); @@ -74,7 +72,7 @@ void validPercentEncoding() throws MalformedPackageURLException { } @Test - void invalidPercentEncoding() throws MalformedPackageURLException { + void invalidPercentEncoding() { assertThrowsExactly( MalformedPackageURLException.class, () -> new PackageURL("pkg:maven/com.google.summit/summit-ast@2.2.0%")); @@ -99,7 +97,10 @@ void constructorParsing( boolean invalid) throws Exception { if (invalid) { - assertThrows(getExpectedException(purlString), () -> new PackageURL(purlString)); + assertThrows( + getExpectedException(purlString), + () -> new PackageURL(purlString), + "Build should fail due to " + description); } else { PackageURL purl = new PackageURL(purlString); assertPurlEquals(parameters, purl); @@ -131,7 +132,8 @@ void constructorParameters( parameters.getName(), parameters.getVersion(), parameters.getQualifiers(), - parameters.getSubpath())); + parameters.getSubpath()), + "Build should fail due to " + description); } else { PackageURL purl = new PackageURL( parameters.getType(), diff --git a/src/test/java/com/github/packageurl/internal/StringUtilTest.java b/src/test/java/com/github/packageurl/internal/StringUtilTest.java index cd634f3..cbec577 100644 --- a/src/test/java/com/github/packageurl/internal/StringUtilTest.java +++ b/src/test/java/com/github/packageurl/internal/StringUtilTest.java @@ -24,14 +24,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrowsExactly; -import com.github.packageurl.MalformedPackageURLException; import com.github.packageurl.ValidationException; import org.junit.jupiter.api.Test; -public class StringUtilTest { - +class StringUtilTest { @Test - void invalidPercentEncoding() throws MalformedPackageURLException { + void invalidPercentEncoding() { Throwable t1 = assertThrowsExactly(ValidationException.class, () -> StringUtil.percentDecode("a%0")); assertEquals("Incomplete percent encoding at offset 1 with value '%0'", t1.getMessage()); Throwable t2 = assertThrowsExactly(ValidationException.class, () -> StringUtil.percentDecode("aaaa%%0A"));