FINERACT-2081: Add assertions to BulkBusinessEventTest

This commit is contained in:
Hossam Hatem
2025-02-28 12:13:28 +01:00
committed by Adam Saghy
parent e1165e813a
commit 142f63ca17
@@ -33,26 +33,39 @@ class BulkBusinessEventTest {
@Test @Test
public void testConstructorWorksForSameAggregateId() { public void testConstructorWorksForSameAggregateId() {
// given // given
List<BusinessEvent<?>> events = List.of(new ClientCreateBusinessEvent(client(1L)), new ClientActivateBusinessEvent(client(1L)));
// when // when
new BulkBusinessEvent(List.of(new ClientCreateBusinessEvent(client(1L)), new ClientActivateBusinessEvent(client(1L)))); BulkBusinessEvent bulkEvent = new BulkBusinessEvent(events);
// then no exception thrown
// then
Assertions.assertEquals(1L, bulkEvent.getAggregateRootId());
Assertions.assertEquals(events, bulkEvent.get());
Assertions.assertEquals(BulkBusinessEvent.TYPE, bulkEvent.getType());
Assertions.assertEquals("Bulk", bulkEvent.getCategory());
} }
@Test @Test
public void testConstructorThrowsExceptionForDifferentAggregateId() { public void testConstructorThrowsExceptionForDifferentAggregateId() {
// given // given
// when List<BusinessEvent<?>> events = List.of(new ClientCreateBusinessEvent(client(1L)), new ClientActivateBusinessEvent(client(2L)));
Assertions.assertThrows(IllegalArgumentException.class, () -> new BulkBusinessEvent(
List.of(new ClientCreateBusinessEvent(client(1L)), new ClientActivateBusinessEvent(client(2L))))); // when/then
// then no exception thrown IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> new BulkBusinessEvent(events));
Assertions.assertEquals("The business events are related to multiple aggregate roots which is not allowed", exception.getMessage());
} }
@Test @Test
public void testConstructorWorksForNullAggregateId() { public void testConstructorWorksForNullAggregateId() {
// given // given
List<BusinessEvent<?>> events = List.of(new ClientCreateBusinessEvent(client(1L)), new ClientActivateBusinessEvent(client(null)));
// when // when
new BulkBusinessEvent(List.of(new ClientCreateBusinessEvent(client(1L)), new ClientActivateBusinessEvent(client(null)))); BulkBusinessEvent bulkEvent = new BulkBusinessEvent(events);
// then no exception thrown
// then
Assertions.assertEquals(1L, bulkEvent.getAggregateRootId());
Assertions.assertEquals(events, bulkEvent.get());
} }
private Client client(Long id) { private Client client(Long id) {
@@ -60,5 +73,4 @@ class BulkBusinessEventTest {
given(client.getId()).willReturn(id); given(client.getId()).willReturn(id);
return client; return client;
} }
} }