@@ -53,9 +53,10 @@ public void setUp() {
5353 // Clear any previous static state
5454 ReflectionTestUtils .setField (OpenapiUtils .class , "openApiClient" , null );
5555 ReflectionTestUtils .setField (OpenapiUtils .class , "openAiServiceFactory" , null );
56+ ReflectionTestUtils .setField (OpenapiUtils .class , "openAiService" , null );
5657
57- // Initialize OpenapiUtils
58- OpenapiUtils .initialize (mockOpenapiClient , mockOpenAiServiceFactory );
58+ // Initialize OpenapiUtils with all three parameters
59+ OpenapiUtils .initialize (mockOpenapiClient , mockOpenAiServiceFactory , mockOpenAiService );
5960
6061 // Set up BellaContext
6162 BellaContext .setApikey (ApikeyInfo .builder ().apikey (TEST_APIKEY ).build ());
@@ -131,14 +132,12 @@ public void testSaveStringAsFile_Success() {
131132 String expectedFileId = "file-123" ;
132133
133134 when (mockFile .getId ()).thenReturn (expectedFileId );
134- when (mockOpenAiServiceFactory .create (TEST_CONSOLE_KEY )).thenReturn (mockOpenAiService );
135135 when (mockOpenAiService .uploadFile (eq (Configs .FILE_API_PURPOSE ), any (byte [].class ), anyString ()))
136136 .thenReturn (mockFile );
137137
138138 String result = OpenapiUtils .saveStringAsFile (testData );
139139
140140 assertEquals (expectedFileId , result );
141- verify (mockOpenAiServiceFactory ).create (TEST_CONSOLE_KEY );
142141 verify (mockOpenAiService ).uploadFile (eq (Configs .FILE_API_PURPOSE ),
143142 eq (testData .getBytes ()), anyString ());
144143 }
@@ -152,7 +151,6 @@ public void testFetchStringFromFile_Success() throws IOException {
152151 okhttp3 .ResponseBody mockResponseBody = mock (okhttp3 .ResponseBody .class );
153152 when (mockResponseBody .bytes ()).thenReturn (contentBytes );
154153
155- when (mockOpenAiServiceFactory .create (TEST_CONSOLE_KEY )).thenReturn (mockOpenAiService );
156154 when (mockOpenAiService .retrieveFileContent (fileId )).thenReturn (mockResponseBody );
157155
158156 String result = OpenapiUtils .fetchStringFromFile (fileId );
@@ -179,7 +177,6 @@ public void testFetchStringFromFile_IOException() throws IOException {
179177 okhttp3 .ResponseBody mockResponseBody = mock (okhttp3 .ResponseBody .class );
180178 when (mockResponseBody .bytes ()).thenThrow (new IOException ("Network error" ));
181179
182- when (mockOpenAiServiceFactory .create (TEST_CONSOLE_KEY )).thenReturn (mockOpenAiService );
183180 when (mockOpenAiService .retrieveFileContent (fileId )).thenReturn (mockResponseBody );
184181
185182 OpenapiUtils .fetchStringFromFile (fileId );
@@ -190,8 +187,6 @@ public void testDownload_Success() throws IOException {
190187 String fileId = "file-123" ;
191188 Path testPath = Paths .get ("/tmp/test-file.txt" );
192189
193- when (mockOpenAiServiceFactory .create ()).thenReturn (mockOpenAiService );
194-
195190 OpenapiUtils .download (fileId , testPath );
196191
197192 verify (mockOpenAiService ).retrieveFileContentAndSave (fileId , testPath );
@@ -202,7 +197,6 @@ public void testDownload_IOException() throws IOException {
202197 String fileId = "file-123" ;
203198 Path testPath = Paths .get ("/tmp/test-file.txt" );
204199
205- when (mockOpenAiServiceFactory .create ()).thenReturn (mockOpenAiService );
206200 doThrow (new IOException ("Download failed" )).when (mockOpenAiService )
207201 .retrieveFileContentAndSave (fileId , testPath );
208202
0 commit comments