16
16
17
17
package org .springframework .util ;
18
18
19
+ import java .io .NotSerializableException ;
20
+ import java .io .Serializable ;
19
21
import java .math .BigInteger ;
20
22
21
23
import org .junit .jupiter .api .Test ;
28
30
* Unit tests for {@link SerializationUtils}.
29
31
*
30
32
* @author Dave Syer
33
+ * @author Sam Brannen
31
34
* @since 3.0.5
32
35
*/
33
36
class SerializationUtilsTests {
@@ -43,6 +46,24 @@ void serializeCycleSunnyDay() {
43
46
assertThat (SerializationUtils .deserialize (SerializationUtils .serialize ("foo" ))).isEqualTo ("foo" );
44
47
}
45
48
49
+ @ Test
50
+ @ SuppressWarnings ("deprecation" )
51
+ void serializeNonSerializableRecord () {
52
+ record Person (String firstName , String lastName ) {}
53
+ Person jane = new Person ("Jane" , "Doe" );
54
+ assertThatIllegalArgumentException ()
55
+ .isThrownBy (() -> SerializationUtils .serialize (jane ))
56
+ .withCauseExactlyInstanceOf (NotSerializableException .class );
57
+ }
58
+
59
+ @ Test
60
+ @ SuppressWarnings ("deprecation" )
61
+ void serializeAndDeserializeSerializableRecord () {
62
+ record Person (String firstName , String lastName ) implements Serializable {}
63
+ Person jane = new Person ("Jane" , "Doe" );
64
+ assertThat (SerializationUtils .deserialize (SerializationUtils .serialize (jane ))).isEqualTo (jane );
65
+ }
66
+
46
67
@ Test
47
68
@ SuppressWarnings ("deprecation" )
48
69
void deserializeUndefined () {
0 commit comments