2323import java .io .ByteArrayInputStream ;
2424import java .io .ByteArrayOutputStream ;
2525import java .io .IOException ;
26+ import java .io .Serializable ;
2627import java .sql .Timestamp ;
28+ import java .time .LocalTime ;
29+ import java .util .ArrayList ;
2730import java .util .Date ;
31+ import java .util .List ;
2832
33+ import org .apache .dubbo .common .serialize .model .SerializablePerson ;
2934import org .junit .jupiter .api .BeforeEach ;
3035import org .junit .jupiter .api .Test ;
3136
@@ -70,6 +75,75 @@ public void testSerializeSqlDate() throws IOException, ClassNotFoundException {
7075 assertThat (serializedTime , is (originTime ));
7176 }
7277
78+ @ Test
79+ public void testObjectList () throws IOException , ClassNotFoundException {
80+ List <SerializablePerson > args = new ArrayList <SerializablePerson >();
81+ args .add (new SerializablePerson ());
82+
83+ this .protostuffObjectOutput .writeObject (args );
84+ this .flushToInput ();
85+
86+ List <SerializablePerson > serializedTime = (List <SerializablePerson >) protostuffObjectInput .readObject ();
87+ assertThat (serializedTime , is (args ));
88+ }
89+
90+ @ Test
91+ public void testCustomizeDateList () throws IOException , ClassNotFoundException {
92+ java .sql .Date originTime = new java .sql .Date (System .currentTimeMillis ());
93+ java .sql .Date yesterdayTime = new java .sql .Date (System .currentTimeMillis () + 30 *60 *1000 );
94+ java .sql .Date beforeTime = new java .sql .Date (System .currentTimeMillis () + 30 *60 *1000 *4 );
95+ List <java .sql .Date > list = new ArrayList <>();
96+
97+ list .add (originTime );
98+ list .add (yesterdayTime );
99+ list .add (beforeTime );
100+
101+ this .protostuffObjectOutput .writeObject (list );
102+ this .flushToInput ();
103+
104+ List <java .sql .Date > serializedTimeList = (List <java .sql .Date >) protostuffObjectInput .readObject ();
105+ assertThat (serializedTimeList , is (list ));
106+ }
107+
108+ @ Test
109+ public void testCustomizeTimeList () throws IOException , ClassNotFoundException {
110+
111+ List <LocalTime > list = new ArrayList <LocalTime >();
112+
113+ LocalTime localTime = LocalTime .parse ("12:00:00" );
114+ LocalTime localSecondTime = LocalTime .parse ("13:00:00" );
115+ LocalTime localThirdTime = LocalTime .parse ("14:00:00" );
116+ list .add (localTime );
117+ list .add (localSecondTime );
118+ list .add (localThirdTime );
119+
120+ LocalTimeList timeList = new LocalTimeList (list );
121+ this .protostuffObjectOutput .writeObject (timeList );
122+ this .flushToInput ();
123+
124+ LocalTimeList serializedTime = protostuffObjectInput .readObject (LocalTimeList .class );
125+ assertThat (serializedTime , is (timeList ));
126+ }
127+
128+ @ Test
129+ public void testListObject () throws IOException , ClassNotFoundException {
130+
131+ List <SerializablePerson > list = new ArrayList <SerializablePerson >();
132+
133+ list .add (new SerializablePerson ());
134+ list .add (new SerializablePerson ());
135+ list .add (new SerializablePerson ());
136+
137+ SerializablePersonList personList = new SerializablePersonList (list );
138+
139+ this .protostuffObjectOutput .writeObject (personList );
140+ this .flushToInput ();
141+
142+ SerializablePersonList serializedTime = protostuffObjectInput .readObject (SerializablePersonList .class );
143+ assertThat (serializedTime , is (personList ));
144+ }
145+
146+
73147 @ Test
74148 public void testSerializeSqlTime () throws IOException , ClassNotFoundException {
75149 java .sql .Time originTime = new java .sql .Time (System .currentTimeMillis ());
@@ -95,4 +169,74 @@ private void flushToInput() throws IOException {
95169 this .byteArrayInputStream = new ByteArrayInputStream (byteArrayOutputStream .toByteArray ());
96170 this .protostuffObjectInput = new ProtostuffObjectInput (byteArrayInputStream );
97171 }
172+
173+ private static class SerializablePersonList implements Serializable {
174+ private static final long serialVersionUID = 1L ;
175+
176+ public List <SerializablePerson > personList ;
177+
178+ public SerializablePersonList () {}
179+
180+ public SerializablePersonList (List <SerializablePerson > list ) {
181+ this .personList = list ;
182+ }
183+
184+ @ Override
185+ public boolean equals (Object obj ) {
186+ if (this == obj )
187+ return true ;
188+ if (obj == null )
189+ return false ;
190+ if (getClass () != obj .getClass ())
191+ return false ;
192+
193+ SerializablePersonList list = (SerializablePersonList ) obj ;
194+ if (list .personList == null && this .personList == null )
195+ return true ;
196+ if (list .personList == null || this .personList == null )
197+ return false ;
198+ if (list .personList .size () != this .personList .size ())
199+ return false ;
200+ for (int i =0 ; i < this .personList .size (); i ++) {
201+ if (!this .personList .get (i ).equals (list .personList .get (i )))
202+ return false ;
203+ }
204+ return true ;
205+ }
206+ }
207+
208+ private static class LocalTimeList implements Serializable {
209+ private static final long serialVersionUID = 1L ;
210+
211+ List <LocalTime > timeList ;
212+
213+ public LocalTimeList () {}
214+
215+ public LocalTimeList (List <LocalTime > timeList ) {
216+ this .timeList = timeList ;
217+ }
218+
219+ @ Override
220+ public boolean equals (Object obj ) {
221+ if (this == obj )
222+ return true ;
223+ if (obj == null )
224+ return false ;
225+ if (getClass () != obj .getClass ())
226+ return false ;
227+
228+ LocalTimeList timeList = (LocalTimeList ) obj ;
229+ if (timeList .timeList == null && this .timeList == null )
230+ return true ;
231+ if (timeList .timeList == null || this .timeList == null )
232+ return false ;
233+ if (timeList .timeList .size () != this .timeList .size ())
234+ return false ;
235+ for (int i =0 ; i < this .timeList .size (); i ++) {
236+ if (!this .timeList .get (i ).equals (timeList .timeList .get (i )))
237+ return false ;
238+ }
239+ return true ;
240+ }
241+ }
98242}
0 commit comments