|
| 1 | +package ch.jalu.configme.properties; |
| 2 | + |
| 3 | +import ch.jalu.configme.properties.convertresult.PropertyValue; |
| 4 | +import ch.jalu.configme.resource.PropertyReader; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 7 | +import org.mockito.Mock; |
| 8 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 9 | + |
| 10 | +import java.util.EnumSet; |
| 11 | +import java.util.Set; |
| 12 | + |
| 13 | +import static ch.jalu.configme.TestUtils.isErrorValueOf; |
| 14 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 15 | +import static org.mockito.BDDMockito.given; |
| 16 | + |
| 17 | +/** |
| 18 | + * Test for {@link EnumSetProperty}. |
| 19 | + */ |
| 20 | +@ExtendWith(MockitoExtension.class) |
| 21 | +class EnumSetPropertyTest { |
| 22 | + |
| 23 | + @Mock |
| 24 | + private PropertyReader reader; |
| 25 | + |
| 26 | + @Test |
| 27 | + void shouldReturnEnumSetDefaultValue() { |
| 28 | + // given |
| 29 | + EnumSet<TestEnum> set = EnumSet.of(TestEnum.ENTRY_A); |
| 30 | + EnumSetProperty<TestEnum> property = |
| 31 | + new EnumSetProperty<>("enum.path", TestEnum.class, set); |
| 32 | + given(reader.getObject(property.getPath())) |
| 33 | + .willReturn(null); |
| 34 | + |
| 35 | + // when |
| 36 | + PropertyValue<Set<TestEnum>> result = property.determineValue(reader); |
| 37 | + |
| 38 | + // then |
| 39 | + assertThat(result, isErrorValueOf(EnumSet.of(TestEnum.ENTRY_A))); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void shouldReturnEnumSetDefaultValueFromArray() { |
| 44 | + // given |
| 45 | + EnumSetProperty<TestEnum> property = |
| 46 | + new EnumSetProperty<>("enum.path", TestEnum.class, new TestEnum[]{TestEnum.ENTRY_B, TestEnum.ENTRY_C}); |
| 47 | + given(reader.getObject(property.getPath())) |
| 48 | + .willReturn(null); |
| 49 | + |
| 50 | + // when |
| 51 | + PropertyValue<Set<TestEnum>> result = property.determineValue(reader); |
| 52 | + |
| 53 | + // then |
| 54 | + assertThat(result, isErrorValueOf(EnumSet.of(TestEnum.ENTRY_B, TestEnum.ENTRY_C))); |
| 55 | + } |
| 56 | + |
| 57 | + private enum TestEnum { |
| 58 | + |
| 59 | + ENTRY_A, |
| 60 | + |
| 61 | + ENTRY_B, |
| 62 | + |
| 63 | + ENTRY_C |
| 64 | + |
| 65 | + } |
| 66 | +} |
0 commit comments