Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 25 additions & 35 deletions src/test/java/com/github/packageurl/PackageURLBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -109,68 +109,58 @@ 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");
}

@Test
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");
}

@Test
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");
}

@Test
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");
}

@Test
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");
}

Expand Down
14 changes: 8 additions & 6 deletions src/test/java/com/github/packageurl/PackageURLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String>) null, null);
PackageURL purl = new PackageURL("maven", "com.google.summit", "summit-ast", "2.2.0\n", null, null);
assertEquals("pkg:maven/com.google.summit/[email protected]%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");
Expand All @@ -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/[email protected]%"));
Expand All @@ -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);
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down