这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
import java.time.LocalDateTime;
import java.util.UUID;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

@AllArgsConstructor
@Data
@Builder
public class LicenseDto {

private UUID id;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The id field is actually unused and unmapped - can we update the LicenseMapper to map this field, just to have a complete example? And add one more unit test to show the mapping. We do not need to make any changes to the article, since this change is unrelated to the topic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, usually id are populated by the database when the License entity is being used persisted, hence I didn't explicitly add any mapping. But I can dd it if it will make more sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just saw PR is already merged, let me raise another PR

Expand All @@ -18,4 +11,24 @@ public class LicenseDto {

private LocalDateTime endDate;

public UUID getId() {
return id;
}

public LocalDateTime getStartDate() {
return startDate;
}

public void setStartDate(LocalDateTime startDate) {
this.startDate = startDate;
}

public LocalDateTime getEndDate() {
return endDate;
}

public void setEndDate(LocalDateTime endDate) {
this.endDate = endDate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class LicenseMapperUnitTest {

@Test
void givenLicenseDtoWithStartDateAndWithoutEndDate_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithDefaultEndDate() {
License license = licenseMapper.toLicense(LicenseDto.builder()
.startDate(LocalDateTime.now())
.build());
LicenseDto licenseDto = new LicenseDto();
licenseDto.setStartDate(LocalDateTime.now());
License license = licenseMapper.toLicense(licenseDto);
assertThat(license).isNotNull();
assertThat(license.getEndDate()
.toLocalDate()).isEqualTo(LocalDate.now()
Expand All @@ -28,19 +28,19 @@ void givenLicenseDtoWithStartDateAndWithoutEndDate_WhenMapperMethodIsInvoked_The

@Test
void givenLicenseDtoWithEndDateAndWithoutStartDate_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithDefaultStartDate() {
License license = licenseMapper.toLicense(LicenseDto.builder()
.endDate(LocalDateTime.now()
.plusYears(2))
.build());
LicenseDto licenseDto = new LicenseDto();
licenseDto.setEndDate(LocalDateTime.now()
.plusYears(2));
License license = licenseMapper.toLicense(licenseDto);
assertThat(license).isNotNull();
assertThat(license.getStartDate()
.toLocalDate()).isEqualTo(LocalDate.now());
}

@Test
void givenLicenseDtoWithoutStartDateAndEndDate_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithDefaultDetails() {
License license = licenseMapper.toLicense(LicenseDto.builder()
.build());
LicenseDto licenseDto = new LicenseDto();
License license = licenseMapper.toLicense(licenseDto);
assertThat(license).isNotNull();
assertThat(license.getStartDate()
.toLocalDate()).isEqualTo(LocalDate.now());
Expand All @@ -53,10 +53,10 @@ void givenLicenseDtoWithoutStartDateAndEndDate_WhenMapperMethodIsInvoked_ThenLic

@Test
void givenLicenseDtoWithEndDateInTwoWeeks_WhenMapperMethodIsInvoked_ThenLicenseShouldBePopulatedWithRenewalRequiredSetToTrue() {
License license = licenseMapper.toLicense(LicenseDto.builder()
.endDate(LocalDateTime.now()
.plusDays(10))
.build());
LicenseDto licenseDto = new LicenseDto();
licenseDto.setEndDate(LocalDateTime.now()
.plusDays(10));
License license = licenseMapper.toLicense(licenseDto);
assertThat(license).isNotNull();
assertThat(license.isRenewalRequired()).isTrue();
}
Expand Down