Skip to content

Commit 0bf1032

Browse files
committed
[#40] feat: ChatContext 수정
1 parent d85b3c5 commit 0bf1032

File tree

5 files changed

+12
-35
lines changed

5 files changed

+12
-35
lines changed

src/main/java/com/nexters/teamace/chat/domain/ChatContext.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import static com.nexters.teamace.common.exception.ValidationErrorMessage.CHAT_ROOM_ID_POSITIVE;
55
import static com.nexters.teamace.common.exception.ValidationErrorMessage.PREVIOUS_CHATS_NOT_NULL;
66

7-
import java.util.List;
8-
9-
public record ChatContext(Long chatRoomId, List<Chat> previousChats) {
7+
public record ChatContext(Long chatRoomId, Chats previousChats) {
108
public ChatContext {
119
if (chatRoomId == null) {
1210
throw new IllegalArgumentException(CHAT_ROOM_ID_NOT_NULL);

src/main/java/com/nexters/teamace/chat/domain/ChatRoom.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ public ChatContext toChatContext() {
3939
throw new IllegalStateException(
4040
"ChatRoom ID must not be null when creating ChatContext");
4141
}
42-
return new ChatContext(this.id, this.chats.getChats());
42+
return new ChatContext(this.id, this.chats);
4343
}
4444
}

src/test/java/com/nexters/teamace/chat/domain/ChatContextTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Context_with_valid_chatRoomId_and_empty_chats {
2727
void it_creates_chat_context() {
2828
// Given
2929
final Long chatRoomId = 1L;
30-
final List<Chat> previousChats = List.of();
30+
final Chats previousChats = new Chats();
3131

3232
// When
3333
final ChatContext chatContext = new ChatContext(chatRoomId, previousChats);
@@ -50,15 +50,15 @@ void it_creates_chat_context() {
5050
final Long chatRoomId = 5L;
5151
final Chat chat1 = Chat.create(chatRoomId, MessageType.USER, "Hello");
5252
final Chat chat2 = Chat.create(chatRoomId, MessageType.SYSTEM, "Hi there");
53-
final List<Chat> previousChats = List.of(chat1, chat2);
53+
final Chats previousChats = new Chats(List.of(chat1, chat2));
5454

5555
// When
5656
final ChatContext chatContext = new ChatContext(chatRoomId, previousChats);
5757

5858
// Then
5959
then(chatContext.chatRoomId()).isEqualTo(chatRoomId);
6060
then(chatContext.previousChats()).isEqualTo(previousChats);
61-
then(chatContext.previousChats()).hasSize(2);
61+
then(chatContext.previousChats().size()).isEqualTo(2);
6262
}
6363
}
6464
}
@@ -76,7 +76,7 @@ class Context_when_chatRoomId_is_null {
7676
void it_throws_IllegalArgumentException() {
7777
// Given
7878
final Long chatRoomId = null;
79-
final List<Chat> previousChats = List.of();
79+
final Chats previousChats = new Chats();
8080

8181
// When & Then
8282
thenThrownBy(() -> new ChatContext(chatRoomId, previousChats))
@@ -94,7 +94,7 @@ class Context_when_chatRoomId_is_zero {
9494
void it_throws_IllegalArgumentException() {
9595
// Given
9696
final Long chatRoomId = 0L;
97-
final List<Chat> previousChats = List.of();
97+
final Chats previousChats = new Chats();
9898

9999
// When & Then
100100
thenThrownBy(() -> new ChatContext(chatRoomId, previousChats))
@@ -112,7 +112,7 @@ class Context_when_chatRoomId_is_negative {
112112
void it_throws_IllegalArgumentException() {
113113
// Given
114114
final Long chatRoomId = -1L;
115-
final List<Chat> previousChats = List.of();
115+
final Chats previousChats = new Chats();
116116

117117
// When & Then
118118
thenThrownBy(() -> new ChatContext(chatRoomId, previousChats))
@@ -130,7 +130,7 @@ class Context_when_chatRoomId_is_one {
130130
void it_creates_chat_context() {
131131
// Given
132132
final Long chatRoomId = 1L;
133-
final List<Chat> previousChats = List.of();
133+
final Chats previousChats = new Chats();
134134

135135
// When
136136
final ChatContext chatContext = new ChatContext(chatRoomId, previousChats);
@@ -154,7 +154,7 @@ class Context_when_previousChats_is_null {
154154
void it_throws_IllegalArgumentException() {
155155
// Given
156156
final Long chatRoomId = 1L;
157-
final List<Chat> previousChats = null;
157+
final Chats previousChats = null;
158158

159159
// When & Then
160160
thenThrownBy(() -> new ChatContext(chatRoomId, previousChats))

src/test/java/com/nexters/teamace/chat/domain/ChatRoomTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void it_returns_ChatContext_with_all_chats() {
143143

144144
// Then
145145
then(chatContext).extracting("chatRoomId").isEqualTo(chatRoom.getId());
146-
then(chatContext.previousChats()).hasSize(2);
146+
then(chatContext.previousChats().size()).isEqualTo(2);
147147
then(chatContext.previousChats())
148148
.extracting("type", "message")
149149
.containsExactly(

src/test/java/com/nexters/teamace/chat/domain/ChatsTest.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void it_creates_chat_list_with_provided_chats() {
4848
// Then
4949
then(chats.size()).isEqualTo(2);
5050
then(chats.isEmpty()).isFalse();
51-
then(chats.getChats()).containsExactly(chat1, chat2);
51+
then(chats).containsExactly(chat1, chat2);
5252
}
5353
}
5454

@@ -99,27 +99,6 @@ void it_adds_chat_to_end_of_list() {
9999
}
100100
}
101101

102-
@Nested
103-
@DisplayName("채팅 목록 조회")
104-
class Describe_getChats {
105-
106-
@Test
107-
@DisplayName("수정 불가능한 채팅 목록을 반환한다")
108-
void it_returns_unmodifiable_chat_list() {
109-
// Given
110-
final Chat chat = Chat.create(1L, MessageType.USER, "Hello");
111-
final Chats chats = new Chats(List.of(chat));
112-
113-
// When
114-
final List<Chat> result = chats.getChats();
115-
116-
// Then
117-
then(result).containsExactly(chat);
118-
thenThrownBy(() -> result.add(Chat.create(2L, MessageType.SYSTEM, "Test")))
119-
.isInstanceOf(UnsupportedOperationException.class);
120-
}
121-
}
122-
123102
@Nested
124103
@DisplayName("첫 번째 채팅 조회")
125104
class Describe_getFirst {

0 commit comments

Comments
 (0)