mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-16 00:50:47 +08:00
test: update MedalService tests for contributor medal
This commit is contained in:
@@ -21,13 +21,13 @@ class MedalServiceTest {
|
|||||||
CommentRepository commentRepo = mock(CommentRepository.class);
|
CommentRepository commentRepo = mock(CommentRepository.class);
|
||||||
PostRepository postRepo = mock(PostRepository.class);
|
PostRepository postRepo = mock(PostRepository.class);
|
||||||
UserRepository userRepo = mock(UserRepository.class);
|
UserRepository userRepo = mock(UserRepository.class);
|
||||||
|
ContributorService contributorService = mock(ContributorService.class);
|
||||||
|
|
||||||
MedalService service = new MedalService(commentRepo, postRepo, userRepo);
|
MedalService service = new MedalService(commentRepo, postRepo, userRepo, contributorService);
|
||||||
|
|
||||||
List<MedalDto> medals = service.getMedals(null);
|
List<MedalDto> medals = service.getMedals(null);
|
||||||
assertFalse(medals.get(0).isCompleted());
|
medals.forEach(m -> assertFalse(m.isCompleted()));
|
||||||
assertFalse(medals.get(1).isCompleted());
|
assertEquals(4, medals.size());
|
||||||
assertFalse(medals.get(2).isCompleted());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -35,16 +35,18 @@ class MedalServiceTest {
|
|||||||
CommentRepository commentRepo = mock(CommentRepository.class);
|
CommentRepository commentRepo = mock(CommentRepository.class);
|
||||||
PostRepository postRepo = mock(PostRepository.class);
|
PostRepository postRepo = mock(PostRepository.class);
|
||||||
UserRepository userRepo = mock(UserRepository.class);
|
UserRepository userRepo = mock(UserRepository.class);
|
||||||
|
ContributorService contributorService = mock(ContributorService.class);
|
||||||
|
|
||||||
when(commentRepo.countByAuthor_Id(1L)).thenReturn(120L);
|
when(commentRepo.countByAuthor_Id(1L)).thenReturn(120L);
|
||||||
when(postRepo.countByAuthor_Id(1L)).thenReturn(80L);
|
when(postRepo.countByAuthor_Id(1L)).thenReturn(80L);
|
||||||
|
when(contributorService.getContributionLines(anyString())).thenReturn(0L);
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.setId(1L);
|
user.setId(1L);
|
||||||
user.setCreatedAt(LocalDateTime.of(2025, 9, 15, 0, 0));
|
user.setCreatedAt(LocalDateTime.of(2025, 9, 15, 0, 0));
|
||||||
when(userRepo.findById(1L)).thenReturn(Optional.of(user));
|
when(userRepo.findById(1L)).thenReturn(Optional.of(user));
|
||||||
when(userRepo.findByUsername("user")).thenReturn(Optional.of(user));
|
when(userRepo.findByUsername("user")).thenReturn(Optional.of(user));
|
||||||
|
|
||||||
MedalService service = new MedalService(commentRepo, postRepo, userRepo);
|
MedalService service = new MedalService(commentRepo, postRepo, userRepo, contributorService);
|
||||||
List<MedalDto> medals = service.getMedals(1L);
|
List<MedalDto> medals = service.getMedals(1L);
|
||||||
|
|
||||||
assertEquals(MedalType.COMMENT, user.getDisplayMedal());
|
assertEquals(MedalType.COMMENT, user.getDisplayMedal());
|
||||||
@@ -62,16 +64,18 @@ class MedalServiceTest {
|
|||||||
CommentRepository commentRepo = mock(CommentRepository.class);
|
CommentRepository commentRepo = mock(CommentRepository.class);
|
||||||
PostRepository postRepo = mock(PostRepository.class);
|
PostRepository postRepo = mock(PostRepository.class);
|
||||||
UserRepository userRepo = mock(UserRepository.class);
|
UserRepository userRepo = mock(UserRepository.class);
|
||||||
|
ContributorService contributorService = mock(ContributorService.class);
|
||||||
|
|
||||||
when(commentRepo.countByAuthor_Id(1L)).thenReturn(120L);
|
when(commentRepo.countByAuthor_Id(1L)).thenReturn(120L);
|
||||||
when(postRepo.countByAuthor_Id(1L)).thenReturn(0L);
|
when(postRepo.countByAuthor_Id(1L)).thenReturn(0L);
|
||||||
|
when(contributorService.getContributionLines(anyString())).thenReturn(0L);
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.setId(1L);
|
user.setId(1L);
|
||||||
user.setCreatedAt(LocalDateTime.of(2025, 9, 15, 0, 0));
|
user.setCreatedAt(LocalDateTime.of(2025, 9, 15, 0, 0));
|
||||||
when(userRepo.findByUsername("user")).thenReturn(Optional.of(user));
|
when(userRepo.findByUsername("user")).thenReturn(Optional.of(user));
|
||||||
when(userRepo.findById(1L)).thenReturn(Optional.of(user));
|
when(userRepo.findById(1L)).thenReturn(Optional.of(user));
|
||||||
|
|
||||||
MedalService service = new MedalService(commentRepo, postRepo, userRepo);
|
MedalService service = new MedalService(commentRepo, postRepo, userRepo, contributorService);
|
||||||
service.selectMedal("user", MedalType.COMMENT);
|
service.selectMedal("user", MedalType.COMMENT);
|
||||||
assertEquals(MedalType.COMMENT, user.getDisplayMedal());
|
assertEquals(MedalType.COMMENT, user.getDisplayMedal());
|
||||||
}
|
}
|
||||||
@@ -81,16 +85,18 @@ class MedalServiceTest {
|
|||||||
CommentRepository commentRepo = mock(CommentRepository.class);
|
CommentRepository commentRepo = mock(CommentRepository.class);
|
||||||
PostRepository postRepo = mock(PostRepository.class);
|
PostRepository postRepo = mock(PostRepository.class);
|
||||||
UserRepository userRepo = mock(UserRepository.class);
|
UserRepository userRepo = mock(UserRepository.class);
|
||||||
|
ContributorService contributorService = mock(ContributorService.class);
|
||||||
|
|
||||||
when(commentRepo.countByAuthor_Id(1L)).thenReturn(10L);
|
when(commentRepo.countByAuthor_Id(1L)).thenReturn(10L);
|
||||||
when(postRepo.countByAuthor_Id(1L)).thenReturn(0L);
|
when(postRepo.countByAuthor_Id(1L)).thenReturn(0L);
|
||||||
|
when(contributorService.getContributionLines(anyString())).thenReturn(0L);
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.setId(1L);
|
user.setId(1L);
|
||||||
user.setCreatedAt(LocalDateTime.of(2025, 9, 15, 0, 0));
|
user.setCreatedAt(LocalDateTime.of(2025, 9, 15, 0, 0));
|
||||||
when(userRepo.findByUsername("user")).thenReturn(Optional.of(user));
|
when(userRepo.findByUsername("user")).thenReturn(Optional.of(user));
|
||||||
when(userRepo.findById(1L)).thenReturn(Optional.of(user));
|
when(userRepo.findById(1L)).thenReturn(Optional.of(user));
|
||||||
|
|
||||||
MedalService service = new MedalService(commentRepo, postRepo, userRepo);
|
MedalService service = new MedalService(commentRepo, postRepo, userRepo, contributorService);
|
||||||
assertThrows(IllegalArgumentException.class, () -> service.selectMedal("user", MedalType.COMMENT));
|
assertThrows(IllegalArgumentException.class, () -> service.selectMedal("user", MedalType.COMMENT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user