View Javadoc
1   package io.github.magwas.coder.openrouter.tests;
2   
3   import static org.mockito.ArgumentMatchers.*;
4   import static org.mockito.Mockito.*;
5   
6   import java.io.IOException;
7   import java.net.http.HttpResponse;
8   
9   import io.github.magwas.coder.openrouter.OpenRouterClientService;
10  import io.github.magwas.coder.tests.MainLoopTestData;
11  import io.github.magwas.konveyor.testing.TestBase;
12  
13  public class OpenRouterClientServiceStub implements MainLoopTestData, OpenRouterResponseTestData {
14  	public static OpenRouterClientService stub() throws IOException, InterruptedException {
15  		OpenRouterClientService mock = mock(OpenRouterClientService.class);
16  		doAnswer(invocation -> {
17  					if (ERROR_STATE.equals(TestBase.environmentState)) {
18  						throw new IOException("Simulated error");
19  					}
20  					var response = mock(HttpResponse.class);
21  					when(response.body()).thenReturn(RESPONSE_BODY);
22  					return response;
23  				})
24  				.when(mock)
25  				.apply(anyString(), anyString());
26  
27  		return mock;
28  	}
29  }