|
31 | 31 | import java.util.Arrays; |
32 | 32 | import java.util.Collections; |
33 | 33 | import java.util.HashMap; |
| 34 | +import java.util.List; |
34 | 35 | import java.util.Map; |
35 | 36 | import java.util.Optional; |
36 | 37 | import java.util.Properties; |
|
39 | 40 | import org.apache.commons.lang3.tuple.Pair; |
40 | 41 | import org.apache.maven.buildcache.DefaultPluginScanConfig; |
41 | 42 | import org.apache.maven.buildcache.hash.HashFactory; |
| 43 | +import org.apache.maven.buildcache.xml.config.AttachedOutputs; |
42 | 44 | import org.apache.maven.buildcache.xml.config.Configuration; |
| 45 | +import org.apache.maven.buildcache.xml.config.DirName; |
43 | 46 | import org.apache.maven.buildcache.xml.config.Remote; |
44 | 47 | import org.apache.maven.execution.MavenExecutionRequest; |
45 | 48 | import org.apache.maven.execution.MavenSession; |
@@ -482,4 +485,45 @@ void testRemoveSaveFinalIgnoredWhenRemoteSaveDisabled() { |
482 | 485 | Pair.of("getUrl", () -> assertEquals("dummy.url.xyz", testObject.getUrl())), |
483 | 486 | Pair.of("isRemoteCacheEnabled", () -> assertTrue(testObject.isRemoteCacheEnabled()))); |
484 | 487 | } |
| 488 | + |
| 489 | + @Test |
| 490 | + void testDefaultAttachedOutputsWhenNotConfigured() { |
| 491 | + // When attachedOutputs is not configured in XML, should return default list |
| 492 | + Configuration configuration = new Configuration(); |
| 493 | + // Deliberately not setting attachedOutputs |
| 494 | + testCacheConfig.setConfiguration(configuration); |
| 495 | + |
| 496 | + assertEquals(CacheState.INITIALIZED, testObject.initialize()); |
| 497 | + |
| 498 | + List<DirName> attachedOutputs = testObject.getAttachedOutputs(); |
| 499 | + assertEquals(2, attachedOutputs.size(), "Should have 2 default attached outputs"); |
| 500 | + |
| 501 | + List<String> dirNames = attachedOutputs.stream() |
| 502 | + .map(DirName::getValue) |
| 503 | + .collect(Collectors.toList()); |
| 504 | + |
| 505 | + assertTrue(dirNames.contains("classes"), "Should include 'classes' directory by default"); |
| 506 | + assertTrue(dirNames.contains("test-classes"), "Should include 'test-classes' directory by default"); |
| 507 | + } |
| 508 | + |
| 509 | + @Test |
| 510 | + void testExplicitAttachedOutputsOverridesDefaults() { |
| 511 | + // When attachedOutputs is explicitly configured, should use those values instead of defaults |
| 512 | + Configuration configuration = new Configuration(); |
| 513 | + AttachedOutputs attachedOutputs = new AttachedOutputs(); |
| 514 | + |
| 515 | + DirName customDir = new DirName(); |
| 516 | + customDir.setValue("custom-output"); |
| 517 | + attachedOutputs.addDirName(customDir); |
| 518 | + |
| 519 | + configuration.setAttachedOutputs(attachedOutputs); |
| 520 | + testCacheConfig.setConfiguration(configuration); |
| 521 | + |
| 522 | + assertEquals(CacheState.INITIALIZED, testObject.initialize()); |
| 523 | + |
| 524 | + List<DirName> result = testObject.getAttachedOutputs(); |
| 525 | + assertEquals(1, result.size(), "Should have 1 explicitly configured output"); |
| 526 | + assertEquals("custom-output", result.get(0).getValue(), |
| 527 | + "Should use explicitly configured directory, not defaults"); |
| 528 | + } |
485 | 529 | } |
0 commit comments