|
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 |
|
@@ -204,100 +204,58 @@ void constructor() throws MalformedPackageURLException { |
204 | 204 |
|
205 | 205 | @Test |
206 | 206 | void constructorWithEmptyType() { |
207 | | - assertThrows(MalformedPackageURLException.class, () -> { |
208 | | - |
209 | | - PackageURL purl = new PackageURL("", "name"); |
210 | | - fail("constructor with an empty type should have thrown an error and this line should not be reached"); |
211 | | - }); |
| 207 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("", "name"), "constructor with an empty type should have thrown an error and this line should not be reached"); |
212 | 208 | } |
213 | 209 |
|
214 | 210 | @Test |
215 | 211 | void constructorWithInvalidCharsType() { |
216 | | - assertThrows(MalformedPackageURLException.class, () -> { |
217 | | - |
218 | | - PackageURL purl = new PackageURL("invalid^type", "name"); |
219 | | - fail("constructor with `invalid^type` should have thrown an error and this line should not be reached"); |
220 | | - }); |
| 212 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("invalid^type", "name"), "constructor with `invalid^type` should have thrown an error and this line should not be reached"); |
221 | 213 | } |
222 | 214 |
|
223 | 215 | @Test |
224 | 216 | void constructorWithInvalidNumberType() { |
225 | | - assertThrows(MalformedPackageURLException.class, () -> { |
226 | | - |
227 | | - PackageURL purl = new PackageURL("0invalid", "name"); |
228 | | - fail("constructor with `0invalid` should have thrown an error and this line should not be reached"); |
229 | | - }); |
| 217 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("0invalid", "name"), "constructor with `0invalid` should have thrown an error and this line should not be reached"); |
230 | 218 | } |
231 | 219 |
|
232 | 220 | @Test |
233 | 221 | void constructorWithInvalidSubpath() { |
234 | | - assertThrows(MalformedPackageURLException.class, () -> { |
235 | | - |
236 | | - PackageURL purl = new PackageURL("pkg:GOLANG/google.golang.org/genproto@abcdedf#invalid/%2F/subpath"); |
237 | | - fail("constructor with `invalid/%2F/subpath` should have thrown an error and this line should not be reached"); |
238 | | - }); |
| 222 | + 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"); |
239 | 223 | } |
240 | 224 |
|
241 | 225 |
|
242 | 226 | @Test |
243 | 227 | void constructorWithNullPurl() { |
244 | | - assertThrows(NullPointerException.class, () -> |
245 | | - new PackageURL(null), |
246 | | - "constructor with null purl should have thrown an error and this line should not be reached"); |
| 228 | + assertThrowsExactly(NullPointerException.class, () -> new PackageURL(null), "constructor with null purl should have thrown an error and this line should not be reached"); |
247 | 229 | } |
248 | 230 |
|
249 | 231 | @Test |
250 | 232 | void constructorWithEmptyPurl() { |
251 | | - assertThrows(MalformedPackageURLException.class, () -> { |
252 | | - |
253 | | - PackageURL purl = new PackageURL(""); |
254 | | - fail("constructor with empty purl should have thrown an error and this line should not be reached"); |
255 | | - }); |
| 233 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL(""), "constructor with empty purl should have thrown an error and this line should not be reached"); |
256 | 234 | } |
257 | 235 |
|
258 | 236 | @Test |
259 | 237 | void constructorWithPortNumber() { |
260 | | - assertThrows(MalformedPackageURLException.class, () -> { |
261 | | - |
262 | | - PackageURL purl = new PackageURL("pkg://generic:8080/name"); |
263 | | - fail("constructor with port number should have thrown an error and this line should not be reached"); |
264 | | - }); |
| 238 | + 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"); |
265 | 239 | } |
266 | 240 |
|
267 | 241 | @Test |
268 | 242 | void constructorWithUsername() { |
269 | | - assertThrows(MalformedPackageURLException.class, () -> { |
270 | | - |
271 | | - PackageURL purl = new PackageURL("pkg://user@generic/name"); |
272 | | - fail("constructor with username should have thrown an error and this line should not be reached"); |
273 | | - }); |
| 243 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("pkg://user@generic/name"), "constructor with username should have thrown an error and this line should not be reached"); |
274 | 244 | } |
275 | 245 |
|
276 | 246 | @Test |
277 | 247 | void constructorWithInvalidUrl() { |
278 | | - assertThrows(MalformedPackageURLException.class, () -> { |
279 | | - |
280 | | - PackageURL purl = new PackageURL("invalid url"); |
281 | | - fail("constructor with invalid url should have thrown an error and this line should not be reached"); |
282 | | - }); |
| 248 | + assertThrowsExactly(MalformedPackageURLException.class, () -> new PackageURL("invalid url"), "constructor with invalid url should have thrown an error and this line should not be reached"); |
283 | 249 | } |
284 | 250 |
|
285 | 251 | @Test |
286 | 252 | void constructorWithDuplicateQualifiers() { |
287 | | - assertThrows(MalformedPackageURLException.class, () -> { |
288 | | - |
289 | | - PackageURL purl = new PackageURL("pkg://generic/name?key=one&key=two"); |
290 | | - fail("constructor with url with duplicate qualifiers should have thrown an error and this line should not be reached"); |
291 | | - }); |
| 253 | + 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"); |
292 | 254 | } |
293 | 255 |
|
294 | 256 | @Test |
295 | 257 | void constructorDuplicateQualifiersMixedCase() { |
296 | | - assertThrows(MalformedPackageURLException.class, () -> { |
297 | | - |
298 | | - PackageURL purl = new PackageURL("pkg://generic/name?key=one&KEY=two"); |
299 | | - fail("constructor with url with duplicate qualifiers should have thrown an error and this line should not be reached"); |
300 | | - }); |
| 258 | + 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"); |
301 | 259 | } |
302 | 260 |
|
303 | 261 | @Test |
|
0 commit comments