Skip to content

Commit fc5c5e8

Browse files
committed
Fix: Update failing unit test to compare paths in a platform-agnostic way.
1 parent acb026f commit fc5c5e8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

oauth2_http/javatests/com/google/auth/oauth2/CertificateIdentityPoolSubjectTokenSupplierTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.nio.charset.StandardCharsets;
4444
import java.nio.file.Files;
4545
import java.nio.file.NoSuchFileException;
46+
import java.nio.file.Path;
4647
import java.nio.file.Paths;
4748
import java.security.cert.CertificateException;
4849
import java.security.cert.CertificateFactory;
@@ -328,25 +329,30 @@ public void getSubjectToken_trustChainInvalidFormat_throwsIOException() throws E
328329

329330
@Test
330331
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.
332333
String nonExistentPath = "/path/to/non/existent/leaf.pem";
333334
when(mockCredentialSource.getCredentialLocation()).thenReturn(nonExistentPath);
334335
// Re-initialize supplier with the bad leaf path
335336
supplier = new CertificateIdentityPoolSubjectTokenSupplier(mockCredentialSource);
336337

337-
// Execute & Verify: Expect the wrapper IOException
338+
// Execute & Verify: Expect the wrapper IOException.
338339
IOException exception =
339340
assertThrows(IOException.class, () -> supplier.getSubjectToken(mockContext));
340341

341-
// Check the message of the wrapper IOException
342+
// Check the message of the wrapper IOException.
342343
assertEquals("Leaf certificate file not found: " + nonExistentPath, exception.getMessage());
343344

344-
// Check that the cause is the original NoSuchFileException
345+
// Check that the cause is the original NoSuchFileException.
345346
assertNotNull("Exception should have a cause", exception.getCause());
346347
assertTrue(
347348
"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);
350356
}
351357

352358
@Test

0 commit comments

Comments
 (0)