16
16
17
17
package org .springframework .boot .configurationprocessor .test ;
18
18
19
+ import java .util .function .Function ;
20
+
19
21
import org .assertj .core .api .AbstractAssert ;
20
22
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 ;
22
25
23
26
import org .springframework .boot .configurationprocessor .metadata .ItemDeprecation ;
24
27
import org .springframework .boot .configurationprocessor .metadata .ItemMetadata ;
28
31
* AssertJ assert for {@link ItemMetadata}.
29
32
*
30
33
* @author Stephane Nicoll
34
+ * @author Stefano Cordio
31
35
*/
32
36
public class ItemMetadataAssert extends AbstractAssert <ItemMetadataAssert , ItemMetadata >
33
37
implements AssertProvider <ItemMetadataAssert > {
34
38
35
- private static final Objects objects = Objects .instance ();
36
-
37
39
public ItemMetadataAssert (ItemMetadata itemMetadata ) {
38
40
super (itemMetadata , ItemMetadataAssert .class );
39
- objects . assertNotNull ( this . info , itemMetadata );
41
+ isNotNull ( );
40
42
}
41
43
42
44
public ItemMetadataAssert isProperty () {
43
- objects . assertEqual ( this . info , this . actual .isOfItemType (ItemType .PROPERTY ), true );
45
+ extracting ( actual -> actual .isOfItemType (ItemType .PROPERTY )). isEqualTo ( true );
44
46
return this ;
45
47
}
46
48
47
49
public ItemMetadataAssert isGroup () {
48
- objects . assertEqual ( this . info , this . actual .isOfItemType (ItemType .GROUP ), true );
50
+ extracting ( actual -> actual .isOfItemType (ItemType .GROUP )). isEqualTo ( true );
49
51
return this ;
50
52
}
51
53
52
54
public ItemMetadataAssert hasName (String name ) {
53
- objects . assertEqual ( this . info , this . actual . getName (), name );
55
+ extracting ( ItemMetadata :: getName ). isEqualTo ( name );
54
56
return this ;
55
57
}
56
58
57
59
public ItemMetadataAssert hasType (String type ) {
58
- objects . assertEqual ( this . info , this . actual . getType (), type );
60
+ extracting ( ItemMetadata :: getType ). isEqualTo ( type );
59
61
return this ;
60
62
}
61
63
@@ -64,7 +66,7 @@ public ItemMetadataAssert hasType(Class<?> type) {
64
66
}
65
67
66
68
public ItemMetadataAssert hasDescription (String description ) {
67
- objects . assertEqual ( this . info , this . actual . getDescription (), description );
69
+ extracting ( ItemMetadata :: getDescription ). isEqualTo ( description );
68
70
return this ;
69
71
}
70
72
@@ -73,7 +75,7 @@ public ItemMetadataAssert hasNoDescription() {
73
75
}
74
76
75
77
public ItemMetadataAssert hasSourceType (String type ) {
76
- objects . assertEqual ( this . info , this . actual . getSourceType (), type );
78
+ extracting ( ItemMetadata :: getSourceType ). isEqualTo ( type );
77
79
return this ;
78
80
}
79
81
@@ -82,12 +84,12 @@ public ItemMetadataAssert hasSourceType(Class<?> type) {
82
84
}
83
85
84
86
public ItemMetadataAssert hasSourceMethod (String type ) {
85
- objects . assertEqual ( this . info , this . actual . getSourceMethod (), type );
87
+ extracting ( ItemMetadata :: getSourceMethod ). isEqualTo ( type );
86
88
return this ;
87
89
}
88
90
89
91
public ItemMetadataAssert hasDefaultValue (Object defaultValue ) {
90
- objects . assertEqual ( this . info , this . actual . getDefaultValue (), defaultValue );
92
+ extracting ( ItemMetadata :: getDefaultValue ). isEqualTo ( defaultValue );
91
93
return this ;
92
94
}
93
95
@@ -97,27 +99,28 @@ public ItemMetadataAssert isDeprecatedWithNoInformation() {
97
99
}
98
100
99
101
public ItemMetadataAssert isDeprecatedWithReason (String reason ) {
100
- ItemDeprecation deprecation = assertItemDeprecation ();
101
- objects .assertEqual (this .info , deprecation .getReason (), reason );
102
+ assertItemDeprecation ().extracting (ItemDeprecation ::getReason ).isEqualTo (reason );
102
103
return this ;
103
104
}
104
105
105
106
public ItemMetadataAssert isDeprecatedWithReplacement (String replacement ) {
106
- ItemDeprecation deprecation = assertItemDeprecation ();
107
- objects .assertEqual (this .info , deprecation .getReplacement (), replacement );
107
+ assertItemDeprecation ().extracting (ItemDeprecation ::getReplacement ).isEqualTo (replacement );
108
108
return this ;
109
109
}
110
110
111
111
public ItemMetadataAssert isNotDeprecated () {
112
- objects . assertNull ( this . info , this . actual . getDeprecation () );
112
+ extracting ( ItemMetadata :: getDeprecation ). isNull ( );
113
113
return this ;
114
114
}
115
115
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 );
121
124
}
122
125
123
126
@ Override
0 commit comments