jnk1m
Foliage IT
jnk1m
전체 방문자
오늘
어제
  • 분류 전체보기 (209)
    • Today I Learned (34)
    • Java (47)
    • Database (15)
    • [NHN Academy] (27)
    • Spring (47)
    • HTML + CSS + JavaScript (11)
    • JSP (3)
    • Node.js (10)
    • React Native (2)
    • 기타 (8)
    • 스크랩 (5)

인기 글

최근 글

티스토리

hELLO · Designed By 정상우.
글쓰기 / 관리자
jnk1m

Foliage IT

RestTemplate get 비교 시 객체 처리
Spring

RestTemplate get 비교 시 객체 처리

2022. 12. 14. 13:02
@Test
    @Order(2)
    void testGetStudent() throws Exception{
        ResponseEntity<Student> result = restTemplate.getForEntity(
                "/students/{id}",
                Student.class,
                1L);

        assertThat(result.getBody())
                .isEqualTo(new Student(1L, "Dave", 100));
    }

Equals 메소드가 구현되어 있지 않으면 해쉬코드를 비교한다.

 

@EqualsAndHashCode 어노테이션을 붙이거나 메소드를 구현하면 정상적으로 작동한다.

 

public boolean equals(final Object o) {
    if (o == this) return true;
    if (!(o instanceof Student)) return false;
    final Student other = (Student) o;
    if (!other.canEqual((Object) this)) return false;
    final Object this$id = this.getId();
    final Object other$id = other.getId();
    if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
    final Object this$name = this.getName();
    final Object other$name = other.getName();
    if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
    final Object this$score = this.getScore();
    final Object other$score = other.getScore();
    if (this$score == null ? other$score != null : !this$score.equals(other$score)) return false;
    return true;
}
    'Spring' 카테고리의 다른 글
    • [에러] @DataJpaTest 할 때 UnsatisfiedDependencyException
    • Spring Boot에서 RestTemplate 빈 등록을 해야할까?
    • [에러] Interface 기반 DTO Projection NULL 에러 원인과 해결 방법
    • [스프링 시큐리티] 사용자 관리 UserDetails, UserDetailsService, UserDetailsManager

    티스토리툴바