From 14806dbd079c38818abb210c91ed73aae457ba43 Mon Sep 17 00:00:00 2001 From: KangJeongmin Date: Fri, 21 Aug 2026 14:45:42 +0900 Subject: [PATCH] =?UTF-8?q?MSG-442=20test:=20=EA=B5=AC=EB=8F=85=20?= =?UTF-8?q?=EB=B3=B5=ED=95=A9=ED=82=A4=20=EB=8F=99=EB=93=B1=EC=84=B1=20?= =?UTF-8?q?=EA=B3=84=EC=95=BD=20=EA=B2=80=EC=A6=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JaCoCo가 EventNotificationSubscriptionId 16.98%를 보고 — existsById는 DB 쿼리로 가서 자바 equals를 태우지 않아 분기 8개가 전부 미실행이었다. UserGridTest 선례 동형의 계약 테스트 1건으로 분기 100%. --- .../EventNotificationSubscriptionIdTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/test/java/com/msg/fillmap/event/entity/EventNotificationSubscriptionIdTest.java diff --git a/src/test/java/com/msg/fillmap/event/entity/EventNotificationSubscriptionIdTest.java b/src/test/java/com/msg/fillmap/event/entity/EventNotificationSubscriptionIdTest.java new file mode 100644 index 00000000..c077d9a0 --- /dev/null +++ b/src/test/java/com/msg/fillmap/event/entity/EventNotificationSubscriptionIdTest.java @@ -0,0 +1,32 @@ +package com.msg.fillmap.event.entity; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +/** + * 행사 알림 구독 복합키의 동등성 계약 (MSG-442, UserGridTest 선례). 운영 경로는 {@code existsById} 로 + * DB 에 물어보므로 equals 를 타지 않는데, 영속성 컨텍스트의 1차 캐시 조회와 컬렉션 담기는 이 구현에 + * 의존한다 — 깨지면 같은 구독을 다른 행으로 보게 된다. + */ +@DisplayName("EventNotificationSubscriptionId 복합키 동등성") +class EventNotificationSubscriptionIdTest { + + @Test + @DisplayName("같은 user_id와 event_occurrence_id 조합의 복합키는 동등하다") + void 같은_user_id와_event_occurrence_id_조합의_복합키는_동등하다() { + EventNotificationSubscriptionId id1 = new EventNotificationSubscriptionId(1L, 10L); + EventNotificationSubscriptionId id2 = new EventNotificationSubscriptionId(1L, 10L); + EventNotificationSubscriptionId otherUser = new EventNotificationSubscriptionId(2L, 10L); + EventNotificationSubscriptionId otherOccurrence = new EventNotificationSubscriptionId(1L, 11L); + + assertThat(id1).isEqualTo(id1); // 자기 참조 + assertThat(id1).isEqualTo(id2); + assertThat(id1).hasSameHashCodeAs(id2); + assertThat(id1).isNotEqualTo(otherUser); // 사용자만 다름 + assertThat(id1).isNotEqualTo(otherOccurrence); // 회차만 다름 + assertThat(id1).isNotEqualTo("1_10"); // 타입 불일치 + assertThat(id1).isNotEqualTo(null); + } +}