BAEL-5977 Code for the Throw Exception for Unexpected Input for Enum with Mapstruct article

This commit is contained in:
thibault.faure
2023-06-06 23:02:22 +02:00
parent 880803be21
commit 3a078d7c9c
5 changed files with 56 additions and 1 deletions
@@ -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));
}
}