@@ -64,16 +64,22 @@ static void resetLocale() {
64
64
void validPercentEncoding () throws MalformedPackageURLException {
65
65
PackageURL purl = new PackageURL ("maven" , "com.google.summit" , "summit-ast" , "2.2.0\n " , null , null );
66
66
assertEquals (
"pkg:maven/com.google.summit/[email protected] %0A" ,
purl .
toString ());
67
- PackageURL purl2 = new PackageURL ("pkg:nuget/%D0%9Cicros%D0%BEft.%D0%95ntit%D1%83Fram%D0%B5work%D0%A1%D0%BEr%D0%B5" );
67
+ PackageURL purl2 =
68
+ new PackageURL ("pkg:nuget/%D0%9Cicros%D0%BEft.%D0%95ntit%D1%83Fram%D0%B5work%D0%A1%D0%BEr%D0%B5" );
68
69
assertEquals ("Мicrosоft.ЕntitуFramеworkСоrе" , purl2 .getName ());
69
- assertEquals ("pkg:nuget/%D0%9Cicros%D0%BEft.%D0%95ntit%D1%83Fram%D0%B5work%D0%A1%D0%BEr%D0%B5" , purl2 .toString ());
70
+ assertEquals (
71
+ "pkg:nuget/%D0%9Cicros%D0%BEft.%D0%95ntit%D1%83Fram%D0%B5work%D0%A1%D0%BEr%D0%B5" , purl2 .toString ());
70
72
}
71
73
72
74
@ SuppressWarnings ("deprecation" )
73
75
@ Test
74
76
void invalidPercentEncoding () throws MalformedPackageURLException {
75
- assertThrowsExactly (
MalformedPackageURLException .
class , () ->
new PackageURL (
"pkg:maven/com.google.summit/[email protected] %" ));
76
- assertThrowsExactly (
MalformedPackageURLException .
class , () ->
new PackageURL (
"pkg:maven/com.google.summit/[email protected] %0" ));
77
+ assertThrowsExactly (
78
+ MalformedPackageURLException .class ,
79
+ () ->
new PackageURL (
"pkg:maven/com.google.summit/[email protected] %" ));
80
+ assertThrowsExactly (
81
+ MalformedPackageURLException .class ,
82
+ () ->
new PackageURL (
"pkg:maven/com.google.summit/[email protected] %0" ));
77
83
PackageURL purl =
new PackageURL (
"pkg:maven/com.google.summit/[email protected] " );
78
84
Throwable t1 = assertThrowsExactly (ValidationException .class , () -> purl .uriDecode ("%" ));
79
85
assertEquals ("Incomplete percent encoding at offset 0 with value '%'" , t1 .getMessage ());
@@ -86,19 +92,20 @@ void invalidPercentEncoding() throws MalformedPackageURLException {
86
92
}
87
93
88
94
static Stream <Arguments > constructorParsing () throws IOException {
89
- return PurlParameters .getTestDataFromFiles ("test-suite-data.json" ,
90
- "custom-suite.json" ,
91
- "string-constructor-only.json" );
95
+ return PurlParameters .getTestDataFromFiles (
96
+ "test-suite-data.json" , "custom-suite.json" , "string-constructor-only.json" );
92
97
}
93
98
94
99
@ DisplayName ("Test constructor parsing" )
95
100
@ ParameterizedTest (name = "{0}: ''{1}''" )
96
101
@ MethodSource
97
- void constructorParsing (String description ,
98
- @ Nullable String purlString ,
99
- PurlParameters parameters ,
100
- @ Nullable String canonicalPurl ,
101
- boolean invalid ) throws Exception {
102
+ void constructorParsing (
103
+ String description ,
104
+ @ Nullable String purlString ,
105
+ PurlParameters parameters ,
106
+ @ Nullable String canonicalPurl ,
107
+ boolean invalid )
108
+ throws Exception {
102
109
if (invalid ) {
103
110
assertThrows (getExpectedException (purlString ), () -> new PackageURL (purlString ));
104
111
} else {
@@ -109,32 +116,38 @@ void constructorParsing(String description,
109
116
}
110
117
111
118
static Stream <Arguments > constructorParameters () throws IOException {
112
- return PurlParameters .getTestDataFromFiles ("test-suite-data.json" , "custom-suite.json" , "components-constructor-only.json" );
119
+ return PurlParameters .getTestDataFromFiles (
120
+ "test-suite-data.json" , "custom-suite.json" , "components-constructor-only.json" );
113
121
}
114
122
115
123
@ DisplayName ("Test constructor parameters" )
116
124
@ ParameterizedTest (name = "{0}: {2}" )
117
125
@ MethodSource
118
- void constructorParameters (String description ,
119
- @ Nullable String purlString ,
120
- PurlParameters parameters ,
121
- @ Nullable String canonicalPurl ,
122
- boolean invalid ) throws Exception {
126
+ void constructorParameters (
127
+ String description ,
128
+ @ Nullable String purlString ,
129
+ PurlParameters parameters ,
130
+ @ Nullable String canonicalPurl ,
131
+ boolean invalid )
132
+ throws Exception {
123
133
if (invalid ) {
124
- assertThrows (getExpectedException (parameters ),
125
- () -> new PackageURL (parameters .getType (),
134
+ assertThrows (
135
+ getExpectedException (parameters ),
136
+ () -> new PackageURL (
137
+ parameters .getType (),
138
+ parameters .getNamespace (),
139
+ parameters .getName (),
140
+ parameters .getVersion (),
141
+ parameters .getQualifiers (),
142
+ parameters .getSubpath ()));
143
+ } else {
144
+ PackageURL purl = new PackageURL (
145
+ parameters .getType (),
126
146
parameters .getNamespace (),
127
147
parameters .getName (),
128
148
parameters .getVersion (),
129
149
parameters .getQualifiers (),
130
- parameters .getSubpath ()));
131
- } else {
132
- PackageURL purl = new PackageURL (parameters .getType (),
133
- parameters .getNamespace (),
134
- parameters .getName (),
135
- parameters .getVersion (),
136
- parameters .getQualifiers (),
137
- parameters .getSubpath ());
150
+ parameters .getSubpath ());
138
151
assertPurlEquals (parameters , purl );
139
152
assertEquals (canonicalPurl , purl .canonicalize (), "canonical PURL" );
140
153
}
@@ -146,14 +159,16 @@ static Stream<Arguments> constructorTypeNameSpace() throws IOException {
146
159
147
160
@ ParameterizedTest
148
161
@ MethodSource
149
- void constructorTypeNameSpace (String description ,
150
- @ Nullable String purlString ,
151
- PurlParameters parameters ,
152
- @ Nullable String canonicalPurl ,
153
- boolean invalid ) throws Exception {
162
+ void constructorTypeNameSpace (
163
+ String description ,
164
+ @ Nullable String purlString ,
165
+ PurlParameters parameters ,
166
+ @ Nullable String canonicalPurl ,
167
+ boolean invalid )
168
+ throws Exception {
154
169
if (invalid ) {
155
- assertThrows (getExpectedException ( parameters ),
156
- () -> new PackageURL (parameters .getType (), parameters .getName ()));
170
+ assertThrows (
171
+ getExpectedException ( parameters ), () -> new PackageURL (parameters .getType (), parameters .getName ()));
157
172
} else {
158
173
PackageURL purl = new PackageURL (parameters .getType (), parameters .getName ());
159
174
assertPurlEquals (parameters , purl );
@@ -173,7 +188,9 @@ private static void assertPurlEquals(PurlParameters expected, PackageURL actual)
173
188
}
174
189
175
190
private static Class <? extends Exception > getExpectedException (PurlParameters json ) {
176
- return json .getType () == null || json .getName () == null ? NullPointerException .class : MalformedPackageURLException .class ;
191
+ return json .getType () == null || json .getName () == null
192
+ ? NullPointerException .class
193
+ : MalformedPackageURLException .class ;
177
194
}
178
195
179
196
private static Class <? extends Exception > getExpectedException (@ Nullable String purl ) {
0 commit comments