-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61cff96
commit 787faf3
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...test/java/site/timecapsulearchive/core/common/fixture/domain/AnnouncementTestFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package site.timecapsulearchive.core.common.fixture.domain; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import site.timecapsulearchive.core.domain.announcement.data.dto.AnnouncementDto; | ||
|
||
public class AnnouncementTestFixture { | ||
|
||
public static List<AnnouncementDto> announcementDtos(int size) { | ||
List<AnnouncementDto> result = new ArrayList<>(); | ||
ZonedDateTime now = ZonedDateTime.now(); | ||
for (int index = 0; index < size; index++) { | ||
result.add( | ||
new AnnouncementDto("title" + index, "content" + index, String.valueOf(index), | ||
now.plusSeconds(index)) | ||
); | ||
} | ||
|
||
return result; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ava/site/timecapsulearchive/core/domain/announcement/service/AnnouncementServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package site.timecapsulearchive.core.domain.announcement.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import site.timecapsulearchive.core.common.fixture.domain.AnnouncementTestFixture; | ||
import site.timecapsulearchive.core.domain.announcement.data.dto.AnnouncementDto; | ||
import site.timecapsulearchive.core.domain.announcement.repository.AnnouncementRepository; | ||
|
||
class AnnouncementServiceTest { | ||
|
||
private final AnnouncementRepository announcementRepository = mock( | ||
AnnouncementRepository.class); | ||
private final AnnouncementService announcementService = new AnnouncementService( | ||
announcementRepository); | ||
|
||
@Test | ||
void 공지사항을_조회하면_가장_최근에_생성된_공지사항이_최상단에_위치한다() { | ||
//given | ||
given(announcementRepository.findAll()).willReturn(AnnouncementTestFixture.announcementDtos(10)); | ||
|
||
//when | ||
List<AnnouncementDto> announcements = announcementService.findAll(); | ||
|
||
//then | ||
assertThat(announcements) | ||
.isSortedAccordingTo(Comparator.comparing(AnnouncementDto::createdAt).reversed()); | ||
} | ||
} |