3939import java .util .HashMap ;
4040import java .util .List ;
4141import java .util .Map ;
42+ import java .util .regex .Pattern ;
4243import java .util .stream .Collectors ;
4344import java .util .stream .Stream ;
4445
@@ -125,6 +126,8 @@ public void testClient_errorEnvironmentApi() {
125126
126127 interceptor .addRule ()
127128 .get (baseUrl + "/environment-document/" )
129+ .headerMatches ("X-Environment-Key" , Pattern .compile ("api-key" ))
130+ .headerMatches ("User-Agent" , Pattern .compile ("flagsmith-java-sdk/.*" ))
128131 .respond (
129132 500 ,
130133 ResponseBody .create ("error" , MEDIATYPE_JSON ));
@@ -162,6 +165,8 @@ public void testClient_validateEnvironment()
162165
163166 interceptor .addRule ()
164167 .get (baseUrl + "/environment-document/" )
168+ .headerMatches ("X-Environment-Key" , Pattern .compile ("api-key" ))
169+ .headerMatches ("User-Agent" , Pattern .compile ("flagsmith-java-sdk/.*" ))
165170 .anyTimes ()
166171 .respond (
167172 FlagsmithTestHelper .environmentString (),
@@ -188,6 +193,8 @@ public void testClient_flagsApiException()
188193
189194 interceptor .addRule ()
190195 .get (baseUrl + "/flags/" )
196+ .headerMatches ("X-Environment-Key" , Pattern .compile ("api-key" ))
197+ .headerMatches ("User-Agent" , Pattern .compile ("flagsmith-java-sdk/.*" ))
191198 .respond (
192199 500 ,
193200 ResponseBody .create ("error" , MEDIATYPE_JSON ));
@@ -211,6 +218,8 @@ public void testClient_flagsApiEmpty()
211218
212219 interceptor .addRule ()
213220 .get (baseUrl + "/flags/" )
221+ .headerMatches ("X-Environment-Key" , Pattern .compile ("api-key" ))
222+ .headerMatches ("User-Agent" , Pattern .compile ("flagsmith-java-sdk/.*" ))
214223 .respond (
215224 "[]" ,
216225 MEDIATYPE_JSON );
@@ -238,6 +247,8 @@ public void testClient_flagsApi()
238247
239248 interceptor .addRule ()
240249 .get (baseUrl + "/flags/" )
250+ .headerMatches ("X-Environment-Key" , Pattern .compile ("api-key" ))
251+ .headerMatches ("User-Agent" , Pattern .compile ("flagsmith-java-sdk/.*" ))
241252 .respond (
242253 MapperFactory .getMapper ().writeValueAsString (featureStateModel ),
243254 MEDIATYPE_JSON );
@@ -264,6 +275,8 @@ public void testClient_identityFlagsApiNoTraitsException() throws FlagsmithClien
264275
265276 interceptor .addRule ()
266277 .post (baseUrl + "/identities/" )
278+ .headerMatches ("X-Environment-Key" , Pattern .compile ("api-key" ))
279+ .headerMatches ("User-Agent" , Pattern .compile ("flagsmith-java-sdk/.*" ))
267280 .respond (
268281 500 ,
269282 ResponseBody .create ("error" , MEDIATYPE_JSON ));
@@ -289,6 +302,8 @@ public void testClient_identityFlagsApiNoTraits() throws FlagsmithClientError {
289302
290303 interceptor .addRule ()
291304 .post (baseUrl + "/identities/" )
305+ .headerMatches ("X-Environment-Key" , Pattern .compile ("api-key" ))
306+ .headerMatches ("User-Agent" , Pattern .compile ("flagsmith-java-sdk/.*" ))
292307 .respond (
293308 json ,
294309 MEDIATYPE_JSON );
@@ -407,7 +422,8 @@ public void testClient_identityFlagsApiWithTraitsWithLocalEnvironment() {
407422 .build ();
408423
409424 interceptor .addRule ()
410- .get (baseUrl + "/flags/" ).anyTimes ()
425+ .get (baseUrl + "/flags/" )
426+ .anyTimes ()
411427 .respond (500 , ResponseBody .create ("error" , MEDIATYPE_JSON ));
412428
413429 assertThrows (FlagsmithApiError .class ,
@@ -443,6 +459,8 @@ public void testClient_defaultFlagWithNoEnvironment() throws FlagsmithClientErro
443459
444460 interceptor .addRule ()
445461 .get (baseUrl + "/flags/" )
462+ .headerMatches ("X-Environment-Key" , Pattern .compile ("api-key" ))
463+ .headerMatches ("User-Agent" , Pattern .compile ("flagsmith-java-sdk/.*" ))
446464 .respond (
447465 "[]" ,
448466 MEDIATYPE_JSON );
@@ -481,6 +499,8 @@ public void testGetIdentitySegmentsNoTraits() throws JsonProcessingException,
481499 MockInterceptor interceptor = new MockInterceptor ();
482500 interceptor .addRule ()
483501 .get (baseUrl + "/environment-document/" )
502+ .headerMatches ("X-Environment-Key" , Pattern .compile ("ser.abcdefg" ))
503+ .headerMatches ("User-Agent" , Pattern .compile ("flagsmith-java-sdk/.*" ))
484504 .anyTimes ()
485505 .respond (
486506 MapperFactory .getMapper ().writeValueAsString (environmentModel ),
@@ -514,6 +534,8 @@ public void testGetIdentitySegmentsWithValidTrait() throws JsonProcessingExcepti
514534 MockInterceptor interceptor = new MockInterceptor ();
515535 interceptor .addRule ()
516536 .get (baseUrl + "/environment-document/" )
537+ .headerMatches ("X-Environment-Key" , Pattern .compile ("ser.abcdefg" ))
538+ .headerMatches ("User-Agent" , Pattern .compile ("flagsmith-java-sdk/.*" ))
517539 .anyTimes ()
518540 .respond (
519541 MapperFactory .getMapper ().writeValueAsString (environmentModel ),
0 commit comments