Skip to content

Commit 2d773e5

Browse files
authored
Fix mentionee class' inheritance. (#996)
And add test cases for record classes.
1 parent f72efe6 commit 2d773e5

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
}

line-bot-webhook/src/main/java/com/linecorp/bot/webhook/model/UnknownMentionee.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616

1717
package com.linecorp.bot.webhook.model;
1818

19-
public record UnknownMentionee(String userId) implements Source {
19+
public record UnknownMentionee(String userId) implements Mentionee {
2020
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.webhook.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(Event.class, UnknownEvent.class),
49+
arguments(Mentionee.class, UnknownMentionee.class),
50+
arguments(MessageContent.class, UnknownMessageContent.class),
51+
arguments(ModuleContent.class, UnknownModuleContent.class),
52+
arguments(Source.class, UnknownSource.class),
53+
arguments(ThingsContent.class, UnknownThingsContent.class)
54+
);
55+
}
56+
}

0 commit comments

Comments
 (0)