From 486e25d05e6d808fdb89423ddba334905dc10c08 Mon Sep 17 00:00:00 2001 From: swonny Date: Tue, 9 Apr 2024 13:26:50 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EC=B1=84=ED=8C=85=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=ED=83=80=EC=9E=85=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ChatWebSocketHandleTextMessageProviderTest.java | 14 ++++++++++++++ ...SocketHandleTextMessageProviderTestFixture.java | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/handler/ChatWebSocketHandleTextMessageProviderTest.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/handler/ChatWebSocketHandleTextMessageProviderTest.java index dd7c99cd9..ef8873bf1 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/handler/ChatWebSocketHandleTextMessageProviderTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/handler/ChatWebSocketHandleTextMessageProviderTest.java @@ -28,6 +28,7 @@ import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.willDoNothing; @@ -173,6 +174,19 @@ class ChatWebSocketHandleTextMessageProviderTest extends ChatWebSocketHandleText assertThat(actual).hasSize(1); } + @Test + void 잘못된_데이터_타입_전달시_예외가_발생한다() throws JsonProcessingException { + // given + given(writerSession.getAttributes()).willReturn(발신자_세션_attribute_정보); + willDoNothing().given(sessions).add(writerSession, 채팅방.getId()); + willReturn(false).given(sessions).containsByUserId(채팅방.getId(), 수신자.getId()); + willReturn(Set.of(writerSession)).given(sessions).getSessionsByChatRoomId(채팅방.getId()); + + // when + assertThatThrownBy(() -> provider.handleCreateSendMessage(writerSession, 잘못된_메시지_전송_데이터)) + .isInstanceOf(IllegalArgumentException.class); + } + @Test void 세션을_삭제한다() { // given diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/handler/fixture/ChatWebSocketHandleTextMessageProviderTestFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/handler/fixture/ChatWebSocketHandleTextMessageProviderTestFixture.java index 07aecd76e..a1fc31506 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/handler/fixture/ChatWebSocketHandleTextMessageProviderTestFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/handler/fixture/ChatWebSocketHandleTextMessageProviderTestFixture.java @@ -46,6 +46,7 @@ public class ChatWebSocketHandleTextMessageProviderTestFixture { protected Map 발신자_세션_attribute_정보; protected Map 수신자_세션_attribute_정보; protected Map 메시지_전송_데이터; + protected Map 잘못된_메시지_전송_데이터; protected CreateReadMessageLogEvent 메시지_로그_생성_이벤트; @@ -93,6 +94,9 @@ void setUpFixture() { "receiverId", String.valueOf(수신자.getId()), "contents", "메시지 내용" ); + 잘못된_메시지_전송_데이터 = Map.of( + "type", "wrong message type" + ); 메시지_로그_생성_이벤트 = new CreateReadMessageLogEvent(채팅방); }