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(채팅방); }