From 9f579a9c6ce152af45f2efc3b66428e85c3b7fa2 Mon Sep 17 00:00:00 2001 From: Laura Cabantous-Taylor Date: Tue, 20 Jan 2026 12:18:45 +0000 Subject: [PATCH 1/7] Add validation rule for long term mentorship commitment --- .../wcc/platform/service/MentorshipService.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/wcc/platform/service/MentorshipService.java b/src/main/java/com/wcc/platform/service/MentorshipService.java index c2f5cd4a..caec66ef 100644 --- a/src/main/java/com/wcc/platform/service/MentorshipService.java +++ b/src/main/java/com/wcc/platform/service/MentorshipService.java @@ -63,6 +63,7 @@ public Mentor create(final Mentor mentor) { if (mentorExists.isPresent()) { throw new DuplicatedMemberException(mentorExists.get().getEmail()); } + validateMentorCommitment(mentor); return mentorRepository.create(mentor); } @@ -194,6 +195,21 @@ public Member updateMentor(final Long mentorId, final MentorDto mentorDto) { final var mentor = mentorOptional.orElseThrow(() -> new MemberNotFoundException(mentorId)); final Mentor updatedMentor = (Mentor) mentorDto.merge(mentor); + validateMentorCommitment(updatedMentor); return mentorRepository.update(mentorId, updatedMentor); } + + private void validateMentorCommitment(Mentor mentor) { + final var isLongTermMentorship = + mentor.getMenteeSection().mentorshipType().contains(MentorshipType.LONG_TERM); + + boolean hasInsufficientAvailability = + mentor.getMenteeSection().availability().stream() + .anyMatch(availability -> availability.hours() < 2); + + if (isLongTermMentorship && hasInsufficientAvailability) { + throw new IllegalArgumentException( + "Long-term mentorship requires mentor to commit at least 2 hours per month."); + } + } } From 85bccf43664587f946f5b49097046a3a524ac7a7 Mon Sep 17 00:00:00 2001 From: Laura Cabantous-Taylor Date: Tue, 20 Jan 2026 12:19:25 +0000 Subject: [PATCH 2/7] Test validation rule (WIP) --- .../service/MentorshipServiceTest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java index b8d2d59d..a27bd559 100644 --- a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java +++ b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java @@ -22,6 +22,8 @@ import static org.mockito.Mockito.withSettings; import com.wcc.platform.domain.cms.attributes.ImageType; +import com.wcc.platform.domain.cms.pages.mentorship.MenteeSection; +import com.wcc.platform.domain.cms.pages.mentorship.MentorMonthAvailability; import com.wcc.platform.domain.exceptions.DuplicatedMemberException; import com.wcc.platform.domain.exceptions.MemberNotFoundException; import com.wcc.platform.domain.platform.member.Member; @@ -93,6 +95,69 @@ void whenCreateGivenMentorDoesNotExistThenCreateMentor() { verify(mentorRepository).create(mentor); } + @Test + void whenCreateGivenLongTermMentorIsAvailableTwoHoursPerMonthThenCreateMentor() { + var mentor = mock(Mentor.class); + var menteeSection = mock(MenteeSection.class); + when(mentor.getId()).thenReturn(2L); + when(mentor.getMenteeSection()).thenReturn(menteeSection); + when(menteeSection.mentorshipType()) + .thenReturn(List.of(MentorshipType.AD_HOC, MentorshipType.LONG_TERM)); + when(menteeSection.availability()) + .thenReturn( + List.of( + new MentorMonthAvailability(Month.JANUARY, 3), + new MentorMonthAvailability(Month.FEBRUARY, 4))); + when(mentorRepository.findById(2L)).thenReturn(Optional.empty()); + when(mentorRepository.create(mentor)).thenReturn(mentor); + + var result = service.create(mentor); + + assertEquals(mentor, result); + verify(mentorRepository).create(mentor); + } + + @Test + void whenCreateGivenAdHocMentorIsNotAvailableTwoHoursPerMonthThenCreateMentor() { + var mentor = mock(Mentor.class); + var menteeSection = mock(MenteeSection.class); + when(mentor.getId()).thenReturn(2L); + when(mentor.getMenteeSection()).thenReturn(menteeSection); + when(menteeSection.mentorshipType()).thenReturn(List.of(MentorshipType.AD_HOC)); + when(menteeSection.availability()) + .thenReturn( + List.of( + new MentorMonthAvailability(Month.JANUARY, 1), + new MentorMonthAvailability(Month.FEBRUARY, 1))); + when(mentorRepository.findById(2L)).thenReturn(Optional.empty()); + when(mentorRepository.create(mentor)).thenReturn(mentor); + + var result = service.create(mentor); + + assertEquals(mentor, result); + verify(mentorRepository).create(mentor); + } + + @Test + void + whenCreateGivenLongTermMentorIsNotAvailableTwoHoursPerMonthThenThrowIllegalArgumentException() { + var mentor = mock(Mentor.class); + var menteeSection = mock(MenteeSection.class); + when(mentor.getId()).thenReturn(1L); + when(mentor.getMenteeSection()).thenReturn(menteeSection); + when(menteeSection.mentorshipType()) + .thenReturn(List.of(MentorshipType.AD_HOC, MentorshipType.LONG_TERM)); + when(menteeSection.availability()) + .thenReturn( + List.of( + new MentorMonthAvailability(Month.JANUARY, 1), + new MentorMonthAvailability(Month.FEBRUARY, 2))); + when(mentorRepository.findById(1L)).thenReturn(Optional.of(mentor)); + + assertThrows(DuplicatedMemberException.class, () -> service.create(mentor)); + verify(mentorRepository, never()).create(any()); + } + @Test void whenGetAllMentorsGivenCycleClosedThenReturnDtosWithoutCycle() { var mentor = mock(Mentor.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS)); From 26495c3ee638d52bd7e6458234792373e3fe0e39 Mon Sep 17 00:00:00 2001 From: Laura Cabantous-Taylor Date: Tue, 20 Jan 2026 12:52:01 +0000 Subject: [PATCH 3/7] Fix tests to validate availability rule on mentor creation --- .../wcc/platform/service/MentorshipServiceTest.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java index a27bd559..4d009aee 100644 --- a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java +++ b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java @@ -85,7 +85,9 @@ void whenCreateGivenMentorAlreadyExistsThenThrowDuplicatedMemberException() { @Test void whenCreateGivenMentorDoesNotExistThenCreateMentor() { var mentor = mock(Mentor.class); + var menteeSection = mock(MenteeSection.class); when(mentor.getId()).thenReturn(2L); + when(mentor.getMenteeSection()).thenReturn(menteeSection); when(mentorRepository.findById(2L)).thenReturn(Optional.empty()); when(mentorRepository.create(mentor)).thenReturn(mentor); @@ -96,7 +98,7 @@ void whenCreateGivenMentorDoesNotExistThenCreateMentor() { } @Test - void whenCreateGivenLongTermMentorIsAvailableTwoHoursPerMonthThenCreateMentor() { + void whenCreateGivenLongTermMentorAndTwoHoursAvailabilityThenCreateMentor() { var mentor = mock(Mentor.class); var menteeSection = mock(MenteeSection.class); when(mentor.getId()).thenReturn(2L); @@ -118,7 +120,7 @@ void whenCreateGivenLongTermMentorIsAvailableTwoHoursPerMonthThenCreateMentor() } @Test - void whenCreateGivenAdHocMentorIsNotAvailableTwoHoursPerMonthThenCreateMentor() { + void whenCreateGivenAdHocMentorAndUnavailabilityThenCreateMentor() { var mentor = mock(Mentor.class); var menteeSection = mock(MenteeSection.class); when(mentor.getId()).thenReturn(2L); @@ -139,8 +141,7 @@ void whenCreateGivenAdHocMentorIsNotAvailableTwoHoursPerMonthThenCreateMentor() } @Test - void - whenCreateGivenLongTermMentorIsNotAvailableTwoHoursPerMonthThenThrowIllegalArgumentException() { + void whenCreateGivenLongTermMentorAndUnavailabilityThenThrowIllegalArgumentException() { var mentor = mock(Mentor.class); var menteeSection = mock(MenteeSection.class); when(mentor.getId()).thenReturn(1L); @@ -152,9 +153,9 @@ void whenCreateGivenAdHocMentorIsNotAvailableTwoHoursPerMonthThenCreateMentor() List.of( new MentorMonthAvailability(Month.JANUARY, 1), new MentorMonthAvailability(Month.FEBRUARY, 2))); - when(mentorRepository.findById(1L)).thenReturn(Optional.of(mentor)); + when(mentorRepository.findById(1L)).thenReturn(Optional.empty()); - assertThrows(DuplicatedMemberException.class, () -> service.create(mentor)); + assertThrows(IllegalArgumentException.class, () -> service.create(mentor)); verify(mentorRepository, never()).create(any()); } From 1b7a7eb430f925be9572a3aa67de8e65d10f3f7d Mon Sep 17 00:00:00 2001 From: Laura Cabantous-Taylor Date: Tue, 20 Jan 2026 18:37:33 +0000 Subject: [PATCH 4/7] Add tests to validate availability rule on mentor update --- .../factories/SetupMentorFactories.java | 65 ++++++++++++++ .../service/MentorshipServiceTest.java | 86 ++++++++++++++++++- 2 files changed, 148 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/wcc/platform/factories/SetupMentorFactories.java b/src/test/java/com/wcc/platform/factories/SetupMentorFactories.java index 3577f500..22d4b5af 100644 --- a/src/test/java/com/wcc/platform/factories/SetupMentorFactories.java +++ b/src/test/java/com/wcc/platform/factories/SetupMentorFactories.java @@ -108,6 +108,38 @@ public static MentorDto createMentorDtoTest(final Long mentorId, final MemberTyp .build(); } + /** Factory test to create MemberDto object with mentorshipTypes and availabilities params. */ + public static MentorDto createMentorDtoTest( + final Long mentorId, + final MemberType type, + final List mentorshipTypes, + final List availabilities) { + return MentorDto.mentorDtoBuilder() + .id(mentorId) + .fullName("fullName " + type.name()) + .position("position " + type.name()) + .email("email@" + type.name().toLowerCase()) + .slackDisplayName("slackDisplayName") + .country(new Country("ES", "Spain")) + .city("City") + .companyName("Company name") + .images(List.of(new Image("image.png", "alt image", ImageType.MOBILE))) + .network(List.of(new SocialNetwork(SocialNetworkType.GITHUB, "collaborator_link_updated"))) + .profileStatus(ProfileStatus.ACTIVE) + .bio("Mentor bio") + .spokenLanguages(List.of("English")) + .skills( + new Skills( + 2, + List.of(TechnicalArea.BACKEND, TechnicalArea.FRONTEND), + List.of(Languages.JAVASCRIPT), + List.of(MentorshipFocusArea.GROW_BEGINNER_TO_MID))) + .menteeSection( + new MenteeSection( + mentorshipTypes, availabilities, "ideal mentee description", "additional")) + .build(); + } + /** Test factory for updated Mentor. */ public static Mentor createUpdatedMentorTest(final Mentor mentor, final MentorDto mentorDto) { @@ -137,6 +169,39 @@ public static Mentor createUpdatedMentorTest(final Mentor mentor, final MentorDt .build(); } + /** Test factory for updated Mentor with mentorship types and availabilities params. */ + public static Mentor createUpdatedMentorTest( + final Mentor mentor, + final MentorDto mentorDto, + final List mentorshipTypes, + final List availabilities) { + + return Mentor.mentorBuilder() + .id(mentor.getId()) + .fullName(mentorDto.getFullName()) + .position(mentorDto.getPosition()) + .email(mentorDto.getEmail()) + .slackDisplayName(mentorDto.getSlackDisplayName()) + .country(mentorDto.getCountry()) + .images(mentorDto.getImages()) + .profileStatus(ProfileStatus.ACTIVE) + .bio("Mentor bio UPDATED") + .spokenLanguages(List.of("English", "German")) + .skills( + new Skills( + 5, + List.of(TechnicalArea.BACKEND), + List.of(Languages.JAVASCRIPT, Languages.C_LANGUAGE), + List.of(MentorshipFocusArea.CHANGE_SPECIALISATION))) + .menteeSection( + new MenteeSection( + mentorshipTypes, + availabilities, + "ideal mentee description UPDATED", + "additional UPDATED")) + .build(); + } + /** Creates a test MemberProfilePicture with associated Resource. */ public static MemberProfilePicture createMemberProfilePictureTest(final Long memberId) { return MemberProfilePicture.builder() diff --git a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java index 4d009aee..8cb97aa6 100644 --- a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java +++ b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java @@ -98,7 +98,10 @@ void whenCreateGivenMentorDoesNotExistThenCreateMentor() { } @Test - void whenCreateGivenLongTermMentorAndTwoHoursAvailabilityThenCreateMentor() { + @DisplayName( + "Given mentor with long-term mentorship and 2+ hours commitment When creating Then create" + + " mentor and return it") + void testCreateAvailableLongTermMentor() { var mentor = mock(Mentor.class); var menteeSection = mock(MenteeSection.class); when(mentor.getId()).thenReturn(2L); @@ -120,7 +123,10 @@ void whenCreateGivenLongTermMentorAndTwoHoursAvailabilityThenCreateMentor() { } @Test - void whenCreateGivenAdHocMentorAndUnavailabilityThenCreateMentor() { + @DisplayName( + "Given mentor with adhoc mentorship and under 2 hours commitment When creating Then create" + + " mentor and return it") + void testCreateUnavailableAdHocMentor() { var mentor = mock(Mentor.class); var menteeSection = mock(MenteeSection.class); when(mentor.getId()).thenReturn(2L); @@ -141,7 +147,10 @@ void whenCreateGivenAdHocMentorAndUnavailabilityThenCreateMentor() { } @Test - void whenCreateGivenLongTermMentorAndUnavailabilityThenThrowIllegalArgumentException() { + @DisplayName( + "Given mentor with long-term mentorship and 2+ hours commitment When creating the" + + " mentor Then throw IllegalArgumentException") + void testCreateUnavailableLongTermMentor() { var mentor = mock(Mentor.class); var menteeSection = mock(MenteeSection.class); when(mentor.getId()).thenReturn(1L); @@ -295,6 +304,77 @@ void testUpdateMentorIllegalIdMismatch() { verify(mentorRepository, never()).update(anyLong(), any()); } + @Test + @DisplayName( + "Given mentor with long-term mentorship and 2+ hours commitment When updating the mentor" + + " Then update and return it") + void testUpdateLongTermMentorAvailableTwoHours() { + final var updatedMentorWithAvailabilities = + createUpdatedMentorTest( + mentor, + mentorDto, + List.of(MentorshipType.AD_HOC, MentorshipType.LONG_TERM), + List.of( + new MentorMonthAvailability(Month.JANUARY, 2), + new MentorMonthAvailability(Month.FEBRUARY, 2))); + long mentorId = 1L; + var mentor = mock(Mentor.class); + when(mentorRepository.findById(mentorId)).thenReturn(Optional.of(mentor)); + when(mentorRepository.update(anyLong(), any())).thenReturn(updatedMentorWithAvailabilities); + Member result = service.updateMentor(mentorId, mentorDto); + + assertEquals(updatedMentorWithAvailabilities, result); + verify(mentorRepository).findById(mentorId); + verify(mentorRepository).update(anyLong(), any()); + } + + @Test + @DisplayName( + "Given mentor with adhoc mentorship and under 2 hours commitment When updating the mentor" + + " Then update and return it") + void testUpdateUnavailableAdHocMentor() { + final var updatedMentorWithAvailabilities = + createUpdatedMentorTest( + mentor, + mentorDto, + List.of(MentorshipType.AD_HOC), + List.of( + new MentorMonthAvailability(Month.JANUARY, 1), + new MentorMonthAvailability(Month.FEBRUARY, 0))); + long mentorId = 1L; + when(mentorRepository.findById(mentorId)).thenReturn(Optional.of(mentor)); + when(mentorRepository.update(anyLong(), any())).thenReturn(updatedMentorWithAvailabilities); + + Member result = service.updateMentor(mentorId, mentorDto); + + assertEquals(updatedMentorWithAvailabilities, result); + verify(mentorRepository).findById(mentorId); + verify(mentorRepository).update(anyLong(), any()); + } + + @Test + @DisplayName( + "Given mentor with long-term mentorship and under 2 hours commitment" + + " When updating the mentor Then throw IllegalArgumentException") + void testUpdateUnavailableLongTermMentorIllegalArgumentException() { + long mentorId = 1L; + MentorDto newMentorDto = + createMentorDtoTest( + 1L, + MemberType.DIRECTOR, + List.of(MentorshipType.AD_HOC, MentorshipType.LONG_TERM), + List.of( + new MentorMonthAvailability(Month.JANUARY, 2), + new MentorMonthAvailability(Month.FEBRUARY, 0))); + when(mentorRepository.findById(mentorId)).thenReturn(Optional.of(mentor)); + + assertThrows( + IllegalArgumentException.class, () -> service.updateMentor(mentorId, newMentorDto)); + + verify(mentorRepository).findById(anyLong()); + verify(mentorRepository, never()).update(anyLong(), any()); + } + @Test @DisplayName( "Given mentor with profile picture, when getAllMentors is called, then images list should" From 20593ba4238185d80adcf32c959fcf3860a07b9d Mon Sep 17 00:00:00 2001 From: Laura Cabantous-Taylor Date: Tue, 20 Jan 2026 20:08:20 +0000 Subject: [PATCH 5/7] Fix failing tests --- .../wcc/platform/service/MentorshipServiceTest.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java index e8fc974f..1a0e39dc 100644 --- a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java +++ b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java @@ -78,9 +78,9 @@ void setUp() { void whenCreateGivenMentorAlreadyExistsThenThrowDuplicatedMemberException() { var mentor = mock(Mentor.class); when(mentor.getId()).thenReturn(1L); + when(mentorRepository.findById(1L)).thenReturn(Optional.of(mentor)); when(mentor.getEmail()).thenReturn("test@test.com"); when(memberRepository.findByEmail("test@test.com")).thenReturn(Optional.empty()); - when(mentorRepository.findById(1L)).thenReturn(Optional.of(mentor)); assertThrows(DuplicatedMemberException.class, () -> service.create(mentor)); verify(mentorRepository, never()).create(any()); @@ -327,7 +327,6 @@ void testUpdateLongTermMentorAvailableTwoHours() { new MentorMonthAvailability(Month.JANUARY, 2), new MentorMonthAvailability(Month.FEBRUARY, 2))); long mentorId = 1L; - var mentor = mock(Mentor.class); when(mentorRepository.findById(mentorId)).thenReturn(Optional.of(mentor)); when(mentorRepository.update(anyLong(), any())).thenReturn(updatedMentorWithAvailabilities); Member result = service.updateMentor(mentorId, mentorDto); @@ -461,18 +460,20 @@ void shouldUseExistingMemberWhenMentorEmailAlreadyExists() { when(mentor.getFullName()).thenReturn("Existing Member as Mentor"); when(mentor.getPosition()).thenReturn("Software Engineer"); when(mentor.getSlackDisplayName()).thenReturn("@existing"); - when(mentor.getCountry()).thenReturn(mock(com.wcc.platform.domain.cms.attributes.Country.class)); + when(mentor.getCountry()) + .thenReturn(mock(com.wcc.platform.domain.cms.attributes.Country.class)); when(mentor.getCity()).thenReturn("New York"); when(mentor.getCompanyName()).thenReturn("Tech Corp"); when(mentor.getImages()).thenReturn(List.of()); when(mentor.getNetwork()).thenReturn(List.of()); when(mentor.getProfileStatus()) .thenReturn(com.wcc.platform.domain.platform.member.ProfileStatus.ACTIVE); - when(mentor.getSkills()).thenReturn(mock(com.wcc.platform.domain.platform.mentorship.Skills.class)); + when(mentor.getSkills()) + .thenReturn(mock(com.wcc.platform.domain.platform.mentorship.Skills.class)); when(mentor.getSpokenLanguages()).thenReturn(List.of("English")); when(mentor.getBio()).thenReturn("Bio"); - when(mentor.getMenteeSection()).thenReturn( - mock(com.wcc.platform.domain.cms.pages.mentorship.MenteeSection.class)); + when(mentor.getMenteeSection()) + .thenReturn(mock(com.wcc.platform.domain.cms.pages.mentorship.MenteeSection.class)); when(mentor.getFeedbackSection()).thenReturn(null); when(mentor.getResources()).thenReturn(null); From fbe77efcc9784011b7d07eba5e0a8767497f1aae Mon Sep 17 00:00:00 2001 From: Laura Cabantous-Taylor Date: Tue, 20 Jan 2026 20:43:00 +0000 Subject: [PATCH 6/7] Refactor validation method --- .../wcc/platform/service/MentorshipService.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/wcc/platform/service/MentorshipService.java b/src/main/java/com/wcc/platform/service/MentorshipService.java index cfdcb5f2..cbd823b5 100644 --- a/src/main/java/com/wcc/platform/service/MentorshipService.java +++ b/src/main/java/com/wcc/platform/service/MentorshipService.java @@ -37,6 +37,7 @@ public class MentorshipService { private static final String EUROPE_LONDON = "Europe/London"; private static final MentorshipCycle ACTIVE_LONG_TERM = new MentorshipCycle(MentorshipType.LONG_TERM, Month.MARCH); + private static final int MINIMUM_HOURS = 2; private final MentorRepository mentorRepository; private final MemberRepository memberRepository; @@ -231,15 +232,15 @@ public Mentor updateMentor(final Long mentorId, final MentorDto mentorDto) { return mentorRepository.update(mentorId, updatedMentor); } - private void validateMentorCommitment(Mentor mentor) { - final var isLongTermMentorship = - mentor.getMenteeSection().mentorshipType().contains(MentorshipType.LONG_TERM); + private void validateMentorCommitment(final Mentor mentor) { + final var menteeSection = mentor.getMenteeSection(); + final boolean isLongTermMentorship = + menteeSection.mentorshipType().contains(MentorshipType.LONG_TERM); + final boolean hasInsufficientHours = + menteeSection.availability().stream() + .anyMatch(availability -> availability.hours() < MINIMUM_HOURS); - boolean hasInsufficientAvailability = - mentor.getMenteeSection().availability().stream() - .anyMatch(availability -> availability.hours() < 2); - - if (isLongTermMentorship && hasInsufficientAvailability) { + if (isLongTermMentorship && hasInsufficientHours) { throw new IllegalArgumentException( "Long-term mentorship requires mentor to commit at least 2 hours per month."); } From a3e872349d3569a4e32251d3e59a5bf5c93d945a Mon Sep 17 00:00:00 2001 From: Laura Cabantous-Taylor Date: Wed, 21 Jan 2026 18:31:42 +0000 Subject: [PATCH 7/7] Add assertion on exception messages --- .../wcc/platform/service/MentorshipServiceTest.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java index 1a0e39dc..5947ecb2 100644 --- a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java +++ b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java @@ -171,7 +171,10 @@ void testCreateUnavailableLongTermMentor() { new MentorMonthAvailability(Month.FEBRUARY, 2))); when(mentorRepository.findById(1L)).thenReturn(Optional.empty()); - assertThrows(IllegalArgumentException.class, () -> service.create(mentor)); + var expectedMsg = "Long-term mentorship requires mentor to commit at least 2 hours per month."; + var exception = assertThrows(IllegalArgumentException.class, () -> service.create(mentor)); + + assertEquals(expectedMsg, exception.getMessage()); verify(mentorRepository, never()).create(any()); } @@ -376,8 +379,11 @@ void testUpdateUnavailableLongTermMentorIllegalArgumentException() { new MentorMonthAvailability(Month.FEBRUARY, 0))); when(mentorRepository.findById(mentorId)).thenReturn(Optional.of(mentor)); - assertThrows( - IllegalArgumentException.class, () -> service.updateMentor(mentorId, newMentorDto)); + var expectedMsg = "Long-term mentorship requires mentor to commit at least 2 hours per month."; + var exception = + assertThrows( + IllegalArgumentException.class, () -> service.updateMentor(mentorId, newMentorDto)); + assertEquals(expectedMsg, exception.getMessage()); verify(mentorRepository).findById(anyLong()); verify(mentorRepository, never()).update(anyLong(), any());