Skip to content

Commit b3a2322

Browse files
committed
Add test property impl that exports to Set again
- Point of the test that a Set is handled properly, but all standard collection property types will produce a list as export value
1 parent 3616eb9 commit b3a2322

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/test/java/ch/jalu/configme/resource/YamlSetPropertyExportTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import ch.jalu.configme.configurationdata.ConfigurationDataBuilder;
66
import ch.jalu.configme.properties.EnumSetProperty;
77
import ch.jalu.configme.samples.TestEnum;
8+
import org.jetbrains.annotations.NotNull;
89
import org.junit.jupiter.api.BeforeEach;
910
import org.junit.jupiter.api.Test;
1011
import org.junit.jupiter.api.io.TempDir;
@@ -13,6 +14,9 @@
1314
import java.nio.file.Files;
1415
import java.nio.file.Path;
1516
import java.util.EnumSet;
17+
import java.util.LinkedHashSet;
18+
import java.util.Set;
19+
import java.util.stream.Collectors;
1620

1721
import static java.util.Collections.singletonList;
1822
import static org.hamcrest.MatcherAssert.assertThat;
@@ -39,7 +43,7 @@ void copyConfigFile() {
3943
void shouldLoadAndExportProperly() throws IOException {
4044
// given
4145
PropertyResource resource = new YamlFileResource(configFile);
42-
EnumSetProperty<TestEnum> setProperty = new EnumSetProperty<>("sample.ratio.fields", TestEnum.class);
46+
EnumSetProperty<TestEnum> setProperty = new ExportToSetProperty("sample.ratio.fields");
4347
ConfigurationData configurationData = ConfigurationDataBuilder.createConfiguration(singletonList(setProperty));
4448
configurationData.setValue(setProperty, EnumSet.of(TestEnum.FIRST, TestEnum.SECOND, TestEnum.THIRD));
4549

@@ -58,4 +62,18 @@ void shouldLoadAndExportProperly() throws IOException {
5862
" - SECOND",
5963
" - THIRD"));
6064
}
65+
66+
private static final class ExportToSetProperty extends EnumSetProperty<TestEnum> {
67+
68+
ExportToSetProperty(String path) {
69+
super(path, TestEnum.class, EnumSet.noneOf(TestEnum.class));
70+
}
71+
72+
@Override
73+
public Set<String> toExportValue(@NotNull EnumSet<TestEnum> value) {
74+
return value.stream()
75+
.map(Enum::name)
76+
.collect(Collectors.toCollection(LinkedHashSet::new));
77+
}
78+
}
6179
}

0 commit comments

Comments
 (0)