diff --git a/mapstruct/src/main/java/com/baeldung/expression/dto/LicenseDto.java b/mapstruct/src/main/java/com/baeldung/expression/dto/LicenseDto.java index 2121038cf332..025df1a4f655 100644 --- a/mapstruct/src/main/java/com/baeldung/expression/dto/LicenseDto.java +++ b/mapstruct/src/main/java/com/baeldung/expression/dto/LicenseDto.java @@ -15,6 +15,10 @@ public UUID getId() { return id; } + public void setId(UUID id) { + this.id = id; + } + public LocalDateTime getStartDate() { return startDate; } diff --git a/mapstruct/src/main/java/com/baeldung/expression/model/License.java b/mapstruct/src/main/java/com/baeldung/expression/model/License.java index 9e87be03d41f..71e4f086c0bb 100644 --- a/mapstruct/src/main/java/com/baeldung/expression/model/License.java +++ b/mapstruct/src/main/java/com/baeldung/expression/model/License.java @@ -3,9 +3,7 @@ import java.time.OffsetDateTime; import java.util.UUID; -import lombok.Data; -@Data public class License { private UUID id; @@ -18,4 +16,43 @@ public class License { private boolean renewalRequired; + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + public OffsetDateTime getStartDate() { + return startDate; + } + + public void setStartDate(OffsetDateTime startDate) { + this.startDate = startDate; + } + + public OffsetDateTime getEndDate() { + return endDate; + } + + public void setEndDate(OffsetDateTime endDate) { + this.endDate = endDate; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public boolean isRenewalRequired() { + return renewalRequired; + } + + public void setRenewalRequired(boolean renewalRequired) { + this.renewalRequired = renewalRequired; + } } 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 73be63561ba9..dcdda5c1ac78 100644 --- a/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java +++ b/mapstruct/src/test/java/com/baeldung/expression/mapper/LicenseMapperUnitTest.java @@ -4,6 +4,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.UUID; import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; @@ -61,4 +62,16 @@ void givenLicenseDtoWithEndDateInTwoWeeks_WhenMapperMethodIsInvoked_ThenLicenseS assertThat(license.isRenewalRequired()).isTrue(); } + @Test + 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()).isSameAs(id); + } + } \ No newline at end of file