Skip to content

Commit 3cc2c09

Browse files
Strum355claude
andcommitted
fix(test): update Maven workspace tests to mock getExecutable
The resolveVerifiedMavenBinary refactoring changed the binary resolution path from getCustomPathOrElse (no verification) to getExecutable (runs --version). Update test mocks accordingly so Maven discovery tests pass in environments without Maven on PATH. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ef2a103 commit 3cc2c09

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/main/java/io/github/guacsec/trustifyda/impl/ExhortApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import io.github.guacsec.trustifyda.image.ImageUtils;
3131
import io.github.guacsec.trustifyda.license.LicenseCheck;
3232
import io.github.guacsec.trustifyda.logging.LoggersFactory;
33-
import io.github.guacsec.trustifyda.providers.golang.model.GoWorkspace;
3433
import io.github.guacsec.trustifyda.providers.JavaMavenProvider;
34+
import io.github.guacsec.trustifyda.providers.golang.model.GoWorkspace;
3535
import io.github.guacsec.trustifyda.providers.javascript.workspace.JsWorkspaceDiscovery;
3636
import io.github.guacsec.trustifyda.providers.rust.model.CargoMetadata;
3737
import io.github.guacsec.trustifyda.tools.Ecosystem;
@@ -986,6 +986,7 @@ private List<Path> discoverGoWorkspaceModules(Path workspaceDir, Set<String> ign
986986
return Collections.emptyList();
987987
}
988988
}
989+
989990
/**
990991
* Discovers Maven multi-module workspace manifests by invoking {@code mvn help:evaluate} to list
991992
* declared modules, then recursively checking each module for nested aggregators.

src/test/java/io/github/guacsec/trustifyda/impl/MavenWorkspaceDiscoveryTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void discoverWorkspaceManifests_mavenMultiModule() throws IOException {
113113
// Mock Maven binary resolution
114114
mockOps.when(() -> Operations.getWrapperPreference("mvn")).thenReturn(false);
115115
mockOps.when(() -> Operations.isWindows()).thenReturn(false);
116-
mockOps.when(() -> Operations.getCustomPathOrElse("mvn")).thenReturn("mvn");
116+
mockOps.when(() -> Operations.getExecutable("mvn", "-v")).thenReturn("mvn");
117117

118118
// Mock mvn help:evaluate for root pom -> returns [module-a, module-b]
119119
mockOps
@@ -162,7 +162,7 @@ void discoverWorkspaceManifests_nestedAggregator() throws IOException {
162162
try (MockedStatic<Operations> mockOps = Mockito.mockStatic(Operations.class)) {
163163
mockOps.when(() -> Operations.getWrapperPreference("mvn")).thenReturn(false);
164164
mockOps.when(() -> Operations.isWindows()).thenReturn(false);
165-
mockOps.when(() -> Operations.getCustomPathOrElse("mvn")).thenReturn("mvn");
165+
mockOps.when(() -> Operations.getExecutable("mvn", "-v")).thenReturn("mvn");
166166

167167
// Root -> [parent]
168168
mockOps
@@ -228,7 +228,7 @@ void discoverWorkspaceManifests_noModules() throws IOException {
228228
try (MockedStatic<Operations> mockOps = Mockito.mockStatic(Operations.class)) {
229229
mockOps.when(() -> Operations.getWrapperPreference("mvn")).thenReturn(false);
230230
mockOps.when(() -> Operations.isWindows()).thenReturn(false);
231-
mockOps.when(() -> Operations.getCustomPathOrElse("mvn")).thenReturn("mvn");
231+
mockOps.when(() -> Operations.getExecutable("mvn", "-v")).thenReturn("mvn");
232232

233233
// Root -> null (no modules)
234234
mockOps
@@ -257,7 +257,7 @@ void discoverWorkspaceManifests_missingModuleDirectory() throws IOException {
257257
try (MockedStatic<Operations> mockOps = Mockito.mockStatic(Operations.class)) {
258258
mockOps.when(() -> Operations.getWrapperPreference("mvn")).thenReturn(false);
259259
mockOps.when(() -> Operations.isWindows()).thenReturn(false);
260-
mockOps.when(() -> Operations.getCustomPathOrElse("mvn")).thenReturn("mvn");
260+
mockOps.when(() -> Operations.getExecutable("mvn", "-v")).thenReturn("mvn");
261261

262262
// Root -> [module-a, module-missing]
263263
mockOps
@@ -298,7 +298,7 @@ void discoverWorkspaceManifests_mvnCommandFails() throws IOException {
298298
try (MockedStatic<Operations> mockOps = Mockito.mockStatic(Operations.class)) {
299299
mockOps.when(() -> Operations.getWrapperPreference("mvn")).thenReturn(false);
300300
mockOps.when(() -> Operations.isWindows()).thenReturn(false);
301-
mockOps.when(() -> Operations.getCustomPathOrElse("mvn")).thenReturn("mvn");
301+
mockOps.when(() -> Operations.getExecutable("mvn", "-v")).thenReturn("mvn");
302302

303303
// mvn command fails with non-zero exit code
304304
mockOps
@@ -327,7 +327,7 @@ void discoverWorkspaceManifests_ignorePatternFiltering() throws IOException {
327327
try (MockedStatic<Operations> mockOps = Mockito.mockStatic(Operations.class)) {
328328
mockOps.when(() -> Operations.getWrapperPreference("mvn")).thenReturn(false);
329329
mockOps.when(() -> Operations.isWindows()).thenReturn(false);
330-
mockOps.when(() -> Operations.getCustomPathOrElse("mvn")).thenReturn("mvn");
330+
mockOps.when(() -> Operations.getExecutable("mvn", "-v")).thenReturn("mvn");
331331

332332
// Root -> [module-a, module-b]
333333
mockOps
@@ -377,7 +377,7 @@ void defaultIgnorePatterns_includesTarget() throws IOException {
377377
try (MockedStatic<Operations> mockOps = Mockito.mockStatic(Operations.class)) {
378378
mockOps.when(() -> Operations.getWrapperPreference("mvn")).thenReturn(false);
379379
mockOps.when(() -> Operations.isWindows()).thenReturn(false);
380-
mockOps.when(() -> Operations.getCustomPathOrElse("mvn")).thenReturn("mvn");
380+
mockOps.when(() -> Operations.getExecutable("mvn", "-v")).thenReturn("mvn");
381381

382382
// Root -> [module-a]
383383
mockOps

0 commit comments

Comments
 (0)