Skip to content

Commit f16e22b

Browse files
author
nickchecan
committed
test: refactor usage of the editor content in the chat test
1 parent bf04800 commit f16e22b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

com.developer.nefarious.zjoule.test/src/com/developer/nefarious/zjoule/test/chat/ChatOrchestratorTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ public void shouldNotStopIfThereIsNoMessageHistory() throws IOException, Interru
6868

6969
List<IChatMessage> mockMessageHistory = new ArrayList<>();
7070
when(mockAIClient.getMessageHistory()).thenReturn(mockMessageHistory);
71-
72-
mockedStaticEditorContentReader.when(EditorContentReader::readActiveEditorContent).thenReturn(null);
71+
72+
String mockEditorContent = null;
73+
mockedStaticEditorContentReader.when(EditorContentReader::readActiveEditorContent).thenReturn(mockEditorContent);
7374

7475
IChatMessage mockSystemMessage = mock(IChatMessage.class);
7576
when(mockAIClient.createMessage(Role.SYSTEM, mockBaseInstructions)).thenReturn(mockSystemMessage);
@@ -84,7 +85,7 @@ public void shouldNotStopIfThereIsNoMessageHistory() throws IOException, Interru
8485
when(mockAnswer.getMessage()).thenReturn(expectedValue);
8586

8687
// Act
87-
String returnValue = cut.getAnswer(mockUserPrompt);
88+
String returnValue = cut.getAnswer(mockUserPrompt, mockEditorContent);
8889

8990
// Assert
9091
verify(mockAIClient).setMessageHistory(mockAllMessages);
@@ -125,7 +126,7 @@ public void shouldPlumbAnswer() throws IOException, InterruptedException {
125126
when(mockAnswer.getMessage()).thenReturn(expectedValue);
126127

127128
// Act
128-
String returnValue = cut.getAnswer(mockUserPrompt);
129+
String returnValue = cut.getAnswer(mockUserPrompt, mockEditorContent);
129130

130131
// Assert
131132
verify(mockAIClient).setMessageHistory(mockAllMessages);
@@ -145,7 +146,8 @@ public void shouldPlumbErrorMessageIfChatCompletionDoesntWork() throws IOExcepti
145146
List<IChatMessage> mockMessageHistory = Arrays.asList(mockOldMessage);
146147
when(mockAIClient.getMessageHistory()).thenReturn(mockMessageHistory);
147148

148-
mockedStaticEditorContentReader.when(EditorContentReader::readActiveEditorContent).thenReturn(null);
149+
String mockEditorContent = null;
150+
mockedStaticEditorContentReader.when(EditorContentReader::readActiveEditorContent).thenReturn(mockEditorContent);
149151

150152
IChatMessage mockSystemMessage = mock(IChatMessage.class);
151153
when(mockAIClient.createMessage(Role.SYSTEM, mockBaseInstructions)).thenReturn(mockSystemMessage);
@@ -156,7 +158,7 @@ public void shouldPlumbErrorMessageIfChatCompletionDoesntWork() throws IOExcepti
156158
String expectedValue = "Error during the AI request execution";
157159

158160
// Act
159-
String returnValue = cut.getAnswer(mockUserPrompt);
161+
String returnValue = cut.getAnswer(mockUserPrompt, mockEditorContent);
160162

161163
// Assert
162164
verify(mockAIClient, never()).setMessageHistory(any());
@@ -170,11 +172,14 @@ public void shouldReturnErrorIfModelIsIncompatible() {
170172
String expectedValue = "The model you have selected is incompatible with the current "
171173
+ "operation. Please verify the model's configuration or choose a "
172174
+ "compatible alternative.";
175+
176+
String mockEditorContent = null;
177+
mockedStaticEditorContentReader.when(EditorContentReader::readActiveEditorContent).thenReturn(mockEditorContent);
173178

174179
mockedStaticAIClientFactory.when(AIClientFactory::getClient).thenReturn(null);
175180

176181
// Act
177-
String returnValue = cut.getAnswer(mockUserPrompt);
182+
String returnValue = cut.getAnswer(mockUserPrompt, mockEditorContent);
178183

179184
// Assert
180185
assertEquals(expectedValue, returnValue);

0 commit comments

Comments
 (0)