From 5cf81139eb7cda3a2795a9a94a5416f334a8e475 Mon Sep 17 00:00:00 2001 From: Ohjintaek Date: Sun, 21 Jan 2024 19:04:54 +0900 Subject: [PATCH] =?UTF-8?q?test:=20RoadmapNodes=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roadmap/domain/RoadmapNodesTest.java | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodesTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodesTest.java index 4d65f7508..c16f642de 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodesTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodesTest.java @@ -4,9 +4,11 @@ import org.junit.jupiter.api.Test; import java.util.List; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; class RoadmapNodesTest { @@ -23,7 +25,45 @@ class RoadmapNodesTest { .hasMessage("한 로드맵에 같은 이름의 노드가 존재할 수 없습니다."); } - // todo: RoadmapNodes 도메인 테스트 추가하기 + @Test + void 로드맵_노드_아이디로_노드를_반환한다() { + // given + final RoadmapNode node1 = new RoadmapNode(1L, "title1", "content1"); + final RoadmapNode node2 = new RoadmapNode(2L, "title2", "content2"); + final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(node1, node2)); + + // when + final long findNodeId = 1; + final long notExistId = 3; + final Optional foundNode1 = roadmapNodes.findById(findNodeId); + final Optional foundNode2 = roadmapNodes.findById(notExistId); + + // then + assertAll( + () -> assertThat(node1).isEqualTo(foundNode1.get()), + () -> assertThat(foundNode2).isEmpty() + ); + } + + @Test + void 로드맵_노드_제목으로_노드를_반환한다() { + // given + final RoadmapNode node1 = new RoadmapNode(1L, "title1", "content1"); + final RoadmapNode node2 = new RoadmapNode(2L, "title2", "content2"); + final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(node1, node2)); + + // when + final String findNodeTitle = "title1"; + final String notExistTitle = "nothing"; + final Optional foundNode1 = roadmapNodes.findByTitle(findNodeTitle); + final Optional foundNode2 = roadmapNodes.findByTitle(notExistTitle); + + // then + assertAll( + () -> assertThat(node1).isEqualTo(foundNode1.get()), + () -> assertThat(foundNode2).isEmpty() + ); + } @Test void 로드맵_노드를_추가한다() {