|
43 | 43 | import java.nio.charset.StandardCharsets; |
44 | 44 | import java.nio.file.Files; |
45 | 45 | import java.nio.file.NoSuchFileException; |
| 46 | +import java.nio.file.Path; |
46 | 47 | import java.nio.file.Paths; |
47 | 48 | import java.security.cert.CertificateException; |
48 | 49 | import java.security.cert.CertificateFactory; |
@@ -328,25 +329,30 @@ public void getSubjectToken_trustChainInvalidFormat_throwsIOException() throws E |
328 | 329 |
|
329 | 330 | @Test |
330 | 331 | public void getSubjectToken_leafCertFileNotFound_throwsIOException() { |
331 | | - // Configure mock to return a non-existent path for the leaf certificate |
| 332 | + // Configure mock to return a non-existent path for the leaf certificate. |
332 | 333 | String nonExistentPath = "/path/to/non/existent/leaf.pem"; |
333 | 334 | when(mockCredentialSource.getCredentialLocation()).thenReturn(nonExistentPath); |
334 | 335 | // Re-initialize supplier with the bad leaf path |
335 | 336 | supplier = new CertificateIdentityPoolSubjectTokenSupplier(mockCredentialSource); |
336 | 337 |
|
337 | | - // Execute & Verify: Expect the wrapper IOException |
| 338 | + // Execute & Verify: Expect the wrapper IOException. |
338 | 339 | IOException exception = |
339 | 340 | assertThrows(IOException.class, () -> supplier.getSubjectToken(mockContext)); |
340 | 341 |
|
341 | | - // Check the message of the wrapper IOException |
| 342 | + // Check the message of the wrapper IOException. |
342 | 343 | assertEquals("Leaf certificate file not found: " + nonExistentPath, exception.getMessage()); |
343 | 344 |
|
344 | | - // Check that the cause is the original NoSuchFileException |
| 345 | + // Check that the cause is the original NoSuchFileException. |
345 | 346 | assertNotNull("Exception should have a cause", exception.getCause()); |
346 | 347 | assertTrue( |
347 | 348 | "Cause should be NoSuchFileException", exception.getCause() instanceof NoSuchFileException); |
348 | | - // Optionally, check the message of the cause (which is the path) |
349 | | - assertEquals(nonExistentPath, exception.getCause().getMessage()); |
| 349 | + |
| 350 | + // Check the message of the cause (which is the path) in a platform-agnostic way. |
| 351 | + Path expectedCausePath = Paths.get(nonExistentPath); |
| 352 | + Path actualCausePath = Paths.get(exception.getCause().getMessage()); |
| 353 | + assertEquals( |
| 354 | + expectedCausePath, |
| 355 | + actualCausePath); |
350 | 356 | } |
351 | 357 |
|
352 | 358 | @Test |
|
0 commit comments