Skip to content

Commit

Permalink
#92 [feat] : ClovaRequestFactory 단위 테스트 코드를 작성한다
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed Nov 27, 2024
1 parent a1e0ea9 commit 5bd4485
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package kusitms.backend.chatbot.application.factory;

import kusitms.backend.chatbot.application.dto.request.ChatbotRequestDto;
import kusitms.backend.chatbot.application.dto.request.ClovaRequestDto;
import kusitms.backend.chatbot.application.dto.request.MessageDto;
import kusitms.backend.chatbot.domain.enums.Role;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.when;

class ClovaRequestFactoryTest {

@InjectMocks
private ClovaRequestFactory clovaRequestFactory;

@Mock
private MessageFactory messageFactory;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}

/**
* ClovaRequestFactory의 createClovaRequest 메서드 테스트
*/
@Test
void testCreateClovaRequest() {
// Given
MessageDto systemMessage = new MessageDto(Role.SYSTEM.getRole(), "System message content");
when(messageFactory.createSystemMessage()).thenReturn(systemMessage);

// When
ChatbotRequestDto chatbotRequest = clovaRequestFactory.createClovaRequest();

// Then
assertNotNull(chatbotRequest);
assertEquals(1, chatbotRequest.getMessages().size());
assertEquals(systemMessage, chatbotRequest.getMessages().get(0));

ClovaRequestDto clovaRequest = (ClovaRequestDto) chatbotRequest;
assertEquals(0.8, clovaRequest.topP());
assertEquals(0.3, clovaRequest.temperature());
assertEquals(256, clovaRequest.maxTokens());
assertEquals(5.0, clovaRequest.repeatPenalty());
}
}

0 comments on commit 5bd4485

Please sign in to comment.