1
1
package de .retest .recheck .review ;
2
2
3
+ import static org .assertj .core .api .Assertions .assertThat ;
3
4
import static org .junit .jupiter .api .Assertions .assertThrows ;
5
+ import static org .mockito .ArgumentMatchers .any ;
4
6
import static org .mockito .ArgumentMatchers .anyString ;
7
+ import static org .mockito .ArgumentMatchers .eq ;
5
8
import static org .mockito .Mockito .atLeastOnce ;
6
9
import static org .mockito .Mockito .mock ;
7
10
import static org .mockito .Mockito .only ;
11
14
import static org .mockito .Mockito .when ;
12
15
13
16
import java .util .Arrays ;
17
+ import java .util .Collections ;
14
18
import java .util .List ;
15
19
16
20
import org .junit .jupiter .api .BeforeEach ;
17
21
import org .junit .jupiter .api .Test ;
22
+ import org .mockito .ArgumentCaptor ;
18
23
19
24
import de .retest .recheck .report .ActionReplayResult ;
20
25
import de .retest .recheck .report .SuiteReplayResult ;
24
29
import de .retest .recheck .ui .descriptors .IdentifyingAttributes ;
25
30
import de .retest .recheck .ui .diff .AttributeDifference ;
26
31
import de .retest .recheck .ui .diff .ElementDifference ;
32
+ import de .retest .recheck .ui .diff .ElementIdentificationWarning ;
27
33
import de .retest .recheck .ui .diff .InsertedDeletedElementDifference ;
28
34
import de .retest .recheck .ui .review .ActionChangeSet ;
29
35
import de .retest .recheck .ui .review .AttributeChanges ;
@@ -65,7 +71,11 @@ class GlobalChangeSetApplierTest {
65
71
@ BeforeEach
66
72
void setUp () {
67
73
identifyingAttributes = mock ( IdentifyingAttributes .class );
74
+ when ( identifyingAttributes .identifier () ).thenReturn ( "a" );
68
75
attributeDifference = mock ( AttributeDifference .class );
76
+ when ( attributeDifference .identifier () ).thenReturn ( "a" );
77
+ when ( attributeDifference .getElementIdentificationWarnings () )
78
+ .thenReturn ( Collections .singletonList ( mock ( ElementIdentificationWarning .class ) ) );
69
79
70
80
testReport = mock ( TestReport .class );
71
81
suiteReplayResult = mock ( SuiteReplayResult .class );
@@ -143,6 +153,7 @@ void create_should_read_all_elements_from_replayResult() {
143
153
verify ( elementDifference1 , times ( 1 ) ).getIdentifyingAttributes ();
144
154
verify ( elementDifference1 , times ( 1 ) ).isInsertionOrDeletion ();
145
155
verifyNoMoreInteractions ( elementDifference1 );
156
+ verify ( attributeDifference , times ( 2 ) ).getElementIdentificationWarnings ();
146
157
}
147
158
148
159
// Add/remove element differences.
@@ -154,8 +165,26 @@ void add_for_all_ident_should_add_ident_change_set() throws Exception {
154
165
155
166
globalApplier .addChangeSetForAllEqualIdentAttributeChanges ( identifyingAttributes , attributeDifference );
156
167
157
- verify ( identifyingAttributesChangeSet1 , times ( 1 ) ).add ( identifyingAttributes , attributeDifference );
158
- verify ( identifyingAttributesChangeSet2 , times ( 1 ) ).add ( identifyingAttributes , attributeDifference );
168
+ verify ( identifyingAttributesChangeSet1 , times ( 1 ) ).add ( eq ( identifyingAttributes ), any () );
169
+ verify ( identifyingAttributesChangeSet2 , times ( 1 ) ).add ( eq ( identifyingAttributes ), any () );
170
+ }
171
+
172
+ @ Test
173
+ void add_for_all_ident_without_warnings_should_inject_warnings () {
174
+ globalApplier .introduce ( actionReplayResult1 , actionChangeSet1 );
175
+ globalApplier .introduce ( actionReplayResult2 , actionChangeSet2 );
176
+
177
+ final AttributeDifference withoutWarnings = mock ( AttributeDifference .class );
178
+ when ( withoutWarnings .identifier () ).thenReturn ( "a" );
179
+
180
+ globalApplier .addChangeSetForAllEqualIdentAttributeChanges ( identifyingAttributes , withoutWarnings );
181
+
182
+ final ArgumentCaptor <AttributeDifference > captor = ArgumentCaptor .forClass ( AttributeDifference .class );
183
+ verify ( identifyingAttributesChangeSet1 , times ( 1 ) ).add ( any (), captor .capture () );
184
+ assertThat ( captor .getValue ().getElementIdentificationWarnings () ).hasSize ( 1 );
185
+
186
+ verify ( identifyingAttributesChangeSet2 , times ( 1 ) ).add ( any (), captor .capture () );
187
+ assertThat ( captor .getValue ().getElementIdentificationWarnings () ).hasSize ( 1 );
159
188
}
160
189
161
190
@ Test
@@ -165,8 +194,26 @@ void add_for_all_state_should_add_state_change_set() throws Exception {
165
194
166
195
globalApplier .createChangeSetForAllEqualAttributesChanges ( identifyingAttributes , attributeDifference );
167
196
168
- verify ( attributeChangeSet1 , times ( 1 ) ).add ( identifyingAttributes , attributeDifference );
169
- verify ( attributeChangeSet2 , times ( 1 ) ).add ( identifyingAttributes , attributeDifference );
197
+ verify ( attributeChangeSet1 , times ( 1 ) ).add ( eq ( identifyingAttributes ), any () );
198
+ verify ( attributeChangeSet2 , times ( 1 ) ).add ( eq ( identifyingAttributes ), any () );
199
+ }
200
+
201
+ @ Test
202
+ void add_for_all_state_without_warnings_should_inject_warnings () {
203
+ globalApplier .introduce ( actionReplayResult1 , actionChangeSet1 );
204
+ globalApplier .introduce ( actionReplayResult2 , actionChangeSet2 );
205
+
206
+ final AttributeDifference withoutWarnings = mock ( AttributeDifference .class );
207
+ when ( withoutWarnings .identifier () ).thenReturn ( "a" );
208
+
209
+ globalApplier .createChangeSetForAllEqualAttributesChanges ( identifyingAttributes , withoutWarnings );
210
+
211
+ final ArgumentCaptor <AttributeDifference > captor = ArgumentCaptor .forClass ( AttributeDifference .class );
212
+ verify ( attributeChangeSet1 , times ( 1 ) ).add ( any (), captor .capture () );
213
+ assertThat ( captor .getValue ().getElementIdentificationWarnings () ).hasSize ( 1 );
214
+
215
+ verify ( attributeChangeSet2 , times ( 1 ) ).add ( any (), captor .capture () );
216
+ assertThat ( captor .getValue ().getElementIdentificationWarnings () ).hasSize ( 1 );
170
217
}
171
218
172
219
@ Test
@@ -176,8 +223,26 @@ void remove_for_all_ident_should_remove_ident_change_set() throws Exception {
176
223
177
224
globalApplier .removeChangeSetForAllEqualIdentAttributeChanges ( identifyingAttributes , attributeDifference );
178
225
179
- verify ( identifyingAttributesChangeSet1 , times ( 1 ) ).remove ( identifyingAttributes , attributeDifference );
180
- verify ( identifyingAttributesChangeSet2 , times ( 1 ) ).remove ( identifyingAttributes , attributeDifference );
226
+ verify ( identifyingAttributesChangeSet1 , times ( 1 ) ).remove ( eq ( identifyingAttributes ), any () );
227
+ verify ( identifyingAttributesChangeSet2 , times ( 1 ) ).remove ( eq ( identifyingAttributes ), any () );
228
+ }
229
+
230
+ @ Test
231
+ void remove_for_all_ident_should_inject_warnings () {
232
+ globalApplier .introduce ( actionReplayResult1 , actionChangeSet1 );
233
+ globalApplier .introduce ( actionReplayResult2 , actionChangeSet2 );
234
+
235
+ final AttributeDifference withoutWarnings = mock ( AttributeDifference .class );
236
+ when ( withoutWarnings .identifier () ).thenReturn ( "a" );
237
+
238
+ globalApplier .removeChangeSetForAllEqualIdentAttributeChanges ( identifyingAttributes , withoutWarnings );
239
+
240
+ final ArgumentCaptor <AttributeDifference > captor = ArgumentCaptor .forClass ( AttributeDifference .class );
241
+ verify ( identifyingAttributesChangeSet1 , times ( 1 ) ).remove ( any (), captor .capture () );
242
+ assertThat ( captor .getValue ().getElementIdentificationWarnings () ).hasSize ( 1 );
243
+
244
+ verify ( identifyingAttributesChangeSet2 , times ( 1 ) ).remove ( any (), captor .capture () );
245
+ assertThat ( captor .getValue ().getElementIdentificationWarnings () ).hasSize ( 1 );
181
246
}
182
247
183
248
@ Test
@@ -187,8 +252,26 @@ void remove_for_all_state_should_remove_state_change_set() throws Exception {
187
252
188
253
globalApplier .removeChangeSetForAllEqualAttributesChanges ( identifyingAttributes , attributeDifference );
189
254
190
- verify ( attributeChangeSet1 , atLeastOnce () ).remove ( identifyingAttributes , attributeDifference );
191
- verify ( attributeChangeSet2 , atLeastOnce () ).remove ( identifyingAttributes , attributeDifference );
255
+ verify ( attributeChangeSet1 , atLeastOnce () ).remove ( eq ( identifyingAttributes ), any () );
256
+ verify ( attributeChangeSet2 , atLeastOnce () ).remove ( eq ( identifyingAttributes ), any () );
257
+ }
258
+
259
+ @ Test
260
+ void remove_for_all_state_should_inject_warnings () {
261
+ globalApplier .introduce ( actionReplayResult1 , actionChangeSet1 );
262
+ globalApplier .introduce ( actionReplayResult2 , actionChangeSet2 );
263
+
264
+ final AttributeDifference withoutWarnings = mock ( AttributeDifference .class );
265
+ when ( withoutWarnings .identifier () ).thenReturn ( "a" );
266
+
267
+ globalApplier .removeChangeSetForAllEqualAttributesChanges ( identifyingAttributes , withoutWarnings );
268
+
269
+ final ArgumentCaptor <AttributeDifference > captor = ArgumentCaptor .forClass ( AttributeDifference .class );
270
+ verify ( attributeChangeSet1 , times ( 1 ) ).remove ( any (), captor .capture () );
271
+ assertThat ( captor .getValue ().getElementIdentificationWarnings () ).hasSize ( 1 );
272
+
273
+ verify ( attributeChangeSet2 , times ( 1 ) ).remove ( any (), captor .capture () );
274
+ assertThat ( captor .getValue ().getElementIdentificationWarnings () ).hasSize ( 1 );
192
275
}
193
276
194
277
@ Test
0 commit comments