Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] pagination 관련 코드 개선 #254

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: CustomPageImpl
- CustomPageImpl 직렬화 / 역직렬화 테스트
kimdozzi committed Aug 25, 2024
commit 0f872506333a7d6d5cc92834a22e26ed565349b3
43 changes: 43 additions & 0 deletions src/test/java/com/genius/gitget/paging/CustomPageImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.genius.gitget.paging;


import static org.junit.jupiter.api.Assertions.*;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.springframework.data.domain.PageRequest;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.genius.gitget.global.page.CustomPageImpl;

public class CustomPageImplTest {

private final ObjectMapper objectMapper = new ObjectMapper();

@Test
public void testCustomPageImplSerialization() throws JsonProcessingException {

// 데이터 목록과 페이지 정보를 설정
List<String> data = List.of("item1", "item2", "item3");
PageRequest pageRequest = PageRequest.of(0, 10);

// CustomPageImpl 객체 생성
CustomPageImpl<String> customPage = new CustomPageImpl<>(data, pageRequest, 3L);

// CustomPageImpl 객체를 JSON으로 직렬화
String json = objectMapper.writeValueAsString(customPage);

System.out.println(json);

// JSON 문자열을 다시 CustomPageImpl 객체로 역직렬화
CustomPageImpl deserializedPage = objectMapper.readValue(json, CustomPageImpl.class);

assertNotNull(deserializedPage);
assertEquals(customPage.getContent(), deserializedPage.getContent());
assertEquals(customPage.getTotalElements(), deserializedPage.getTotalElements());
assertEquals(customPage.getPageable().getPageNumber(), deserializedPage.getPageable().getPageNumber());
}
}