1515import java .util .HashMap ;
1616import java .util .Map ;
1717import java .util .function .BiConsumer ;
18+ import javax .annotation .ParametersAreNonnullByDefault ;
1819import org .junit .jupiter .api .BeforeEach ;
1920import org .junit .jupiter .api .Test ;
2021import org .tabletest .junit .TableTest ;
@@ -28,6 +29,7 @@ class BaggagePropagatorTest extends DDJavaSpecification {
2829 private Map <String , String > carrier ;
2930 private Context context ;
3031
32+ @ ParametersAreNonnullByDefault
3133 static class MapCarrierAccessor
3234 implements CarrierSetter <Map <String , String >>, CarrierVisitor <Map <String , String >> {
3335 @ Override
@@ -78,7 +80,7 @@ void testBaggagePropagatorContextInjection(Map<String, String> baggageMap, Strin
7880 "third entry dropped | [key1: val1, key2: val2, key3: val3] | 'key1=val1,key2=val2'"
7981 })
8082 void testBaggageInjectItemLimit (Map <String , String > baggage , String baggageHeader ) {
81- // creating a new instance after injecting config
83+ // Creating propagator with test item limit
8284 propagator = new BaggagePropagator (true , true , 2 , DEFAULT_TRACE_BAGGAGE_MAX_BYTES );
8385 context = Baggage .create (baggage ).storeInto (context );
8486
@@ -94,7 +96,7 @@ void testBaggageInjectItemLimit(Map<String, String> baggage, String baggageHeade
9496 "single entry exceeds bytes once encoded | [abcdefg: 'hijklmnopq♥'] | '' "
9597 })
9698 void testBaggageInjectBytesLimit (Map <String , String > baggage , String baggageHeader ) {
97- // creating a new instance after injecting config
99+ // Creating propagator with test bytes limit
98100 propagator = new BaggagePropagator (true , true , DEFAULT_TRACE_BAGGAGE_MAX_ITEMS , 20 );
99101 context = Baggage .create (baggage ).storeInto (context );
100102
@@ -113,7 +115,9 @@ void testTracingPropagatorContextExtractor(String baggageHeader, Map<String, Str
113115
114116 context = this .propagator .extract (context , headers , ContextVisitors .stringValuesMap ());
115117
116- assertEquals (baggageMap , Baggage .fromContext (context ).asMap ());
118+ Baggage baggage = Baggage .fromContext (context );
119+ assertNotNull (baggage );
120+ assertEquals (baggageMap , baggage .asMap ());
117121 }
118122
119123 @ Test
@@ -123,7 +127,7 @@ void testExtractingNonAsciiHeaders() {
123127 context = this .propagator .extract (context , headers , ContextVisitors .stringValuesMap ());
124128 Baggage baggage = Baggage .fromContext (context );
125129
126- // non ASCII values data are still accessible as part of the API
130+ // non- ASCII values data are still accessible as part of the API
127131 assertNotNull (baggage );
128132 assertEquals ("vallée" , baggage .asMap ().get ("key1" ));
129133 assertEquals ("value" , baggage .asMap ().get ("clé2" ));
@@ -163,8 +167,9 @@ void testBaggageCache(String baggageHeader, String cachedString) {
163167
164168 context = this .propagator .extract (context , headers , ContextVisitors .stringValuesMap ());
165169
166- Baggage baggageContext = Baggage .fromContext (context );
167- assertEquals (cachedString , baggageContext .getW3cHeader ());
170+ Baggage baggage = Baggage .fromContext (context );
171+ assertNotNull (baggage );
172+ assertEquals (cachedString , baggage .getW3cHeader ());
168173 }
169174
170175 @ TableTest ({
@@ -180,24 +185,26 @@ void testBaggageCacheItemsLimit(String baggageHeader, String cachedString) {
180185
181186 context = this .propagator .extract (context , headers , ContextVisitors .stringValuesMap ());
182187
183- Baggage baggageContext = Baggage .fromContext (context );
184- assertEquals (cachedString , baggageContext .getW3cHeader ());
188+ Baggage baggage = Baggage .fromContext (context );
189+ assertNotNull (baggage );
190+ assertEquals (cachedString , baggage .getW3cHeader ());
185191 }
186192
187193 @ TableTest ({
188194 "scenario | baggageHeader | cachedString " ,
189195 "limit not reached | 'key1=val1,key2=val2' | 'key1=val1,key2=val2'" ,
190196 "third entry truncates | 'key1=val1,key2=val2,key3=val3' | 'key1=val1,key2=val2'"
191197 })
192- void testBaggageCacheBytesLimit (String scenario , String baggageHeader , String cachedString ) {
193- // creating a new instance after injecting config
198+ void testBaggageCacheBytesLimit (String baggageHeader , String cachedString ) {
199+ // Creating propagator with test bytes limit
194200 propagator = new BaggagePropagator (true , true , DEFAULT_TRACE_BAGGAGE_MAX_ITEMS , 20 );
195201 Map <String , String > headers = singletonMap (BAGGAGE_KEY , baggageHeader );
196202
197203 context = this .propagator .extract (context , headers , ContextVisitors .stringValuesMap ());
198204
199- Baggage baggageContext = Baggage .fromContext (context );
200- assertEquals (cachedString , baggageContext .getW3cHeader ());
205+ Baggage baggage = Baggage .fromContext (context );
206+ assertNotNull (baggage );
207+ assertEquals (cachedString , baggage .getW3cHeader ());
201208 }
202209
203210 @ TableTest ({
@@ -207,14 +214,16 @@ void testBaggageCacheBytesLimit(String scenario, String baggageHeader, String ca
207214 "third entry dropped | 'key1=val1,key2=val2,key3=val3' | [key1: val1, key2: val2]"
208215 })
209216 void testBaggageExtractItemsLimit (String baggageHeader , Map <String , String > baggageMap ) {
210- // creating a new instance after injecting config
217+ // Creating propagator with test item limit
211218 propagator = new BaggagePropagator (true , true , 2 , DEFAULT_TRACE_BAGGAGE_MAX_BYTES );
212219 Map <String , String > headers = singletonMap (BAGGAGE_KEY , baggageHeader );
213220
214221 context = this .propagator .extract (context , headers , ContextVisitors .stringValuesMap ());
215222
216223 // parsing stops once the item limit is exceeded
217- assertEquals (baggageMap , Baggage .fromContext (context ).asMap ());
224+ Baggage baggage = Baggage .fromContext (context );
225+ assertNotNull (baggage );
226+ assertEquals (baggageMap , baggage .asMap ());
218227 }
219228
220229 @ TableTest ({
@@ -224,14 +233,16 @@ void testBaggageExtractItemsLimit(String baggageHeader, Map<String, String> bagg
224233 "third entry dropped | 'key1=val1,key2=val2,key3=val3' | [key1: val1, key2: val2]"
225234 })
226235 void testBaggageExtractBytesLimit (String baggageHeader , Map <String , String > baggageMap ) {
227- // creating a new instance after injecting config
236+ // Creating propagator with test bytes limit
228237 propagator = new BaggagePropagator (true , true , DEFAULT_TRACE_BAGGAGE_MAX_ITEMS , 20 );
229238 Map <String , String > headers = singletonMap (BAGGAGE_KEY , baggageHeader );
230239
231240 context = this .propagator .extract (context , headers , ContextVisitors .stringValuesMap ());
232241
233242 // parsing stops once the byte limit is exceeded
234- assertEquals (baggageMap , Baggage .fromContext (context ).asMap ());
243+ Baggage baggage = Baggage .fromContext (context );
244+ assertNotNull (baggage );
245+ assertEquals (baggageMap , baggage .asMap ());
235246 }
236247
237248 @ Test
0 commit comments