diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcher.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcher.java index 092a0a9b..914c8230 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcher.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcher.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.hs.office.debitor; +import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource; import net.hostsharing.hsadminng.mapper.EntityPatcher; @@ -35,6 +36,10 @@ class HsOfficeDebitorEntityPatcher implements EntityPatcher { + verifyNotNull(newValue, "refundBankAccount"); + entity.setRefundBankAccount(em.getReference(HsOfficeBankAccountEntity.class, newValue)); + }); } private void verifyNotNull(final Object newValue, final String propertyName) { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java index d94e9323..1983df59 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityPatcherUnitTest.java @@ -1,5 +1,6 @@ package net.hostsharing.hsadminng.hs.office.debitor; +import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; @@ -42,6 +43,9 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< private static final boolean INITIAL_VAT_REVERSE_CHARGE = true; private static final boolean PATCHED_VAT_REVERSE_CHARGE = false; + private static final UUID INITIAL_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID(); + private static final UUID PATCHED_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID(); + private final HsOfficePartnerEntity givenInitialPartner = HsOfficePartnerEntity.builder() .uuid(INITIAL_PARTNER_UUID) .build(); @@ -49,6 +53,10 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< private final HsOfficeContactEntity givenInitialContact = HsOfficeContactEntity.builder() .uuid(INITIAL_CONTACT_UUID) .build(); + + private final HsOfficeBankAccountEntity givenInitialBankAccount = HsOfficeBankAccountEntity.builder() + .uuid(INITIAL_REFUND_BANK_ACCOUNT_UUID) + .build(); @Mock private EntityManager em; @@ -56,8 +64,8 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< void initMocks() { lenient().when(em.getReference(eq(HsOfficeContactEntity.class), any())).thenAnswer(invocation -> HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build()); - lenient().when(em.getReference(eq(HsOfficeContactEntity.class), any())).thenAnswer(invocation -> - HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build()); + lenient().when(em.getReference(eq(HsOfficeBankAccountEntity.class), any())).thenAnswer(invocation -> + HsOfficeBankAccountEntity.builder().uuid(invocation.getArgument(1)).build()); } @Override @@ -72,6 +80,7 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< entity.setVatBusiness(true); entity.setVatReverseCharge(INITIAL_VAT_REVERSE_CHARGE); entity.setDefaultPrefix("abc"); + entity.setRefundBankAccount(givenInitialBankAccount); return entity; } @@ -120,7 +129,7 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< new SimpleProperty<>( "personType", HsOfficeDebitorPatchResource::setVatBusiness, - PATCHED_BILLABLE, + PATCHED_VAT_BUSINESS, HsOfficeDebitorEntity::setVatBusiness) .notNullable(), new SimpleProperty<>( @@ -134,6 +143,13 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< HsOfficeDebitorPatchResource::setDefaultPrefix, PATCHED_DEFAULT_PREFIX, HsOfficeDebitorEntity::setDefaultPrefix) + .notNullable(), + new JsonNullableProperty<>( + "refundBankAccount", + HsOfficeDebitorPatchResource::setRefundBankAccountUuid, + PATCHED_REFUND_BANK_ACCOUNT_UUID, + HsOfficeDebitorEntity::setRefundBankAccount, + newBankAccount(PATCHED_REFUND_BANK_ACCOUNT_UUID)) .notNullable() ); } @@ -143,4 +159,10 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase< newContact.setUuid(uuid); return newContact; } + + private HsOfficeBankAccountEntity newBankAccount(final UUID uuid) { + final var newBankAccount = new HsOfficeBankAccountEntity(); + newBankAccount.setUuid(uuid); + return newBankAccount; + } } diff --git a/src/test/java/net/hostsharing/test/PatchUnitTestBase.java b/src/test/java/net/hostsharing/test/PatchUnitTestBase.java index 7be61b19..51f78bb4 100644 --- a/src/test/java/net/hostsharing/test/PatchUnitTestBase.java +++ b/src/test/java/net/hostsharing/test/PatchUnitTestBase.java @@ -1,5 +1,6 @@ package net.hostsharing.test; +import net.hostsharing.hsadminng.hs.office.migration.HasUuid; import net.hostsharing.hsadminng.mapper.EntityPatcher; import org.junit.jupiter.api.Named; import org.junit.jupiter.api.Test; @@ -232,7 +233,7 @@ public abstract class PatchUnitTestBase { } } - protected static class JsonNullableProperty extends Property { + protected static class JsonNullableProperty extends Property { private final BiConsumer> resourceSetter; public final RV givenPatchValue;