2828import org .apache .kafka .common .protocol .ApiKeys ;
2929import org .apache .kafka .common .protocol .ApiMessage ;
3030import org .apache .kafka .common .protocol .Errors ;
31+ import org .apache .kafka .common .serialization .Serde ;
3132import org .apache .kafka .common .serialization .Serdes ;
3233import org .apache .kafka .common .serialization .StringDeserializer ;
3334import org .apache .kafka .common .serialization .StringSerializer ;
@@ -288,15 +289,18 @@ void testSimpleTestClientReportsConnectionState() {
288289 @ Test
289290 void testIllegalToAskForNonExistentVirtualCluster () {
290291 try (var tester = kroxyliciousTester (proxy (kafkaCluster ))) {
292+ // these are variables to prevent multiple method invocations within assertThrows
293+ Map <String , Object > emptyMap = Map .of ();
294+ Serde <String > stringSerde = Serdes .String ();
291295 assertThrows (IllegalArgumentException .class , () -> tester .simpleTestClient ("NON_EXIST" ));
292296 assertThrows (IllegalArgumentException .class , () -> tester .consumer ("NON_EXIST" ));
293- assertThrows (IllegalArgumentException .class , () -> tester .consumer ("NON_EXIST" , Map . of () ));
294- assertThrows (IllegalArgumentException .class , () -> tester .consumer ("NON_EXIST" , Serdes . String (), Serdes . String (), Map . of () ));
297+ assertThrows (IllegalArgumentException .class , () -> tester .consumer ("NON_EXIST" , emptyMap ));
298+ assertThrows (IllegalArgumentException .class , () -> tester .consumer ("NON_EXIST" , stringSerde , stringSerde , emptyMap ));
295299 assertThrows (IllegalArgumentException .class , () -> tester .producer ("NON_EXIST" ));
296- assertThrows (IllegalArgumentException .class , () -> tester .producer ("NON_EXIST" , Map . of () ));
297- assertThrows (IllegalArgumentException .class , () -> tester .producer ("NON_EXIST" , Serdes . String (), Serdes . String (), Map . of () ));
300+ assertThrows (IllegalArgumentException .class , () -> tester .producer ("NON_EXIST" , emptyMap ));
301+ assertThrows (IllegalArgumentException .class , () -> tester .producer ("NON_EXIST" , stringSerde , stringSerde , emptyMap ));
298302 assertThrows (IllegalArgumentException .class , () -> tester .admin ("NON_EXIST" ));
299- assertThrows (IllegalArgumentException .class , () -> tester .admin ("NON_EXIST" , Map . of () ));
303+ assertThrows (IllegalArgumentException .class , () -> tester .admin ("NON_EXIST" , emptyMap ));
300304 }
301305 }
302306
@@ -309,13 +313,16 @@ void testIllegalToAskForDefaultClientsWhenVirtualClustersAmbiguous() {
309313 try (var tester = kroxyliciousTester (proxy )) {
310314 assertThrows (AmbiguousVirtualClusterException .class , tester ::simpleTestClient );
311315 assertThrows (AmbiguousVirtualClusterException .class , tester ::consumer );
312- assertThrows (AmbiguousVirtualClusterException .class , () -> tester .consumer (Map .of ()));
313- assertThrows (AmbiguousVirtualClusterException .class , () -> tester .consumer (Serdes .String (), Serdes .String (), Map .of ()));
316+ // these are variables to prevent multiple method invocations within assertThrows
317+ Map <String , Object > emptyMap = Map .of ();
318+ Serde <String > stringSerde = Serdes .String ();
319+ assertThrows (AmbiguousVirtualClusterException .class , () -> tester .consumer (emptyMap ));
320+ assertThrows (AmbiguousVirtualClusterException .class , () -> tester .consumer (stringSerde , stringSerde , emptyMap ));
314321 assertThrows (AmbiguousVirtualClusterException .class , tester ::producer );
315- assertThrows (AmbiguousVirtualClusterException .class , () -> tester .producer (Map . of () ));
316- assertThrows (AmbiguousVirtualClusterException .class , () -> tester .producer (Serdes . String (), Serdes . String (), Map . of () ));
322+ assertThrows (AmbiguousVirtualClusterException .class , () -> tester .producer (emptyMap ));
323+ assertThrows (AmbiguousVirtualClusterException .class , () -> tester .producer (stringSerde , stringSerde , emptyMap ));
317324 assertThrows (AmbiguousVirtualClusterException .class , tester ::admin );
318- assertThrows (AmbiguousVirtualClusterException .class , () -> tester .admin (Map . of () ));
325+ assertThrows (AmbiguousVirtualClusterException .class , () -> tester .admin (emptyMap ));
319326 }
320327 }
321328
0 commit comments