1
1
/*
2
- * Copyright 2012-2024 the original author or authors.
2
+ * Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
19
19
import java .time .Duration ;
20
20
import java .util .ArrayList ;
21
21
import java .util .List ;
22
- import java .util .Map ;
23
22
import java .util .function .BiConsumer ;
24
23
import java .util .function .Consumer ;
25
24
30
29
import org .apache .pulsar .client .impl .AutoClusterFailover ;
31
30
import org .apache .pulsar .common .schema .KeyValueEncodingType ;
32
31
import 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 ;
35
33
import org .junit .jupiter .api .Nested ;
36
34
import org .junit .jupiter .api .Test ;
37
35
import org .mockito .ArgumentMatchers ;
57
55
import org .springframework .test .util .ReflectionTestUtils ;
58
56
59
57
import static org .assertj .core .api .Assertions .assertThat ;
60
- import static org .assertj .core .api .Assertions .entry ;
61
58
import static org .mockito .BDDMockito .given ;
62
59
import static org .mockito .Mockito .inOrder ;
63
60
import static org .mockito .Mockito .mock ;
@@ -235,10 +232,6 @@ PulsarAdminBuilderCustomizer customizerBar() {
235
232
@ Nested
236
233
class SchemaResolverTests {
237
234
238
- @ SuppressWarnings ("rawtypes" )
239
- private static final InstanceOfAssertFactory <Map , MapAssert <Class , Schema >> CLASS_SCHEMA_MAP = InstanceOfAssertFactories
240
- .map (Class .class , Schema .class );
241
-
242
235
private final ApplicationContextRunner contextRunner = PulsarConfigurationTests .this .contextRunner ;
243
236
244
237
@ Test
@@ -254,8 +247,7 @@ void whenHasUserDefinedSchemaResolverCustomizer() {
254
247
.addCustomSchemaMapping (TestRecord .class , Schema .STRING );
255
248
this .contextRunner .withBean ("schemaResolverCustomizer" , SchemaResolverCustomizer .class , () -> customizer )
256
249
.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 )));
259
251
}
260
252
261
253
@ Test
@@ -265,8 +257,7 @@ void whenHasDefaultsTypeMappingForPrimitiveAddsToSchemaResolver() {
265
257
properties .add ("spring.pulsar.defaults.type-mappings[0].schema-info.schema-type=STRING" );
266
258
this .contextRunner .withPropertyValues (properties .toArray (String []::new ))
267
259
.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 )));
270
261
}
271
262
272
263
@ Test
@@ -277,8 +268,7 @@ void whenHasDefaultsTypeMappingForStructAddsToSchemaResolver() {
277
268
Schema <?> expectedSchema = Schema .JSON (TestRecord .class );
278
269
this .contextRunner .withPropertyValues (properties .toArray (String []::new ))
279
270
.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 )));
282
272
}
283
273
284
274
@ Test
@@ -291,12 +281,16 @@ void whenHasDefaultsTypeMappingForKeyValueAddsToSchemaResolver() {
291
281
KeyValueEncodingType .INLINE );
292
282
this .contextRunner .withPropertyValues (properties .toArray (String []::new ))
293
283
.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 ));
296
291
}
297
292
298
- @ SuppressWarnings ("rawtypes" )
299
- private Consumer <Schema > schemaEqualTo (Schema <?> expected ) {
293
+ private Consumer <Schema <?>> schemaEqualTo (Schema <?> expected ) {
300
294
return (actual ) -> assertThat (actual .getSchemaInfo ()).isEqualTo (expected .getSchemaInfo ());
301
295
}
302
296
@@ -324,8 +318,10 @@ void whenHasDefaultsTypeMappingAddsToSchemaResolver() {
324
318
this .contextRunner .withPropertyValues (properties .toArray (String []::new ))
325
319
.run ((context ) -> assertThat (context ).getBean (TopicResolver .class )
326
320
.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
+ }));
329
325
}
330
326
331
327
}
0 commit comments