1616
1717package org .springframework .boot .configurationprocessor .test ;
1818
19+ import java .util .function .Function ;
20+
1921import org .assertj .core .api .AbstractAssert ;
2022import 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
2326import org .springframework .boot .configurationprocessor .metadata .ItemDeprecation ;
2427import org .springframework .boot .configurationprocessor .metadata .ItemMetadata ;
2831 * AssertJ assert for {@link ItemMetadata}.
2932 *
3033 * @author Stephane Nicoll
34+ * @author Stefano Cordio
3135 */
3236public 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