Search in sources :

Example 1 with HttpBackendSelector

use of com.dtflys.forest.backend.HttpBackendSelector in project forest by dromara.

the class TestForestConfiguration method testBackend.

@Test
public void testBackend() {
    ForestConfiguration configuration = ForestConfiguration.createConfiguration();
    configuration.setBackendName("okhttp3");
    assertEquals("okhttp3", configuration.getBackend().getName());
    configuration.setBackend(null);
    configuration.setBackendName("httpclient");
    assertEquals("httpclient", configuration.getBackend().getName());
    HttpBackendSelector originSelector = new HttpBackendSelector();
    HttpBackendSelector selector = Mockito.spy(originSelector);
    configuration.setHttpBackendSelector(selector);
    Mockito.when(selector.findOkHttp3BackendInstance()).thenReturn(null);
    configuration.setBackendName(null);
    configuration.setBackend(null);
    Assert.assertEquals("httpclient", configuration.getBackend().getName());
    Mockito.when(selector.findHttpclientBackendInstance()).thenReturn(null);
    configuration.setBackendName(null);
    configuration.setBackend(null);
    boolean thrown = false;
    try {
        HttpBackend backend = configuration.getBackend();
        System.out.print(backend);
    } catch (ForestRuntimeException e) {
        thrown = true;
    }
    assertTrue(thrown);
}
Also used : HttpBackendSelector(com.dtflys.forest.backend.HttpBackendSelector) ForestConfiguration(com.dtflys.forest.config.ForestConfiguration) ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) HttpBackend(com.dtflys.forest.backend.HttpBackend) Test(org.junit.Test)

Aggregations

HttpBackend (com.dtflys.forest.backend.HttpBackend)1 HttpBackendSelector (com.dtflys.forest.backend.HttpBackendSelector)1 ForestConfiguration (com.dtflys.forest.config.ForestConfiguration)1 ForestRuntimeException (com.dtflys.forest.exceptions.ForestRuntimeException)1 Test (org.junit.Test)1