From 28c56a4fd6e062109beb7d89e36e9c5fdceed5a3 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 2 Oct 2024 12:12:04 +0200 Subject: [PATCH] extract assertEventStatus --- ...omainSetupHostingAssetFactoryUnitTest.java | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/factories/DomainSetupHostingAssetFactoryUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/factories/DomainSetupHostingAssetFactoryUnitTest.java index 9220f509..5a846260 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/factories/DomainSetupHostingAssetFactoryUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/factories/DomainSetupHostingAssetFactoryUnitTest.java @@ -119,16 +119,8 @@ class DomainSetupHostingAssetFactoryUnitTest { ); // then - emwFake.stream(BookingItemCreatedEventEntity.class) - .reduce(EntityManagerWrapperFake::toSingleElement) - .map(eventEntity -> { - assertThat(eventEntity.getBookingItem()).isSameAs(givenBookingItem); - assertThat(eventEntity.getAssetJson()).isEqualTo(givenAssetJson); - assertThat(eventEntity.getStatusMessage()).isEqualTo( - "[[DNS] no TXT record 'Hostsharing-domain-setup-verification-code=null' found for domain name 'example.org' (nor in its super-domain)]" - ); - return true; - }); + assertEventStatus(givenBookingItem, givenAssetJson, + "[[DNS] no TXT record 'Hostsharing-domain-setup-verification-code=null' found for domain name 'example.org' (nor in its super-domain)]"); } @Test @@ -164,15 +156,8 @@ class DomainSetupHostingAssetFactoryUnitTest { ); // then - emwFake.stream(BookingItemCreatedEventEntity.class) - .reduce(EntityManagerWrapperFake::toSingleElement) - .map(eventEntity -> { - assertThat(eventEntity.getBookingItem()).isSameAs(givenBookingItem); - assertThat(eventEntity.getAssetJson()).isEqualTo(givenAssetJson); - assertThat(eventEntity.getStatusMessage()).isEqualTo( - "domain DNS setup not allowed for legacy compatibility"); - return true; - }); + assertEventStatus(givenBookingItem, givenAssetJson, + "domain DNS setup not allowed for legacy compatibility"); } @SafeVarargs @@ -182,4 +167,20 @@ class DomainSetupHostingAssetFactoryUnitTest { .resources(Map.ofEntries(givenResources)) .build(); } + + private void assertEventStatus( + final HsBookingItemRealEntity givenBookingItem, + final String givenAssetJson, + final String expected) { + emwFake.stream(BookingItemCreatedEventEntity.class) + .reduce(EntityManagerWrapperFake::toSingleElement) + .map(eventEntity -> { + assertThat(eventEntity.getBookingItem()).isSameAs(givenBookingItem); + assertThat(eventEntity.getAssetJson()).isEqualTo(givenAssetJson); + assertThat(eventEntity.getStatusMessage()).isEqualTo( + expected + ); + return true; + }); + } }