11/*
2- * Copyright 2012-2024 the original author or authors.
2+ * Copyright 2012-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1919import java .time .Duration ;
2020import java .util .ArrayList ;
2121import java .util .List ;
22- import java .util .Map ;
2322import java .util .function .BiConsumer ;
2423import java .util .function .Consumer ;
2524
3029import org .apache .pulsar .client .impl .AutoClusterFailover ;
3130import org .apache .pulsar .common .schema .KeyValueEncodingType ;
3231import org .assertj .core .api .InstanceOfAssertFactories ;
33- import org .assertj .core .api .InstanceOfAssertFactory ;
34- import org .assertj .core .api .MapAssert ;
32+ import org .assertj .core .api .ThrowingConsumer ;
3533import org .junit .jupiter .api .Nested ;
3634import org .junit .jupiter .api .Test ;
3735import org .mockito .ArgumentMatchers ;
5755import org .springframework .test .util .ReflectionTestUtils ;
5856
5957import static org .assertj .core .api .Assertions .assertThat ;
60- import static org .assertj .core .api .Assertions .entry ;
6158import static org .mockito .BDDMockito .given ;
6259import static org .mockito .Mockito .inOrder ;
6360import static org .mockito .Mockito .mock ;
@@ -235,10 +232,6 @@ PulsarAdminBuilderCustomizer customizerBar() {
235232 @ Nested
236233 class SchemaResolverTests {
237234
238- @ SuppressWarnings ("rawtypes" )
239- private static final InstanceOfAssertFactory <Map , MapAssert <Class , Schema >> CLASS_SCHEMA_MAP = InstanceOfAssertFactories
240- .map (Class .class , Schema .class );
241-
242235 private final ApplicationContextRunner contextRunner = PulsarConfigurationTests .this .contextRunner ;
243236
244237 @ Test
@@ -254,8 +247,7 @@ void whenHasUserDefinedSchemaResolverCustomizer() {
254247 .addCustomSchemaMapping (TestRecord .class , Schema .STRING );
255248 this .contextRunner .withBean ("schemaResolverCustomizer" , SchemaResolverCustomizer .class , () -> customizer )
256249 .run ((context ) -> assertThat (context ).getBean (DefaultSchemaResolver .class )
257- .extracting (DefaultSchemaResolver ::getCustomSchemaMappings , InstanceOfAssertFactories .MAP )
258- .containsEntry (TestRecord .class , Schema .STRING ));
250+ .satisfies (customSchemaMappingOf (TestRecord .class , Schema .STRING )));
259251 }
260252
261253 @ Test
@@ -265,8 +257,7 @@ void whenHasDefaultsTypeMappingForPrimitiveAddsToSchemaResolver() {
265257 properties .add ("spring.pulsar.defaults.type-mappings[0].schema-info.schema-type=STRING" );
266258 this .contextRunner .withPropertyValues (properties .toArray (String []::new ))
267259 .run ((context ) -> assertThat (context ).getBean (DefaultSchemaResolver .class )
268- .extracting (DefaultSchemaResolver ::getCustomSchemaMappings , InstanceOfAssertFactories .MAP )
269- .containsOnly (entry (TestRecord .class , Schema .STRING )));
260+ .satisfies (customSchemaMappingOf (TestRecord .class , Schema .STRING )));
270261 }
271262
272263 @ Test
@@ -277,8 +268,7 @@ void whenHasDefaultsTypeMappingForStructAddsToSchemaResolver() {
277268 Schema <?> expectedSchema = Schema .JSON (TestRecord .class );
278269 this .contextRunner .withPropertyValues (properties .toArray (String []::new ))
279270 .run ((context ) -> assertThat (context ).getBean (DefaultSchemaResolver .class )
280- .extracting (DefaultSchemaResolver ::getCustomSchemaMappings , CLASS_SCHEMA_MAP )
281- .hasEntrySatisfying (TestRecord .class , schemaEqualTo (expectedSchema )));
271+ .satisfies (customSchemaMappingOf (TestRecord .class , expectedSchema )));
282272 }
283273
284274 @ Test
@@ -291,12 +281,16 @@ void whenHasDefaultsTypeMappingForKeyValueAddsToSchemaResolver() {
291281 KeyValueEncodingType .INLINE );
292282 this .contextRunner .withPropertyValues (properties .toArray (String []::new ))
293283 .run ((context ) -> assertThat (context ).getBean (DefaultSchemaResolver .class )
294- .extracting (DefaultSchemaResolver ::getCustomSchemaMappings , CLASS_SCHEMA_MAP )
295- .hasEntrySatisfying (TestRecord .class , schemaEqualTo (expectedSchema )));
284+ .satisfies (customSchemaMappingOf (TestRecord .class , expectedSchema )));
285+ }
286+
287+ private ThrowingConsumer <DefaultSchemaResolver > customSchemaMappingOf (Class <?> messageType ,
288+ Schema <?> expectedSchema ) {
289+ return (resolver ) -> assertThat (resolver .getCustomSchemaMapping (messageType ))
290+ .hasValueSatisfying (schemaEqualTo (expectedSchema ));
296291 }
297292
298- @ SuppressWarnings ("rawtypes" )
299- private Consumer <Schema > schemaEqualTo (Schema <?> expected ) {
293+ private Consumer <Schema <?>> schemaEqualTo (Schema <?> expected ) {
300294 return (actual ) -> assertThat (actual .getSchemaInfo ()).isEqualTo (expected .getSchemaInfo ());
301295 }
302296
@@ -324,8 +318,10 @@ void whenHasDefaultsTypeMappingAddsToSchemaResolver() {
324318 this .contextRunner .withPropertyValues (properties .toArray (String []::new ))
325319 .run ((context ) -> assertThat (context ).getBean (TopicResolver .class )
326320 .asInstanceOf (InstanceOfAssertFactories .type (DefaultTopicResolver .class ))
327- .extracting (DefaultTopicResolver ::getCustomTopicMappings , InstanceOfAssertFactories .MAP )
328- .containsOnly (entry (TestRecord .class , "foo-topic" ), entry (String .class , "string-topic" )));
321+ .satisfies ((resolver ) -> {
322+ assertThat (resolver .getCustomTopicMapping (TestRecord .class )).hasValue ("foo-topic" );
323+ assertThat (resolver .getCustomTopicMapping (String .class )).hasValue ("string-topic" );
324+ }));
329325 }
330326
331327 }
0 commit comments