Skip to content

Commit

Permalink
refactor: (#68) @nested 삭제
Browse files Browse the repository at this point in the history
- 카테고리를 조회하는 기능에서 보면 같으나 멤버, 비회원으로 나누어진 메서드므로 해당 어노테이션을 제거함
  • Loading branch information
aiaiaiai1 committed Jul 20, 2023
1 parent 3cecd49 commit 3d4307b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.restassured.module.mockmvc.RestAssuredMockMvc;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
Expand All @@ -33,63 +32,57 @@ void setUp() {
RestAssuredMockMvc.standaloneSetup(new CategoryController(categoryService));
}

@Nested
@DisplayName("카테고리 조회")
class Getting {

@Test
@DisplayName("전체 카테고리 목록을 조회한다.")
void getAllCategories() {
// given
Category category = Category.builder()
.name("개발")
.build();
given(categoryService.getAllCategories()).willReturn(List.of(new CategoryResponse(category, false)));

// when
RestAssuredMockMvc.
given().log().all()
.when().get("/categories/guest")
.then().log().all()
.status(HttpStatus.OK)
.body("[0].id", nullValue())
.body("[0].name", equalTo("개발"))
.body("[0].isFavorite", equalTo(false));
}

@Test
@DisplayName("회원으로 전체 카테고리 목록을 조회한다.")
void getAllCategoriesFromMember() {
// given
Category category = Category.builder()
.name("개발")
.build();

Category category1 = Category.builder()
.name("음식")
.build();

List<CategoryResponse> categoryResponses = List.of(
new CategoryResponse(category, false),
new CategoryResponse(category1, true)
);

given(categoryService.getAllCategories(any())).willReturn(categoryResponses);

// when
List<CategoryResponse> results = RestAssuredMockMvc
.given().log().all()
.when().get("/categories")
.then().log().all()
.status(HttpStatus.OK)
.extract()
.as(new ParameterizedTypeReference<List<CategoryResponse>>() {
}.getType());

// then
assertThat(results).usingRecursiveComparison().isEqualTo(categoryResponses);
}
@Test
@DisplayName("전체 카테고리 목록을 조회한다.")
void getAllCategories() {
// given
Category category = Category.builder()
.name("개발")
.build();
given(categoryService.getAllCategories()).willReturn(List.of(new CategoryResponse(category, false)));

// when
RestAssuredMockMvc.
given().log().all()
.when().get("/categories/guest")
.then().log().all()
.status(HttpStatus.OK)
.body("[0].id", nullValue())
.body("[0].name", equalTo("개발"))
.body("[0].isFavorite", equalTo(false));
}

@Test
@DisplayName("회원으로 전체 카테고리 목록을 조회한다.")
void getAllCategoriesFromMember() {
// given
Category category = Category.builder()
.name("개발")
.build();

Category category1 = Category.builder()
.name("음식")
.build();

List<CategoryResponse> categoryResponses = List.of(
new CategoryResponse(category, false),
new CategoryResponse(category1, true)
);

given(categoryService.getAllCategories(any())).willReturn(categoryResponses);

// when
List<CategoryResponse> results = RestAssuredMockMvc
.given().log().all()
.when().get("/categories")
.then().log().all()
.status(HttpStatus.OK)
.extract()
.as(new ParameterizedTypeReference<List<CategoryResponse>>() {
}.getType());

// then
assertThat(results).usingRecursiveComparison().isEqualTo(categoryResponses);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ class CategoryServiceTest {
@Autowired
MemberRepository memberRepository;

@Nested
@DisplayName("조회 하기")
class Getting {

@Test
@DisplayName("모든 카테고리를 가져온다.")
void getAllCategories() {
Expand Down Expand Up @@ -108,8 +104,6 @@ void getAllCategoriesFromMember() {
);
}

}

@Test
@DisplayName("선호하는 카테고리를 선호 카테고리 목록에 추가한다.")
void addFavoriteCategory() {
Expand Down

0 comments on commit 3d4307b

Please sign in to comment.