29
29
import java .util .List ;
30
30
import java .util .Map ;
31
31
import java .util .function .Supplier ;
32
-
33
32
import static org .hamcrest .Matchers .equalTo ;
34
33
import static org .hamcrest .Matchers .hasItem ;
35
34
import static org .hamcrest .Matchers .hasSize ;
@@ -215,8 +214,8 @@ public void testResponseHeaders() {
215
214
public void testCopyHeaders () {
216
215
Settings build = Settings .builder ().put ("request.headers.default" , "1" ).build ();
217
216
ThreadContext threadContext = new ThreadContext (build );
218
- threadContext .copyHeaders (Collections .<String ,String >emptyMap ().entrySet ());
219
- threadContext .copyHeaders (Collections .<String ,String >singletonMap ("foo" , "bar" ).entrySet ());
217
+ threadContext .copyHeaders (Collections .<String , String >emptyMap ().entrySet ());
218
+ threadContext .copyHeaders (Collections .<String , String >singletonMap ("foo" , "bar" ).entrySet ());
220
219
assertEquals ("bar" , threadContext .getHeader ("foo" ));
221
220
}
222
221
@@ -443,7 +442,7 @@ public void onAfter() {
443
442
assertEquals ("bar" , threadContext .getHeader ("foo" ));
444
443
assertEquals ("bar_transient" , threadContext .getTransient ("foo" ));
445
444
assertNotNull (threadContext .getTransient ("failure" ));
446
- assertEquals ("exception from doRun" , ((RuntimeException )threadContext .getTransient ("failure" )).getMessage ());
445
+ assertEquals ("exception from doRun" , ((RuntimeException ) threadContext .getTransient ("failure" )).getMessage ());
447
446
assertFalse (threadContext .isDefaultContext ());
448
447
threadContext .putTransient ("after" , "after" );
449
448
}
@@ -604,7 +603,7 @@ protected void doRun() throws Exception {
604
603
public void testMarkAsSystemContext () throws IOException {
605
604
try (ThreadContext threadContext = new ThreadContext (Settings .EMPTY )) {
606
605
assertFalse (threadContext .isSystemContext ());
607
- try (ThreadContext .StoredContext context = threadContext .stashContext ()){
606
+ try (ThreadContext .StoredContext context = threadContext .stashContext ()) {
608
607
assertFalse (threadContext .isSystemContext ());
609
608
threadContext .markAsSystemContext ();
610
609
assertTrue (threadContext .isSystemContext ());
@@ -613,6 +612,17 @@ public void testMarkAsSystemContext() throws IOException {
613
612
}
614
613
}
615
614
615
+ public void testPutHeaders () {
616
+ Settings build = Settings .builder ().put ("request.headers.default" , "1" ).build ();
617
+ ThreadContext threadContext = new ThreadContext (build );
618
+ threadContext .putHeader (Collections .<String , String >emptyMap ());
619
+ threadContext .putHeader (Collections .<String , String >singletonMap ("foo" , "bar" ));
620
+ assertEquals ("bar" , threadContext .getHeader ("foo" ));
621
+ IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () ->
622
+ threadContext .putHeader (Collections .<String , String >singletonMap ("foo" , "boom" )));
623
+ assertEquals ("value for key [foo] already present" , e .getMessage ());
624
+ }
625
+
616
626
/**
617
627
* Sometimes wraps a Runnable in an AbstractRunnable.
618
628
*/
0 commit comments