|
| 1 | +/* |
| 2 | + * Copyright 2023 LINE Corporation |
| 3 | + * |
| 4 | + * LINE Corporation licenses this file to you under the Apache License, |
| 5 | + * version 2.0 (the "License"); you may not use this file except in compliance |
| 6 | + * with the License. You may obtain a copy of the License at: |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations |
| 14 | + * under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.linecorp.bot.messaging.model; |
| 18 | + |
| 19 | +import static org.assertj.core.api.Assertions.assertThat; |
| 20 | +import static org.junit.jupiter.params.provider.Arguments.arguments; |
| 21 | + |
| 22 | +import java.util.stream.Stream; |
| 23 | + |
| 24 | +import org.junit.jupiter.params.ParameterizedTest; |
| 25 | +import org.junit.jupiter.params.provider.Arguments; |
| 26 | +import org.junit.jupiter.params.provider.MethodSource; |
| 27 | + |
| 28 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 29 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
| 30 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 31 | + |
| 32 | +class UnknownFallbackTest { |
| 33 | + ObjectMapper objectMapper = new ObjectMapper() |
| 34 | + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) |
| 35 | + .enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE); |
| 36 | + |
| 37 | + @ParameterizedTest |
| 38 | + @MethodSource("targets") |
| 39 | + void testUnknownFallback(Class<?> klass, Class<?> target) throws JsonProcessingException { |
| 40 | + Object object = objectMapper.readValue(""" |
| 41 | + {"type":"great-new-thing"} |
| 42 | + """, klass); |
| 43 | + assertThat(object).isInstanceOf(target); |
| 44 | + } |
| 45 | + |
| 46 | + public static Stream<Arguments> targets() { |
| 47 | + return Stream.of( |
| 48 | + arguments(Action.class, UnknownAction.class), |
| 49 | + arguments(DemographicFilter.class, UnknownDemographicFilter.class), |
| 50 | + arguments(FlexBoxBackground.class, UnknownFlexBoxBackground.class), |
| 51 | + arguments(FlexComponent.class, UnknownFlexComponent.class), |
| 52 | + arguments(FlexContainer.class, UnknownFlexContainer.class), |
| 53 | + arguments(ImagemapAction.class, UnknownImagemapAction.class), |
| 54 | + arguments(Message.class, UnknownMessage.class), |
| 55 | + arguments(Recipient.class, UnknownRecipient.class), |
| 56 | + arguments(Template.class, UnknownTemplate.class) |
| 57 | + ); |
| 58 | + } |
| 59 | +} |
0 commit comments