Skip to content

Commit

Permalink
refactor: BaseEntity의 equals&hashCode 제거 (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkdhoho committed Nov 1, 2024
1 parent 81d122c commit f516158
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 32 deletions.
14 changes: 0 additions & 14 deletions src/main/java/com/listywave/common/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Temporal;
import java.time.LocalDateTime;
import java.util.Objects;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
Expand All @@ -33,17 +32,4 @@ public class BaseEntity {
@LastModifiedDate
@Temporal(TIMESTAMP)
private LocalDateTime updatedDate;

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BaseEntity that = (BaseEntity) o;
return Objects.equals(getId(), that.getId());
}

@Override
public int hashCode() {
return Objects.hashCode(getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ItemTest {
void ItemImageUrl을_수정할_수_있다() {
String newValue = "sfksadfhskfhjaf";

item.updateItemImageUrl(newValue);
item.updateItemImageUrl(new ItemImageUrl(newValue));

assertThat(item.getImageUrl().getValue()).isEqualTo(newValue);
}
Expand Down
17 changes: 0 additions & 17 deletions src/test/java/com/listywave/user/application/domain/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@

import com.listywave.image.application.domain.DefaultBackgroundImages;
import com.listywave.image.application.domain.DefaultProfileImages;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
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.util.ReflectionUtils;

@DisplayName("회원은 ")
class UserTest {
Expand Down Expand Up @@ -324,19 +322,4 @@ class 팔로우_팔로워_수 {
void 카카오_액세스_토큰이_존재하는지_검증한다() {
assertThatNoException().isThrownBy(() -> user.validateHasKakaoAccessToken());
}

@Test
void ID가_같으면_동등한_객체다() {
// given
User other = User.init(312414L, "[email protected]", "sflkhadsfsad.asdjhfahsjdf.asdkjhfasdhjf");

Field idField = ReflectionUtils.findField(User.class, "id");
idField.setAccessible(true);
ReflectionUtils.setField(idField, user, 11L);
ReflectionUtils.setField(idField, other, 11L);

// expect
assertThat(user).isEqualTo(other);
assertThat(user).hasSameHashCodeAs(other);
}
}

0 comments on commit f516158

Please sign in to comment.