|
24 | 24 | import static org.junit.jupiter.api.Assertions.assertEquals; |
25 | 25 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
26 | 26 | import static org.junit.jupiter.api.Assertions.assertNull; |
27 | | -import static org.junit.jupiter.api.Assertions.assertThrows; |
| 27 | +import static org.junit.jupiter.api.Assertions.assertThrowsExactly; |
28 | 28 | import static org.junit.jupiter.api.Assertions.assertTrue; |
29 | 29 | import static org.junit.jupiter.api.Assertions.fail; |
30 | 30 |
|
@@ -229,100 +229,58 @@ void constructor() throws MalformedPackageURLException { |
229 | 229 |
|
230 | 230 | @Test |
231 | 231 | void constructorWithEmptyType() { |
232 | | - assertThrows(MalformedPackageURLException.class, () -> { |
233 | | - |
234 | | - PackageURL purl = new PackageURL("", "name"); |
235 | | - fail("constructor with an empty type should have thrown an error and this line should not be reached"); |
236 | | - }); |
| 232 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("", "name"), "constructor with an empty type should have thrown an error and this line should not be reached"); |
237 | 233 | } |
238 | 234 |
|
239 | 235 | @Test |
240 | 236 | void constructorWithInvalidCharsType() { |
241 | | - assertThrows(MalformedPackageURLException.class, () -> { |
242 | | - |
243 | | - PackageURL purl = new PackageURL("invalid^type", "name"); |
244 | | - fail("constructor with `invalid^type` should have thrown an error and this line should not be reached"); |
245 | | - }); |
| 237 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("invalid^type", "name"), "constructor with `invalid^type` should have thrown an error and this line should not be reached"); |
246 | 238 | } |
247 | 239 |
|
248 | 240 | @Test |
249 | 241 | void constructorWithInvalidNumberType() { |
250 | | - assertThrows(MalformedPackageURLException.class, () -> { |
251 | | - |
252 | | - PackageURL purl = new PackageURL("0invalid", "name"); |
253 | | - fail("constructor with `0invalid` should have thrown an error and this line should not be reached"); |
254 | | - }); |
| 242 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("0invalid", "name"), "constructor with `0invalid` should have thrown an error and this line should not be reached"); |
255 | 243 | } |
256 | 244 |
|
257 | 245 | @Test |
258 | 246 | void constructorWithInvalidSubpath() { |
259 | | - assertThrows(MalformedPackageURLException.class, () -> { |
260 | | - |
261 | | - PackageURL purl = new PackageURL("pkg:GOLANG/google.golang.org/genproto@abcdedf#invalid/%2F/subpath"); |
262 | | - fail("constructor with `invalid/%2F/subpath` should have thrown an error and this line should not be reached"); |
263 | | - }); |
| 247 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("pkg:GOLANG/google.golang.org/genproto@abcdedf#invalid/%2F/subpath"), "constructor with `invalid/%2F/subpath` should have thrown an error and this line should not be reached"); |
264 | 248 | } |
265 | 249 |
|
266 | 250 |
|
267 | 251 | @Test |
268 | 252 | void constructorWithNullPurl() { |
269 | | - assertThrows(NullPointerException.class, () -> |
270 | | - new PackageURL(null), |
271 | | - "constructor with null purl should have thrown an error and this line should not be reached"); |
| 253 | + assertThrowsExactly(NullPointerException.class, () -> new PackageURL(null), "constructor with null purl should have thrown an error and this line should not be reached"); |
272 | 254 | } |
273 | 255 |
|
274 | 256 | @Test |
275 | 257 | void constructorWithEmptyPurl() { |
276 | | - assertThrows(MalformedPackageURLException.class, () -> { |
277 | | - |
278 | | - PackageURL purl = new PackageURL(""); |
279 | | - fail("constructor with empty purl should have thrown an error and this line should not be reached"); |
280 | | - }); |
| 258 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL(""), "constructor with empty purl should have thrown an error and this line should not be reached"); |
281 | 259 | } |
282 | 260 |
|
283 | 261 | @Test |
284 | 262 | void constructorWithPortNumber() { |
285 | | - assertThrows(MalformedPackageURLException.class, () -> { |
286 | | - |
287 | | - PackageURL purl = new PackageURL("pkg://generic:8080/name"); |
288 | | - fail("constructor with port number should have thrown an error and this line should not be reached"); |
289 | | - }); |
| 263 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("pkg://generic:8080/name"), "constructor with port number should have thrown an error and this line should not be reached"); |
290 | 264 | } |
291 | 265 |
|
292 | 266 | @Test |
293 | 267 | void constructorWithUsername() { |
294 | | - assertThrows(MalformedPackageURLException.class, () -> { |
295 | | - |
296 | | - PackageURL purl = new PackageURL("pkg://user@generic/name"); |
297 | | - fail("constructor with username should have thrown an error and this line should not be reached"); |
298 | | - }); |
| 268 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("pkg://user@generic/name"), "constructor with username should have thrown an error and this line should not be reached"); |
299 | 269 | } |
300 | 270 |
|
301 | 271 | @Test |
302 | 272 | void constructorWithInvalidUrl() { |
303 | | - assertThrows(MalformedPackageURLException.class, () -> { |
304 | | - |
305 | | - PackageURL purl = new PackageURL("invalid url"); |
306 | | - fail("constructor with invalid url should have thrown an error and this line should not be reached"); |
307 | | - }); |
| 273 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("invalid url"), "constructor with invalid url should have thrown an error and this line should not be reached"); |
308 | 274 | } |
309 | 275 |
|
310 | 276 | @Test |
311 | 277 | void constructorWithDuplicateQualifiers() { |
312 | | - assertThrows(MalformedPackageURLException.class, () -> { |
313 | | - |
314 | | - PackageURL purl = new PackageURL("pkg://generic/name?key=one&key=two"); |
315 | | - fail("constructor with url with duplicate qualifiers should have thrown an error and this line should not be reached"); |
316 | | - }); |
| 278 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("pkg://generic/name?key=one&key=two"), "constructor with url with duplicate qualifiers should have thrown an error and this line should not be reached"); |
317 | 279 | } |
318 | 280 |
|
319 | 281 | @Test |
320 | 282 | void constructorDuplicateQualifiersMixedCase() { |
321 | | - assertThrows(MalformedPackageURLException.class, () -> { |
322 | | - |
323 | | - PackageURL purl = new PackageURL("pkg://generic/name?key=one&KEY=two"); |
324 | | - fail("constructor with url with duplicate qualifiers should have thrown an error and this line should not be reached"); |
325 | | - }); |
| 283 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("pkg://generic/name?key=one&KEY=two"), "constructor with url with duplicate qualifiers should have thrown an error and this line should not be reached"); |
326 | 284 | } |
327 | 285 |
|
328 | 286 | @Test |
|
0 commit comments