56
56
import java .util .ArrayList ;
57
57
import java .util .Arrays ;
58
58
import java .util .Calendar ;
59
+ import java .util .Collection ;
59
60
import java .util .Collections ;
60
61
import java .util .Date ;
61
62
import java .util .HashMap ;
62
63
import java .util .LinkedHashMap ;
63
64
import java .util .List ;
64
65
import java .util .Map ;
66
+ import java .util .Set ;
65
67
import java .util .UUID ;
68
+ import java .util .stream .Stream ;
66
69
70
+ import org .assertj .core .api .InstanceOfAssertFactories ;
67
71
import org .junit .jupiter .api .BeforeEach ;
68
72
import org .junit .jupiter .api .Test ;
69
73
import org .junit .jupiter .api .extension .ExtendWith ;
74
+ import org .junit .jupiter .params .ParameterizedTest ;
75
+ import org .junit .jupiter .params .provider .Arguments ;
76
+ import org .junit .jupiter .params .provider .MethodSource ;
70
77
import org .mockito .Mock ;
71
78
import org .mockito .junit .jupiter .MockitoExtension ;
72
79
import org .springframework .core .convert .converter .Converter ;
@@ -1997,20 +2004,18 @@ void readGenericEntity() {
1997
2004
1998
2005
@ Test // GH-2168, GH-3179
1999
2006
void writePlainList () {
2007
+
2000
2008
List <Object > source = Arrays .asList ("Hello" , "stream" , "message" , 100L );
2001
2009
RedisTestData target = write (source );
2002
- Object classValue = target .getBucket ().get ("_class" );
2003
2010
2004
- assertThat (classValue )
2005
- .as ("_class metadata should be written" )
2006
- .isNotNull ()
2007
- .isInstanceOf (byte [].class );
2008
- assertThat (new String ((byte []) classValue , StandardCharsets .UTF_8 ))
2009
- .isEqualTo (ClassUtils .getUserClass (source ).getName ());
2010
- assertThat (target ).containsEntry ("[0]" , "Hello" )
2011
- .containsEntry ("[1]" , "stream" )
2012
- .containsEntry ("[2]" , "message" )
2013
- .containsEntry ("[3]" , "100" );
2011
+ assertThat (target ) //
2012
+ .containsEntry ("_class" , "java.util.List" ) //
2013
+ .containsEntry ("[0]" , "Hello" ) //
2014
+ .containsEntry ("[0]._class" , "java.lang.String" ) //
2015
+ .containsEntry ("[1]" , "stream" ) //
2016
+ .containsEntry ("[2]" , "message" ) //
2017
+ .containsEntry ("[3]" , "100" ) //
2018
+ .containsEntry ("[3]._class" , "java.lang.Long" );
2014
2019
}
2015
2020
2016
2021
@ Test // DATAREDIS-1175
@@ -2031,6 +2036,21 @@ void readPlainList() {
2031
2036
assertThat (target ).containsExactly ("Hello" , "stream" , "message" , 100L );
2032
2037
}
2033
2038
2039
+ @ ParameterizedTest // GH-3179
2040
+ @ MethodSource ("justCollections" )
2041
+ void readsPlainCollectionIfObjectTypeRequested (Class <?> type , Collection <Object > collection ) {
2042
+
2043
+ RedisTestData source = write (collection );
2044
+
2045
+ Object target = this .converter .read (Object .class , source .getRedisData ());
2046
+
2047
+ assertThat (target ).isInstanceOf (type ).asInstanceOf (InstanceOfAssertFactories .COLLECTION ).containsExactlyElementsOf (collection );
2048
+ }
2049
+
2050
+ private static Stream <Arguments > justCollections () {
2051
+ return Stream .of (Arguments .of (List .class , Arrays .asList ("Hello" , "stream" , "message" , 100L )), Arguments .of (Set .class , Set .of ("Hello" , "stream" , "message" , 100L )));
2052
+ }
2053
+
2034
2054
private RedisTestData write (Object source ) {
2035
2055
2036
2056
RedisData rdo = new RedisData ();
0 commit comments