55import ch .jalu .configme .configurationdata .ConfigurationDataBuilder ;
66import ch .jalu .configme .properties .EnumSetProperty ;
77import ch .jalu .configme .samples .TestEnum ;
8+ import org .jetbrains .annotations .NotNull ;
89import org .junit .jupiter .api .BeforeEach ;
910import org .junit .jupiter .api .Test ;
1011import org .junit .jupiter .api .io .TempDir ;
1314import java .nio .file .Files ;
1415import java .nio .file .Path ;
1516import java .util .EnumSet ;
17+ import java .util .LinkedHashSet ;
18+ import java .util .Set ;
19+ import java .util .stream .Collectors ;
1620
1721import static java .util .Collections .singletonList ;
1822import 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