diff --git a/skill-tree/src/test/java/com/RDS/skilltree/unit/EndorsementServiceTest.java b/skill-tree/src/test/java/com/RDS/skilltree/unit/EndorsementServiceTest.java index c3df10a1..d3047097 100644 --- a/skill-tree/src/test/java/com/RDS/skilltree/unit/EndorsementServiceTest.java +++ b/skill-tree/src/test/java/com/RDS/skilltree/unit/EndorsementServiceTest.java @@ -83,18 +83,30 @@ void testCreateEndorsement() { // Mock data UUID userId = UUID.randomUUID(); UUID skillId = UUID.randomUUID(); + UUID endorsementId = UUID.randomUUID(); EndorsementDRO endorsementDRO = new EndorsementDRO(); endorsementDRO.setUserId(userId); endorsementDRO.setSkillId(skillId); UserModel mockUser = UserModel.builder().id(userId).build(); SkillModel mockSkill = SkillModel.builder().id(skillId).build(); - - // Mock the repository behavior + EndorsementModel mockEndorsement = EndorsementModel.builder() + .id(endorsementId) + .user(mockUser) + .skill(mockSkill) + .build(); + mockEndorsement.setCreatedAt(Instant.now()); + mockEndorsement.setUpdatedAt(Instant.now()); + mockEndorsement.setCreatedBy(mockUser); + mockEndorsement.setUpdatedBy(mockUser); + + // Mock the repository behavior when(userRepository.findById(userId)).thenReturn(Optional.of(mockUser)); when(skillRepository.findById(skillId)).thenReturn(Optional.of(mockSkill)); + when(endorsementRepository.save(any(EndorsementModel.class))).thenReturn(mockEndorsement); + - // Call the service method + // Call the service method EndorsementModel result = endorsementService.createEndorsement(endorsementDRO); // Verify the interactions