|
8 | 8 | import static org.mockito.ArgumentMatchers.any; |
9 | 9 | import static org.mockito.Mockito.when; |
10 | 10 |
|
| 11 | +import java.util.Collections; |
11 | 12 | import java.util.HashMap; |
12 | 13 | import java.util.Map; |
13 | 14 | import java.util.Set; |
@@ -41,7 +42,6 @@ public class MLToolExecutorTest { |
41 | 42 | private Client client; |
42 | 43 | @Mock |
43 | 44 | private SdkClient sdkClient; |
44 | | - private Settings settings; |
45 | 45 | @Mock |
46 | 46 | private ClusterService clusterService; |
47 | 47 | @Mock |
@@ -176,4 +176,30 @@ public void test_EmptyInputData() { |
176 | 176 | mlToolExecutor.execute(toolMLInput, actionListener); |
177 | 177 | }); |
178 | 178 | } |
| 179 | + |
| 180 | + @Test |
| 181 | + public void test_ImmutableEmptyParametersMap() { |
| 182 | + Map<String, String> immutableEmptyMap = Collections.emptyMap(); |
| 183 | + |
| 184 | + when(toolMLInput.getToolName()).thenReturn("TestTool"); |
| 185 | + when(toolMLInput.getInputDataset()).thenReturn(inputDataSet); |
| 186 | + when(inputDataSet.getParameters()).thenReturn(immutableEmptyMap); |
| 187 | + when(toolFactory.create(any())).thenReturn(tool); |
| 188 | + when(tool.validate(any())).thenReturn(true); |
| 189 | + |
| 190 | + Mockito.doAnswer(invocation -> { |
| 191 | + Map<String, String> params = invocation.getArgument(0); |
| 192 | + // Tool tries to modify parameters, should not throw exception |
| 193 | + params.put("test_key", "test_value"); |
| 194 | + ActionListener<Object> listener = invocation.getArgument(1); |
| 195 | + listener.onResponse("test result"); |
| 196 | + return null; |
| 197 | + }).when(tool).run(any(), any()); |
| 198 | + |
| 199 | + mlToolExecutor.execute(toolMLInput, actionListener); |
| 200 | + |
| 201 | + Mockito.verify(actionListener).onResponse(outputCaptor.capture()); |
| 202 | + Output output = outputCaptor.getValue(); |
| 203 | + Assert.assertTrue(output instanceof ModelTensorOutput); |
| 204 | + } |
179 | 205 | } |
0 commit comments