Merge pull request #14234 from thibaultfaure/article/BAEL-5977
BAEL-5977 Code for the Throw Exception for Unexpected Input for Enum …
This commit is contained in:
commit
95ce4116d3
|
@ -73,7 +73,7 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<org.mapstruct.version>1.5.3.Final</org.mapstruct.version>
|
<org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
|
||||||
<springframework.version>4.3.4.RELEASE</springframework.version>
|
<springframework.version>4.3.4.RELEASE</springframework.version>
|
||||||
<lombok.mapstruct.binding.version>0.2.0</lombok.mapstruct.binding.version>
|
<lombok.mapstruct.binding.version>0.2.0</lombok.mapstruct.binding.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.baeldung.enums;
|
||||||
|
|
||||||
|
enum InputLevel {
|
||||||
|
|
||||||
|
LOW, MEDIUM, HIGH
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.baeldung.enums;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.MappingConstants;
|
||||||
|
import org.mapstruct.ValueMapping;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
interface LevelMapper {
|
||||||
|
|
||||||
|
@ValueMapping(source = MappingConstants.ANY_REMAINING, target = MappingConstants.THROW_EXCEPTION)
|
||||||
|
OutputLevel inputLevelToOutputLevel(InputLevel inputLevel);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.baeldung.enums;
|
||||||
|
|
||||||
|
enum OutputLevel {
|
||||||
|
|
||||||
|
LOW, HIGH
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.baeldung.enums;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
class LevelMapperUnitTest {
|
||||||
|
|
||||||
|
LevelMapper levelMapper = Mappers.getMapper(LevelMapper.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenHighInputLevel_WhenInputLevelToOutputLevel_ThenHighOutputLevel() {
|
||||||
|
assertEquals(OutputLevel.HIGH, levelMapper.inputLevelToOutputLevel(InputLevel.HIGH));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenMediumInputLevel_WhenInputLevelToOutputLevel_ThenThrows() {
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> levelMapper.inputLevelToOutputLevel(InputLevel.MEDIUM));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenLowInputLevel_WhenInputLevelToOutputLevel_ThenLowOutputLevel() {
|
||||||
|
assertEquals(OutputLevel.LOW, levelMapper.inputLevelToOutputLevel(InputLevel.LOW));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue