From 7ad9401d8b92071a9405a6edd0e40e9a9affcc52 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 21 Apr 2025 20:19:17 -0700 Subject: [PATCH] Migrate from deprecated Spring Pulsar methods See gh-45096 --- .../pulsar/PulsarConfigurationTests.java | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarConfigurationTests.java index 0bd73b338cf..ab0eaeb4543 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.pulsar; import java.time.Duration; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -30,8 +29,7 @@ import org.apache.pulsar.client.api.Schema; import org.apache.pulsar.client.impl.AutoClusterFailover; import org.apache.pulsar.common.schema.KeyValueEncodingType; import org.assertj.core.api.InstanceOfAssertFactories; -import org.assertj.core.api.InstanceOfAssertFactory; -import org.assertj.core.api.MapAssert; +import org.assertj.core.api.ThrowingConsumer; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; @@ -57,7 +55,6 @@ import org.springframework.pulsar.function.PulsarFunctionAdministration; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; @@ -235,10 +232,6 @@ class PulsarConfigurationTests { @Nested class SchemaResolverTests { - @SuppressWarnings("rawtypes") - private static final InstanceOfAssertFactory> CLASS_SCHEMA_MAP = InstanceOfAssertFactories - .map(Class.class, Schema.class); - private final ApplicationContextRunner contextRunner = PulsarConfigurationTests.this.contextRunner; @Test @@ -254,8 +247,7 @@ class PulsarConfigurationTests { .addCustomSchemaMapping(TestRecord.class, Schema.STRING); this.contextRunner.withBean("schemaResolverCustomizer", SchemaResolverCustomizer.class, () -> customizer) .run((context) -> assertThat(context).getBean(DefaultSchemaResolver.class) - .extracting(DefaultSchemaResolver::getCustomSchemaMappings, InstanceOfAssertFactories.MAP) - .containsEntry(TestRecord.class, Schema.STRING)); + .satisfies(customSchemaMappingOf(TestRecord.class, Schema.STRING))); } @Test @@ -265,8 +257,7 @@ class PulsarConfigurationTests { properties.add("spring.pulsar.defaults.type-mappings[0].schema-info.schema-type=STRING"); this.contextRunner.withPropertyValues(properties.toArray(String[]::new)) .run((context) -> assertThat(context).getBean(DefaultSchemaResolver.class) - .extracting(DefaultSchemaResolver::getCustomSchemaMappings, InstanceOfAssertFactories.MAP) - .containsOnly(entry(TestRecord.class, Schema.STRING))); + .satisfies(customSchemaMappingOf(TestRecord.class, Schema.STRING))); } @Test @@ -277,8 +268,7 @@ class PulsarConfigurationTests { Schema expectedSchema = Schema.JSON(TestRecord.class); this.contextRunner.withPropertyValues(properties.toArray(String[]::new)) .run((context) -> assertThat(context).getBean(DefaultSchemaResolver.class) - .extracting(DefaultSchemaResolver::getCustomSchemaMappings, CLASS_SCHEMA_MAP) - .hasEntrySatisfying(TestRecord.class, schemaEqualTo(expectedSchema))); + .satisfies(customSchemaMappingOf(TestRecord.class, expectedSchema))); } @Test @@ -291,12 +281,16 @@ class PulsarConfigurationTests { KeyValueEncodingType.INLINE); this.contextRunner.withPropertyValues(properties.toArray(String[]::new)) .run((context) -> assertThat(context).getBean(DefaultSchemaResolver.class) - .extracting(DefaultSchemaResolver::getCustomSchemaMappings, CLASS_SCHEMA_MAP) - .hasEntrySatisfying(TestRecord.class, schemaEqualTo(expectedSchema))); + .satisfies(customSchemaMappingOf(TestRecord.class, expectedSchema))); + } + + private ThrowingConsumer customSchemaMappingOf(Class messageType, + Schema expectedSchema) { + return (resolver) -> assertThat(resolver.getCustomSchemaMapping(messageType)) + .hasValueSatisfying(schemaEqualTo(expectedSchema)); } - @SuppressWarnings("rawtypes") - private Consumer schemaEqualTo(Schema expected) { + private Consumer> schemaEqualTo(Schema expected) { return (actual) -> assertThat(actual.getSchemaInfo()).isEqualTo(expected.getSchemaInfo()); } @@ -324,8 +318,10 @@ class PulsarConfigurationTests { this.contextRunner.withPropertyValues(properties.toArray(String[]::new)) .run((context) -> assertThat(context).getBean(TopicResolver.class) .asInstanceOf(InstanceOfAssertFactories.type(DefaultTopicResolver.class)) - .extracting(DefaultTopicResolver::getCustomTopicMappings, InstanceOfAssertFactories.MAP) - .containsOnly(entry(TestRecord.class, "foo-topic"), entry(String.class, "string-topic"))); + .satisfies((resolver) -> { + assertThat(resolver.getCustomTopicMapping(TestRecord.class)).hasValue("foo-topic"); + assertThat(resolver.getCustomTopicMapping(String.class)).hasValue("string-topic"); + })); } }