Skip to content

Commit 143d341

Browse files
mp911dechristophstrobl
authored andcommitted
DATAREDIS-1245 - Consider List subtypes used with RedisScript as MULTI return type.
We now consider List and subtypes of List to be returned as MULTI return type. Previously, List subtypes were considered to represent the value type. Original Pull Request: #571
1 parent 62f9da6 commit 143d341

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/main/java/org/springframework/data/redis/connection/ReturnType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*
2626
* @author Jennifer Hickey
2727
* @author Christoph Strobl
28+
* @author Mark Paluch
2829
*/
2930
public enum ReturnType {
3031

@@ -62,15 +63,19 @@ public static ReturnType fromJavaType(@Nullable Class<?> javaType) {
6263
if (javaType == null) {
6364
return ReturnType.STATUS;
6465
}
65-
if (javaType.isAssignableFrom(List.class)) {
66+
67+
if (List.class.isAssignableFrom(javaType)) {
6668
return ReturnType.MULTI;
6769
}
70+
6871
if (javaType.isAssignableFrom(Boolean.class)) {
6972
return ReturnType.BOOLEAN;
7073
}
74+
7175
if (javaType.isAssignableFrom(Long.class)) {
7276
return ReturnType.INTEGER;
7377
}
78+
7479
return ReturnType.VALUE;
7580
}
7681
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://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,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.redis.connection;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
20+
import java.util.ArrayList;
21+
import java.util.LinkedList;
22+
import java.util.List;
23+
24+
import org.junit.jupiter.params.ParameterizedTest;
25+
import org.junit.jupiter.params.provider.ValueSource;
26+
27+
/**
28+
* Unit tests for {@link ReturnType}.
29+
*
30+
* @author Mark Paluch
31+
*/
32+
class ReturnTypeUnitTests {
33+
34+
@ParameterizedTest // DATAREDIS-1245
35+
@ValueSource(classes = { List.class, ArrayList.class, LinkedList.class })
36+
void shouldConsiderListsAsMultiType(Class<?> listClass) {
37+
38+
assertThat(ReturnType.fromJavaType(listClass)).isEqualTo(ReturnType.MULTI);
39+
}
40+
41+
}

0 commit comments

Comments
 (0)