1+ /*
2+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
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+ * A copy of the License is located at
7+ *
8+ * http://aws.amazon.com/apache2.0
9+ *
10+ * or in the "license" file accompanying this file. This file is distributed
11+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+ * express or implied. See the License for the specific language governing
13+ * permissions and limitations under the License.
14+ */
15+
16+ package software .amazon .awssdk .utilslite ;
17+
18+ import org .junit .jupiter .api .AfterEach ;
19+ import org .junit .jupiter .api .Test ;
20+
21+ import static org .assertj .core .api .Assertions .assertThat ;
22+
23+ class SdkInternalThreadLocalTest {
24+
25+ @ AfterEach
26+ void cleanup () {
27+ SdkInternalThreadLocal .clear ();
28+ }
29+
30+ @ Test
31+ void putAndGet_shouldStoreAndRetrieveValue () {
32+ SdkInternalThreadLocal .put ("test-key" , "test-value" );
33+
34+ assertThat (SdkInternalThreadLocal .get ("test-key" )).isEqualTo ("test-value" );
35+ }
36+
37+ @ Test
38+ void get_withNonExistentKey_shouldReturnNull () {
39+ assertThat (SdkInternalThreadLocal .get ("non-existent" )).isNull ();
40+ }
41+
42+ @ Test
43+ void put_withValidKeyValue_shouldStoreValue () {
44+ SdkInternalThreadLocal .put ("test-key" , "test-value" );
45+
46+ String removed = SdkInternalThreadLocal .remove ("test-key" );
47+
48+ assertThat (removed ).isEqualTo ("test-value" );
49+ assertThat (SdkInternalThreadLocal .get ("test-key" )).isNull ();
50+ }
51+
52+ @ Test
53+ void remove_withExistingKey_shouldRemoveAndReturnValue () {
54+ SdkInternalThreadLocal .put ("test-key" , "test-value" );
55+ SdkInternalThreadLocal .put ("test-key" , null );
56+
57+ assertThat (SdkInternalThreadLocal .get ("test-key" )).isNull ();
58+ }
59+
60+ @ Test
61+ void clear_withMultipleValues_shouldRemoveAllValues () {
62+ SdkInternalThreadLocal .put ("key1" , "value1" );
63+ SdkInternalThreadLocal .put ("key2" , "value2" );
64+
65+ SdkInternalThreadLocal .clear ();
66+
67+ assertThat (SdkInternalThreadLocal .get ("key1" )).isNull ();
68+ assertThat (SdkInternalThreadLocal .get ("key2" )).isNull ();
69+ }
70+ }
0 commit comments