Skip to content

Commit c7b659c

Browse files
scordiosnicoll
authored andcommitted
Replace AssertJ internal APIs with alternative implementations
See gh-46855 Signed-off-by: Stefano Cordio <[email protected]>
1 parent 9f0716d commit c7b659c

File tree

2 files changed

+29
-31
lines changed
  • spring-boot-project

2 files changed

+29
-31
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/json/ObjectContentAssert.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,18 @@
1616

1717
package org.springframework.boot.test.json;
1818

19-
import java.util.Map;
20-
2119
import org.assertj.core.api.AbstractMapAssert;
2220
import org.assertj.core.api.AbstractObjectArrayAssert;
2321
import org.assertj.core.api.AbstractObjectAssert;
2422
import org.assertj.core.api.Assert;
25-
import org.assertj.core.api.Assertions;
26-
import org.assertj.core.internal.Objects;
23+
import org.assertj.core.api.InstanceOfAssertFactories;
2724

2825
/**
2926
* AssertJ {@link Assert} for {@link ObjectContent}.
3027
*
3128
* @param <A> the actual type
3229
* @author Phillip Webb
30+
* @author Stefano Cordio
3331
* @since 1.4.0
3432
*/
3533
public class ObjectContentAssert<A> extends AbstractObjectAssert<ObjectContentAssert<A>, A> {
@@ -44,19 +42,16 @@ protected ObjectContentAssert(A actual) {
4442
* @return an array assertion object
4543
*/
4644
public AbstractObjectArrayAssert<?, Object> asArray() {
47-
Objects.instance().assertIsInstanceOf(this.info, this.actual, Object[].class);
48-
return Assertions.assertThat((Object[]) this.actual);
45+
return asInstanceOf(InstanceOfAssertFactories.ARRAY);
4946
}
5047

5148
/**
5249
* Verifies that the actual value is a map, and returns a map assertion, to allow
5350
* chaining of map-specific assertions from this call.
5451
* @return a map assertion object
5552
*/
56-
@SuppressWarnings("unchecked")
5753
public AbstractMapAssert<?, ?, Object, Object> asMap() {
58-
Objects.instance().assertIsInstanceOf(this.info, this.actual, Map.class);
59-
return Assertions.assertThat((Map<Object, Object>) this.actual);
54+
return asInstanceOf(InstanceOfAssertFactories.MAP);
6055
}
6156

6257
}

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/test/ItemMetadataAssert.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616

1717
package org.springframework.boot.configurationprocessor.test;
1818

19+
import java.util.function.Function;
20+
1921
import org.assertj.core.api.AbstractAssert;
2022
import org.assertj.core.api.AssertProvider;
21-
import org.assertj.core.internal.Objects;
23+
import org.assertj.core.api.Assertions;
24+
import org.assertj.core.api.ObjectAssert;
2225

2326
import org.springframework.boot.configurationprocessor.metadata.ItemDeprecation;
2427
import org.springframework.boot.configurationprocessor.metadata.ItemMetadata;
@@ -28,34 +31,33 @@
2831
* AssertJ assert for {@link ItemMetadata}.
2932
*
3033
* @author Stephane Nicoll
34+
* @author Stefano Cordio
3135
*/
3236
public class ItemMetadataAssert extends AbstractAssert<ItemMetadataAssert, ItemMetadata>
3337
implements AssertProvider<ItemMetadataAssert> {
3438

35-
private static final Objects objects = Objects.instance();
36-
3739
public ItemMetadataAssert(ItemMetadata itemMetadata) {
3840
super(itemMetadata, ItemMetadataAssert.class);
39-
objects.assertNotNull(this.info, itemMetadata);
41+
isNotNull();
4042
}
4143

4244
public ItemMetadataAssert isProperty() {
43-
objects.assertEqual(this.info, this.actual.isOfItemType(ItemType.PROPERTY), true);
45+
extracting((actual) -> actual.isOfItemType(ItemType.PROPERTY)).isEqualTo(true);
4446
return this;
4547
}
4648

4749
public ItemMetadataAssert isGroup() {
48-
objects.assertEqual(this.info, this.actual.isOfItemType(ItemType.GROUP), true);
50+
extracting((actual) -> actual.isOfItemType(ItemType.GROUP)).isEqualTo(true);
4951
return this;
5052
}
5153

5254
public ItemMetadataAssert hasName(String name) {
53-
objects.assertEqual(this.info, this.actual.getName(), name);
55+
extracting(ItemMetadata::getName).isEqualTo(name);
5456
return this;
5557
}
5658

5759
public ItemMetadataAssert hasType(String type) {
58-
objects.assertEqual(this.info, this.actual.getType(), type);
60+
extracting(ItemMetadata::getType).isEqualTo(type);
5961
return this;
6062
}
6163

@@ -64,7 +66,7 @@ public ItemMetadataAssert hasType(Class<?> type) {
6466
}
6567

6668
public ItemMetadataAssert hasDescription(String description) {
67-
objects.assertEqual(this.info, this.actual.getDescription(), description);
69+
extracting(ItemMetadata::getDescription).isEqualTo(description);
6870
return this;
6971
}
7072

@@ -73,7 +75,7 @@ public ItemMetadataAssert hasNoDescription() {
7375
}
7476

7577
public ItemMetadataAssert hasSourceType(String type) {
76-
objects.assertEqual(this.info, this.actual.getSourceType(), type);
78+
extracting(ItemMetadata::getSourceType).isEqualTo(type);
7779
return this;
7880
}
7981

@@ -82,12 +84,12 @@ public ItemMetadataAssert hasSourceType(Class<?> type) {
8284
}
8385

8486
public ItemMetadataAssert hasSourceMethod(String type) {
85-
objects.assertEqual(this.info, this.actual.getSourceMethod(), type);
87+
extracting(ItemMetadata::getSourceMethod).isEqualTo(type);
8688
return this;
8789
}
8890

8991
public ItemMetadataAssert hasDefaultValue(Object defaultValue) {
90-
objects.assertEqual(this.info, this.actual.getDefaultValue(), defaultValue);
92+
extracting(ItemMetadata::getDefaultValue).isEqualTo(defaultValue);
9193
return this;
9294
}
9395

@@ -97,27 +99,28 @@ public ItemMetadataAssert isDeprecatedWithNoInformation() {
9799
}
98100

99101
public ItemMetadataAssert isDeprecatedWithReason(String reason) {
100-
ItemDeprecation deprecation = assertItemDeprecation();
101-
objects.assertEqual(this.info, deprecation.getReason(), reason);
102+
assertItemDeprecation().extracting(ItemDeprecation::getReason).isEqualTo(reason);
102103
return this;
103104
}
104105

105106
public ItemMetadataAssert isDeprecatedWithReplacement(String replacement) {
106-
ItemDeprecation deprecation = assertItemDeprecation();
107-
objects.assertEqual(this.info, deprecation.getReplacement(), replacement);
107+
assertItemDeprecation().extracting(ItemDeprecation::getReplacement).isEqualTo(replacement);
108108
return this;
109109
}
110110

111111
public ItemMetadataAssert isNotDeprecated() {
112-
objects.assertNull(this.info, this.actual.getDeprecation());
112+
extracting(ItemMetadata::getDeprecation).isNull();
113113
return this;
114114
}
115115

116-
private ItemDeprecation assertItemDeprecation() {
117-
ItemDeprecation deprecation = this.actual.getDeprecation();
118-
objects.assertNotNull(this.info, deprecation);
119-
objects.assertNull(this.info, deprecation.getLevel());
120-
return deprecation;
116+
private ObjectAssert<ItemDeprecation> assertItemDeprecation() {
117+
ObjectAssert<ItemDeprecation> itemDeprecationAssert = extracting(ItemMetadata::getDeprecation);
118+
itemDeprecationAssert.extracting(ItemDeprecation::getLevel).isNull();
119+
return itemDeprecationAssert;
120+
}
121+
122+
private <T> ObjectAssert<T> extracting(Function<ItemMetadata, T> extractor) {
123+
return super.extracting(extractor, Assertions::assertThat);
121124
}
122125

123126
@Override

0 commit comments

Comments
 (0)