Skip to content

Commit 0aaf3f5

Browse files
committed
Add tests for default attachedOutputs behavior
Tests verify that: - When attachedOutputs is not configured, it defaults to 'classes' and 'test-classes' - When attachedOutputs is explicitly configured, it overrides the defaults Addresses reviewer feedback from PR apache#388 requesting tests for restoration behavior.
1 parent fe23afa commit 0aaf3f5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/test/java/org/apache/maven/buildcache/xml/CacheConfigImplTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Arrays;
3232
import java.util.Collections;
3333
import java.util.HashMap;
34+
import java.util.List;
3435
import java.util.Map;
3536
import java.util.Optional;
3637
import java.util.Properties;
@@ -39,7 +40,9 @@
3940
import org.apache.commons.lang3.tuple.Pair;
4041
import org.apache.maven.buildcache.DefaultPluginScanConfig;
4142
import org.apache.maven.buildcache.hash.HashFactory;
43+
import org.apache.maven.buildcache.xml.config.AttachedOutputs;
4244
import org.apache.maven.buildcache.xml.config.Configuration;
45+
import org.apache.maven.buildcache.xml.config.DirName;
4346
import org.apache.maven.buildcache.xml.config.Remote;
4447
import org.apache.maven.execution.MavenExecutionRequest;
4548
import org.apache.maven.execution.MavenSession;
@@ -482,4 +485,45 @@ void testRemoveSaveFinalIgnoredWhenRemoteSaveDisabled() {
482485
Pair.of("getUrl", () -> assertEquals("dummy.url.xyz", testObject.getUrl())),
483486
Pair.of("isRemoteCacheEnabled", () -> assertTrue(testObject.isRemoteCacheEnabled())));
484487
}
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+
}
485529
}

0 commit comments

Comments
 (0)