16
16
package software .amazon .awssdk .core .util ;
17
17
18
18
import static org .assertj .core .api .Assertions .assertThat ;
19
+ import static org .junit .Assert .assertNotNull ;
20
+ import static org .junit .jupiter .api .Assertions .assertSame ;
19
21
22
+ import java .io .ByteArrayInputStream ;
23
+ import java .io .ByteArrayOutputStream ;
24
+ import java .io .ObjectInputStream ;
25
+ import java .io .ObjectOutputStream ;
20
26
import java .util .HashMap ;
21
27
import org .junit .jupiter .api .Test ;
22
28
@@ -41,4 +47,25 @@ public void hashCode_sameAsEmptyMap() {
41
47
public void toString_emptyMap () {
42
48
assertThat (AUTO_CONSTRUCT_MAP .toString ()).isEqualTo ("{}" );
43
49
}
50
+
51
+ @ Test
52
+ public void serialization_sameSingletonInstance () throws Exception {
53
+ DefaultSdkAutoConstructMap <?, ?> originalInstance = DefaultSdkAutoConstructMap .getInstance ();
54
+
55
+ // Serialize the object
56
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream ();
57
+ ObjectOutputStream objectOut = new ObjectOutputStream (byteOut );
58
+ objectOut .writeObject (originalInstance );
59
+ objectOut .close ();
60
+
61
+ // Deserialize the object
62
+ ByteArrayInputStream byteIn = new ByteArrayInputStream (byteOut .toByteArray ());
63
+ ObjectInputStream objectIn = new ObjectInputStream (byteIn );
64
+ DefaultSdkAutoConstructMap <?, ?> deserializedInstance = (DefaultSdkAutoConstructMap <?, ?>) objectIn .readObject ();
65
+ objectIn .close ();
66
+
67
+ // Assert that deserialization was successful
68
+ assertNotNull (deserializedInstance );
69
+ assertSame (originalInstance , deserializedInstance , "Deserialized instance should be the same singleton instance" );
70
+ }
44
71
}
0 commit comments