Skip to content

Commit

Permalink
Merge pull request #1294 from woowacourse/feature/1280-bebe-hoy
Browse files Browse the repository at this point in the history
Feature/#1280 bebe hoy
  • Loading branch information
wonyongChoi05 authored May 17, 2023
2 parents 9fa43f3 + 9360664 commit f931ad1
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
Expand Down Expand Up @@ -54,7 +54,7 @@
@Configuration
public class DataLoaderApplicationListener implements ApplicationListener<ContextRefreshedEvent> {

private static final Random random = ThreadLocalRandom.current();
private static final Random random = new SecureRandom();
private static final Logger logger = LoggerFactory.getLogger(DataLoaderApplicationListener.class);

private final EntityManagerFactory entityManagerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package wooteco.prolog.studylog.application;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import wooteco.prolog.login.ui.LoginMember;
import wooteco.prolog.member.application.MemberService;
import wooteco.prolog.member.application.dto.MemberResponse;
import wooteco.prolog.member.domain.Role;
import wooteco.prolog.roadmap.application.dto.SessionResponse;
import wooteco.prolog.session.application.MissionService;
import wooteco.prolog.session.application.SessionService;
import wooteco.prolog.session.application.dto.MissionResponse;
import wooteco.prolog.studylog.application.dto.FilterResponse;
import wooteco.prolog.studylog.application.dto.TagResponse;

import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.doReturn;

@ExtendWith(MockitoExtension.class)
class FilterServiceTest {

@InjectMocks
FilterService filterService;

@Mock
SessionService sessionService;

@Mock
MissionService missionService;

@Mock
TagService tagService;

@Mock
MemberService memberService;

@DisplayName("로그인 멤버와 관련된 세션, 미션, 태그, 멤버 정보를 가져와서 FilterResponse를 반환한다.")
@Test
void showAll() {
// given
LoginMember loginMember = new LoginMember();

List<SessionResponse> sessionResponses = new ArrayList<>();
sessionResponses.add(new SessionResponse(1L, "session1"));
doReturn(sessionResponses).when(sessionService).findAllWithMySessionFirst(loginMember);

List<MissionResponse> missionResponses = new ArrayList<>();
missionResponses.add(new MissionResponse(1L, "mission1", new wooteco.prolog.session.application.dto.SessionResponse(1L, "session1")));
doReturn(missionResponses).when(missionService).findAllWithMyMissionFirst(loginMember);

List<TagResponse> tagResponses = new ArrayList<>();
tagResponses.add(new TagResponse(1L, "tag1"));
doReturn(tagResponses).when(tagService).findTagsIncludedInStudylogs();

List<MemberResponse> memberResponses = new ArrayList<>();
memberResponses.add(new MemberResponse(1L, "베베", "bebe", Role.CREW, "img"));
doReturn(memberResponses).when(memberService).findAllOrderByNickNameAsc();

// when
FilterResponse response = filterService.showAll(loginMember);

// then
assertAll(
() -> assertThat(response.getSessions()).isEqualTo(sessionResponses),
() -> assertThat(response.getMissions()).isEqualTo(missionResponses),
() -> assertThat(response.getTags()).isEqualTo(tagResponses),
() -> assertThat(response.getMembers()).isEqualTo(memberResponses)
);
}
}

0 comments on commit f931ad1

Please sign in to comment.