-
Notifications
You must be signed in to change notification settings - Fork 19
fix: correct issues with PackageURLTest
#156
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
Merged
jeremylong
merged 3 commits into
package-url:master
from
dwalluck:assert-equals-swap-arguments
Mar 11, 2025
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.TreeMap; | ||
|
|
||
| import org.apache.commons.io.IOUtils; | ||
|
|
@@ -37,7 +38,8 @@ | |
| /** | ||
| * Test cases for PackageURL parsing | ||
| * <p> | ||
| * Original test cases retrieved from: https://raw.githubusercontent.com/package-url/purl-spec/master/test-suite-data.json | ||
| * Original test cases retrieved from: | ||
| * <a href="https://raw.githubusercontent.com/package-url/purl-spec/master/test-suite-data.json">https://raw.githubusercontent.com/package-url/purl-spec/master/test-suite-data.json</a> | ||
| * | ||
| * @author Steve Springett | ||
| */ | ||
|
|
@@ -51,7 +53,8 @@ public class PackageURLTest { | |
| @BeforeClass | ||
| public static void setup() throws IOException { | ||
| InputStream is = PackageURLTest.class.getResourceAsStream("/test-suite-data.json"); | ||
| String jsonTxt = IOUtils.toString(is, "UTF-8"); | ||
| Assert.assertNotNull(is); | ||
| String jsonTxt = IOUtils.toString(is, StandardCharsets.UTF_8); | ||
| json = new JSONArray(jsonTxt); | ||
| } | ||
|
|
||
|
|
@@ -77,7 +80,7 @@ public void testConstructorParsing() throws Exception { | |
| if (invalid) { | ||
| try { | ||
| PackageURL purl = new PackageURL(purlString); | ||
| Assert.fail("Inavlid purl should have caused an exception: " + purl.toString()); | ||
| Assert.fail("Inavlid purl should have caused an exception: " + purl); | ||
| } catch (MalformedPackageURLException e) { | ||
| Assert.assertNotNull(e.getMessage()); | ||
| } | ||
|
|
@@ -97,7 +100,7 @@ public void testConstructorParsing() throws Exception { | |
| } else { | ||
| Assert.assertNotNull(purl.getQualifiers()); | ||
| Assert.assertEquals(qualifiers.length(), purl.getQualifiers().size()); | ||
| qualifiers.keySet().forEach((key) -> { | ||
| qualifiers.keySet().forEach(key -> { | ||
| String value = qualifiers.getString(key); | ||
| Assert.assertTrue(purl.getQualifiers().containsKey(key)); | ||
| Assert.assertEquals(value, purl.getQualifiers().get(key)); | ||
|
|
@@ -130,16 +133,16 @@ public void testConstructorParameters() throws MalformedPackageURLException { | |
| TreeMap<String, String> map = null; | ||
| if (qualifiers != null) { | ||
| map = qualifiers.toMap().entrySet().stream().collect( | ||
| TreeMap<String, String>::new, | ||
| TreeMap::new, | ||
| (qmap, entry) -> qmap.put(entry.getKey(), (String) entry.getValue()), | ||
| TreeMap<String, String>::putAll | ||
| TreeMap::putAll | ||
| ); | ||
| } | ||
|
|
||
| if (invalid) { | ||
| try { | ||
| PackageURL purl = new PackageURL(type, namespace, name, version, map, subpath); | ||
| Assert.fail("Invalid package url components should have caused an exception: " + purl.toString()); | ||
| Assert.fail("Invalid package url components should have caused an exception: " + purl); | ||
| } catch (MalformedPackageURLException e) { | ||
| Assert.assertNotNull(e.getMessage()); | ||
| } | ||
|
|
@@ -158,7 +161,7 @@ public void testConstructorParameters() throws MalformedPackageURLException { | |
| if (qualifiers != null) { | ||
| Assert.assertNotNull(purl.getQualifiers()); | ||
| Assert.assertEquals(qualifiers.length(), purl.getQualifiers().size()); | ||
| qualifiers.keySet().forEach((key) -> { | ||
| qualifiers.keySet().forEach(key -> { | ||
| String value = qualifiers.getString(key); | ||
| Assert.assertTrue(purl.getQualifiers().containsKey(key)); | ||
| Assert.assertEquals(value, purl.getQualifiers().get(key)); | ||
|
|
@@ -177,6 +180,7 @@ public void testConstructor() throws MalformedPackageURLException { | |
|
|
||
| purl = new PackageURL("pkg:generic/namespace/[email protected]?key=value=="); | ||
| Assert.assertEquals("generic", purl.getType()); | ||
| Assert.assertNotNull(purl.getQualifiers()); | ||
| Assert.assertEquals(1, purl.getQualifiers().size()); | ||
| Assert.assertTrue(purl.getQualifiers().containsValue("value==")); | ||
|
|
||
|
|
@@ -268,24 +272,23 @@ public void testConstructorWithDuplicateQualifiers() throws MalformedPackageURLE | |
|
|
||
| @Test | ||
| public void testStandardTypes() { | ||
| exception = ExpectedException.none(); | ||
| Assert.assertEquals(PackageURL.StandardTypes.BITBUCKET, "bitbucket"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.CARGO, "cargo"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.COMPOSER, "composer"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.DEBIAN, "deb"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.DOCKER, "docker"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.GEM, "gem"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.GENERIC, "generic"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.GITHUB, "github"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.GOLANG, "golang"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.HEX, "hex"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.MAVEN, "maven"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.NPM, "npm"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.NUGET, "nuget"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.PYPI, "pypi"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.RPM, "rpm"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.NIXPKGS, "nixpkgs"); | ||
| Assert.assertEquals(PackageURL.StandardTypes.HACKAGE, "hackage"); | ||
| Assert.assertEquals("bitbucket", PackageURL.StandardTypes.BITBUCKET); | ||
| Assert.assertEquals("cargo", PackageURL.StandardTypes.CARGO); | ||
| Assert.assertEquals("composer", PackageURL.StandardTypes.COMPOSER); | ||
| Assert.assertEquals("deb", PackageURL.StandardTypes.DEBIAN); | ||
| Assert.assertEquals("docker", PackageURL.StandardTypes.DOCKER); | ||
| Assert.assertEquals("gem", PackageURL.StandardTypes.GEM); | ||
| Assert.assertEquals("generic", PackageURL.StandardTypes.GENERIC); | ||
| Assert.assertEquals("github", PackageURL.StandardTypes.GITHUB); | ||
| Assert.assertEquals("golang", PackageURL.StandardTypes.GOLANG); | ||
| Assert.assertEquals("hex", PackageURL.StandardTypes.HEX); | ||
| Assert.assertEquals("maven", PackageURL.StandardTypes.MAVEN); | ||
| Assert.assertEquals("npm", PackageURL.StandardTypes.NPM); | ||
| Assert.assertEquals("nuget", PackageURL.StandardTypes.NUGET); | ||
| Assert.assertEquals("pypi", PackageURL.StandardTypes.PYPI); | ||
| Assert.assertEquals("rpm", PackageURL.StandardTypes.RPM); | ||
| Assert.assertEquals("nixpkgs", PackageURL.StandardTypes.NIXPKGS); | ||
| Assert.assertEquals("hackage", PackageURL.StandardTypes.HACKAGE); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -319,14 +322,14 @@ public void testGetCoordinatesNoCacheIssue89() throws Exception { | |
| public void testNpmCaseSensitive() throws Exception { | ||
| // e.g. https://www.npmjs.com/package/base64/v/1.0.0 | ||
| PackageURL base64Lowercase = new PackageURL("pkg:npm/[email protected]"); | ||
| Assert.assertEquals(base64Lowercase.getType(), "npm"); | ||
| Assert.assertEquals(base64Lowercase.getName(), "base64"); | ||
| Assert.assertEquals(base64Lowercase.getVersion(), "1.0.0"); | ||
| Assert.assertEquals("npm", base64Lowercase.getType()); | ||
| Assert.assertEquals("base64", base64Lowercase.getName()); | ||
| Assert.assertEquals("1.0.0", base64Lowercase.getVersion()); | ||
|
|
||
| // e.g. https://www.npmjs.com/package/Base64/v/1.0.0 | ||
| PackageURL base64Uppercase = new PackageURL("pkg:npm/[email protected]"); | ||
| Assert.assertEquals(base64Uppercase.getType(), "npm"); | ||
| Assert.assertEquals(base64Uppercase.getName(), "Base64"); | ||
| Assert.assertEquals(base64Uppercase.getVersion(), "1.0.0"); | ||
| Assert.assertEquals("npm", base64Uppercase.getType()); | ||
| Assert.assertEquals("Base64", base64Uppercase.getName()); | ||
| Assert.assertEquals("1.0.0", base64Uppercase.getVersion()); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.