@@ -127,7 +127,7 @@ void interceptsSaveMethod() throws Throwable {
127
127
}
128
128
129
129
@ Test // DATACMNS-1663
130
- public void interceptsDeleteMethod () throws Throwable {
130
+ void interceptsDeleteMethod () throws Throwable {
131
131
SomeEvent event = new SomeEvent ();
132
132
MultipleEvents sample = MultipleEvents .of (Collections .singletonList (event ));
133
133
mockInvocation (invocation , SampleRepository .class .getMethod ("delete" , Object .class ), sample );
@@ -152,7 +152,7 @@ void doesNotInterceptNonSaveMethod() throws Throwable {
152
152
}
153
153
154
154
@ Test // DATACMNS-1663
155
- public void doesNotInterceptDeleteByIdMethod () throws Throwable {
155
+ void doesNotInterceptDeleteByIdMethod () throws Throwable {
156
156
157
157
doReturn (SampleRepository .class .getMethod ("deleteById" , Object .class )).when (invocation ).getMethod ();
158
158
@@ -204,7 +204,7 @@ void publishesEventsForCallToSaveWithIterable() throws Throwable {
204
204
}
205
205
206
206
@ Test // DATACMNS-1663
207
- public void publishesEventsForCallToDeleteWithIterable () throws Throwable {
207
+ void publishesEventsForCallToDeleteWithIterable () throws Throwable {
208
208
209
209
SomeEvent event = new SomeEvent ();
210
210
MultipleEvents sample = MultipleEvents .of (Collections .singletonList (event ));
@@ -217,6 +217,34 @@ public void publishesEventsForCallToDeleteWithIterable() throws Throwable {
217
217
verify (publisher ).publishEvent (any (SomeEvent .class ));
218
218
}
219
219
220
+ @ Test // GH-2448
221
+ void publishesEventsForCallToDeleteInBatchWithIterable () throws Throwable {
222
+
223
+ SomeEvent event = new SomeEvent ();
224
+ MultipleEvents sample = MultipleEvents .of (Collections .singletonList (event ));
225
+ mockInvocation (invocation , SampleRepository .class .getMethod ("deleteInBatch" , Iterable .class ), sample );
226
+
227
+ EventPublishingMethodInterceptor //
228
+ .of (EventPublishingMethod .of (MultipleEvents .class ), publisher )//
229
+ .invoke (invocation );
230
+
231
+ verify (publisher ).publishEvent (any (SomeEvent .class ));
232
+ }
233
+
234
+ @ Test // GH-2448
235
+ void publishesEventsForCallToDeleteAllInBatchWithIterable () throws Throwable {
236
+
237
+ SomeEvent event = new SomeEvent ();
238
+ MultipleEvents sample = MultipleEvents .of (Collections .singletonList (event ));
239
+ mockInvocation (invocation , SampleRepository .class .getMethod ("deleteAllInBatch" , Iterable .class ), sample );
240
+
241
+ EventPublishingMethodInterceptor //
242
+ .of (EventPublishingMethod .of (MultipleEvents .class ), publisher )//
243
+ .invoke (invocation );
244
+
245
+ verify (publisher ).publishEvent (any (SomeEvent .class ));
246
+ }
247
+
220
248
@ Test // DATACMNS-975
221
249
void publishesEventsAfterSaveInvocation () throws Throwable {
222
250
@@ -294,6 +322,17 @@ void publishesEventFromParameter() throws Throwable {
294
322
verify (publisher , times (1 )).publishEvent (event );
295
323
}
296
324
325
+ @ Test // GH-2448
326
+ void doesNotEmitEventsFromPrimitiveValue () throws Throwable {
327
+
328
+ Method method = SampleRepository .class .getMethod ("delete" , Object .class );
329
+ mockInvocation (invocation , method , "foo" , MultipleEvents .of (Collections .emptySet ()));
330
+
331
+ EventPublishingMethodInterceptor .of (EventPublishingMethod .of (MultipleEvents .class ), publisher ).invoke (invocation );
332
+
333
+ verify (publisher , never ()).publishEvent (any ());
334
+ }
335
+
297
336
private static void mockInvocation (MethodInvocation invocation , Method method , Object parameterAndReturnValue )
298
337
throws Throwable {
299
338
@@ -322,17 +361,23 @@ void clearDomainEvents() {}
322
361
}
323
362
324
363
@ Value (staticConstructor = "of" )
325
- static class OneEvent {
364
+ private static class OneEvent {
326
365
@ Getter (onMethod = @ __ (@ DomainEvents )) Object event ;
327
366
}
328
367
329
368
@ Value
330
- static class SomeEvent {
369
+ private static class SomeEvent {
331
370
UUID id = UUID .randomUUID ();
332
371
}
333
372
334
373
interface SampleRepository extends CrudRepository <MultipleEvents , Long > {
335
374
336
375
MultipleEvents saveAndFlush (MultipleEvents events );
376
+
377
+ MultipleEvents delete (String name );
378
+
379
+ MultipleEvents deleteAllInBatch (Iterable <MultipleEvents > events );
380
+
381
+ MultipleEvents deleteInBatch (Iterable <MultipleEvents > events );
337
382
}
338
383
}
0 commit comments