diff --git a/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/test/ItemMetadataAssert.java b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/test/ItemMetadataAssert.java index cc77cdc8a9af..e64b12c13623 100644 --- a/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/test/ItemMetadataAssert.java +++ b/configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/test/ItemMetadataAssert.java @@ -16,9 +16,12 @@ package org.springframework.boot.configurationprocessor.test; +import java.util.function.Function; + import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AssertProvider; -import org.assertj.core.internal.Objects; +import org.assertj.core.api.Assertions; +import org.assertj.core.api.ObjectAssert; import org.springframework.boot.configurationprocessor.metadata.ItemDeprecation; import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; @@ -28,34 +31,33 @@ * AssertJ assert for {@link ItemMetadata}. * * @author Stephane Nicoll + * @author Stefano Cordio */ public class ItemMetadataAssert extends AbstractAssert implements AssertProvider { - private static final Objects objects = Objects.instance(); - public ItemMetadataAssert(ItemMetadata itemMetadata) { super(itemMetadata, ItemMetadataAssert.class); - objects.assertNotNull(this.info, itemMetadata); + isNotNull(); } public ItemMetadataAssert isProperty() { - objects.assertEqual(this.info, this.actual.isOfItemType(ItemType.PROPERTY), true); + extracting((actual) -> actual.isOfItemType(ItemType.PROPERTY)).isEqualTo(true); return this; } public ItemMetadataAssert isGroup() { - objects.assertEqual(this.info, this.actual.isOfItemType(ItemType.GROUP), true); + extracting((actual) -> actual.isOfItemType(ItemType.GROUP)).isEqualTo(true); return this; } public ItemMetadataAssert hasName(String name) { - objects.assertEqual(this.info, this.actual.getName(), name); + extracting(ItemMetadata::getName).isEqualTo(name); return this; } public ItemMetadataAssert hasType(String type) { - objects.assertEqual(this.info, this.actual.getType(), type); + extracting(ItemMetadata::getType).isEqualTo(type); return this; } @@ -64,7 +66,7 @@ public ItemMetadataAssert hasType(Class type) { } public ItemMetadataAssert hasDescription(String description) { - objects.assertEqual(this.info, this.actual.getDescription(), description); + extracting(ItemMetadata::getDescription).isEqualTo(description); return this; } @@ -73,7 +75,7 @@ public ItemMetadataAssert hasNoDescription() { } public ItemMetadataAssert hasSourceType(String type) { - objects.assertEqual(this.info, this.actual.getSourceType(), type); + extracting(ItemMetadata::getSourceType).isEqualTo(type); return this; } @@ -82,12 +84,12 @@ public ItemMetadataAssert hasSourceType(Class type) { } public ItemMetadataAssert hasSourceMethod(String type) { - objects.assertEqual(this.info, this.actual.getSourceMethod(), type); + extracting(ItemMetadata::getSourceMethod).isEqualTo(type); return this; } public ItemMetadataAssert hasDefaultValue(Object defaultValue) { - objects.assertEqual(this.info, this.actual.getDefaultValue(), defaultValue); + extracting(ItemMetadata::getDefaultValue).isEqualTo(defaultValue); return this; } @@ -97,27 +99,28 @@ public ItemMetadataAssert isDeprecatedWithNoInformation() { } public ItemMetadataAssert isDeprecatedWithReason(String reason) { - ItemDeprecation deprecation = assertItemDeprecation(); - objects.assertEqual(this.info, deprecation.getReason(), reason); + assertItemDeprecation().extracting(ItemDeprecation::getReason).isEqualTo(reason); return this; } public ItemMetadataAssert isDeprecatedWithReplacement(String replacement) { - ItemDeprecation deprecation = assertItemDeprecation(); - objects.assertEqual(this.info, deprecation.getReplacement(), replacement); + assertItemDeprecation().extracting(ItemDeprecation::getReplacement).isEqualTo(replacement); return this; } public ItemMetadataAssert isNotDeprecated() { - objects.assertNull(this.info, this.actual.getDeprecation()); + extracting(ItemMetadata::getDeprecation).isNull(); return this; } - private ItemDeprecation assertItemDeprecation() { - ItemDeprecation deprecation = this.actual.getDeprecation(); - objects.assertNotNull(this.info, deprecation); - objects.assertNull(this.info, deprecation.getLevel()); - return deprecation; + private ObjectAssert assertItemDeprecation() { + ObjectAssert itemDeprecationAssert = extracting(ItemMetadata::getDeprecation); + itemDeprecationAssert.extracting(ItemDeprecation::getLevel).isNull(); + return itemDeprecationAssert; + } + + private ObjectAssert extracting(Function extractor) { + return super.extracting(extractor, Assertions::assertThat); } @Override diff --git a/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/ObjectContentAssert.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/ObjectContentAssert.java index 90bc0f18f182..d58612f85959 100644 --- a/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/ObjectContentAssert.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/ObjectContentAssert.java @@ -16,20 +16,18 @@ package org.springframework.boot.test.json; -import java.util.Map; - import org.assertj.core.api.AbstractMapAssert; import org.assertj.core.api.AbstractObjectArrayAssert; import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.Assert; -import org.assertj.core.api.Assertions; -import org.assertj.core.internal.Objects; +import org.assertj.core.api.InstanceOfAssertFactories; /** * AssertJ {@link Assert} for {@link ObjectContent}. * * @param the actual type * @author Phillip Webb + * @author Stefano Cordio * @since 1.4.0 */ public class ObjectContentAssert extends AbstractObjectAssert, A> { @@ -44,8 +42,7 @@ protected ObjectContentAssert(A actual) { * @return an array assertion object */ public AbstractObjectArrayAssert asArray() { - Objects.instance().assertIsInstanceOf(this.info, this.actual, Object[].class); - return Assertions.assertThat((Object[]) this.actual); + return asInstanceOf(InstanceOfAssertFactories.ARRAY); } /** @@ -53,10 +50,8 @@ public AbstractObjectArrayAssert asArray() { * chaining of map-specific assertions from this call. * @return a map assertion object */ - @SuppressWarnings("unchecked") public AbstractMapAssert asMap() { - Objects.instance().assertIsInstanceOf(this.info, this.actual, Map.class); - return Assertions.assertThat((Map) this.actual); + return asInstanceOf(InstanceOfAssertFactories.MAP); } }