|
16 | 16 | */ |
17 | 17 | package io.github.guacsec.trustifyda.providers; |
18 | 18 |
|
| 19 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; |
20 | 21 | import static org.junit.jupiter.api.Assertions.assertFalse; |
21 | 22 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
|
28 | 29 | import io.github.guacsec.trustifyda.sbom.SbomFactory; |
29 | 30 | import io.github.guacsec.trustifyda.tools.Ecosystem.Type; |
30 | 31 | import java.io.IOException; |
31 | | -import java.lang.reflect.InvocationTargetException; |
32 | 32 | import java.nio.charset.StandardCharsets; |
33 | 33 | import java.nio.file.Files; |
34 | 34 | import java.nio.file.Path; |
35 | 35 | import java.util.HashMap; |
36 | 36 | import java.util.HashSet; |
37 | | -import java.util.Map; |
38 | 37 | import java.util.Set; |
39 | 38 | import org.junit.jupiter.api.Test; |
40 | 39 | import org.junit.jupiter.api.io.TempDir; |
@@ -760,28 +759,11 @@ public void testVirtualWorkspaceWithoutWorkspaceDepsDoesNotThrowNPE(@TempDir Pat |
760 | 759 | new PackageURL(Type.CARGO.getType(), null, "test-workspace", "1.0.0", null, null); |
761 | 760 | sbom.addRoot(root); |
762 | 761 |
|
763 | | - // Call the private processWorkspaceDependencies via reflection |
764 | | - var method = |
765 | | - CargoProvider.class.getDeclaredMethod( |
766 | | - "processWorkspaceDependencies", |
767 | | - Sbom.class, |
768 | | - PackageURL.class, |
769 | | - Map.class, |
770 | | - Set.class, |
771 | | - TomlParseResult.class); |
772 | | - method.setAccessible(true); |
773 | | - |
774 | 762 | // This should NOT throw NPE when [workspace.dependencies] is absent |
775 | | - try { |
776 | | - method.invoke(provider, sbom, root, new HashMap<>(), new HashSet<>(), tomlResult); |
777 | | - } catch (InvocationTargetException e) { |
778 | | - if (e.getCause() instanceof NullPointerException) { |
779 | | - throw new AssertionError( |
780 | | - "processWorkspaceDependencies threw NPE when [workspace.dependencies] is absent." |
781 | | - + " The method should handle a missing workspace.dependencies table gracefully.", |
782 | | - e.getCause()); |
783 | | - } |
784 | | - throw e; |
785 | | - } |
| 763 | + assertDoesNotThrow( |
| 764 | + () -> |
| 765 | + provider.processWorkspaceDependencies( |
| 766 | + sbom, root, new HashMap<>(), new HashSet<>(), tomlResult), |
| 767 | + "processWorkspaceDependencies should handle missing [workspace.dependencies] gracefully"); |
786 | 768 | } |
787 | 769 | } |
0 commit comments