Skip to content

Commit

Permalink
add unit test: testBuilderCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyuT committed Mar 12, 2024
1 parent ae67f8b commit deb218a
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.function.BiFunction;

import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -320,6 +321,28 @@ public void testAuthContext() {
Assert.assertNull(client.getAuthContext());
}

@SneakyThrows
@Test
public void testBuilderCallback() {
//default config
MockRestClientImpl restClient = new MockRestClientImpl(TEST_URL,
RestClientConfig.builder().build());
OkHttpClient okHttpClient = Whitebox.getInternalState(restClient, "client");
Assert.assertEquals(okHttpClient.connectTimeoutMillis(), 10000);
Assert.assertEquals(okHttpClient.readTimeoutMillis(), 10000);

//set config by builderCallback
RestClientConfig config = RestClientConfig.builder().builderCallback(
builder -> builder.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)).build();

restClient = new MockRestClientImpl(TEST_URL, config);
okHttpClient = Whitebox.getInternalState(restClient, "client");

Assert.assertEquals(okHttpClient.connectTimeoutMillis(), 5000);
Assert.assertEquals(okHttpClient.readTimeoutMillis(), 30000);
}

@SneakyThrows
@Test
public void testRequest() {
Expand Down Expand Up @@ -485,6 +508,10 @@ public MockRestClientImpl(String url, int timeout) {
super(url, timeout);
}

public MockRestClientImpl(String url, RestClientConfig config) {
super(url, config);
}

@Override
protected void checkStatus(Response response, int... statuses) {
// pass
Expand Down

0 comments on commit deb218a

Please sign in to comment.