From 2a7f3fbc54ae722b336f05351ab2b9c44ffd1c86 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Tue, 5 Sep 2023 10:04:58 +0530 Subject: [PATCH] BAEL-6572: Modified test to validateId mapping --- .../java/com/baeldung/expression/mapper/LicenseMapper.java | 6 ------ .../baeldung/expression/mapper/LicenseMapperUnitTest.java | 6 ++++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/mapstruct/src/main/java/com/baeldung/expression/mapper/LicenseMapper.java b/mapstruct/src/main/java/com/baeldung/expression/mapper/LicenseMapper.java index 8bfcd8b14b..100588b45d 100644 --- a/mapstruct/src/main/java/com/baeldung/expression/mapper/LicenseMapper.java +++ b/mapstruct/src/main/java/com/baeldung/expression/mapper/LicenseMapper.java @@ -4,7 +4,6 @@ import java.time.Duration; import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.time.ZoneOffset; -import java.util.UUID; import org.mapstruct.AfterMapping; import org.mapstruct.Mapper; @@ -21,7 +20,6 @@ public interface LicenseMapper { @Mapping(target = "endDate", ignore = true) @Mapping(target = "active", constant = "true") @Mapping(target = "renewalRequired", conditionExpression = "java(isEndDateInTwoWeeks(licenseDto))", source = ".") - @Mapping(target = "id", expression = "java(setId())") License toLicense(LicenseDto licenseDto); @AfterMapping @@ -42,8 +40,4 @@ public interface LicenseMapper { .toDays() <= 14; } - default UUID setId() { - return UUID.randomUUID(); - } - } diff --git a/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java b/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java index 1c22f972a9..dcdda5c1ac 100644 --- a/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java +++ b/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java @@ -63,13 +63,15 @@ class LicenseMapperUnitTest { } @Test - void givenLicenseDtoWithValidDetails_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithValidId() { + void givenLicenseDtoWithoutId_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithValidId() { LicenseDto licenseDto = new LicenseDto(); + UUID id = UUID.randomUUID(); + licenseDto.setId(id); licenseDto.setEndDate(LocalDateTime.now() .plusDays(10)); License license = licenseMapper.toLicense(licenseDto); assertThat(license).isNotNull(); - assertThat(license.getId()).isNotNull(); + assertThat(license.getId()).isSameAs(id); } } \ No newline at end of file