Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.time.Duration;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -96,6 +97,13 @@ public static void setHttpProxy(String host, int port, String username, String p
.build();
}

public static void setTimeout(final Duration duration) {

Objects.requireNonNull(duration, "Duration cannot be null");
sharedClient = sharedClient.newBuilder()
.callTimeout( duration )
.build();
}

/**
* Create service s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;
import java.net.ProxySelector;
import java.net.URISyntaxException;
import java.time.Duration;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -116,4 +117,21 @@ void testSetHttpProxy_WithAuthentication() {
assertEquals(CustomProxyAuthenticator.class, WhatsappApiServiceGenerator.getSharedClient().proxyAuthenticator().getClass(), "Authenticator should be CustomProxyAuthenticator");

}

/**
* Method under test:
* {@link WhatsappApiServiceGenerator#setTimeout(Duration)}
*/
@Test
void testSetTimeout() {

assertEquals( 20 * 1000, WhatsappApiServiceGenerator.getSharedClient().callTimeoutMillis() );

// Set timeout in shared client
WhatsappApiServiceGenerator.setTimeout( Duration.ofMinutes( 1L ) );

// Check if timeout is set
assertEquals( 60 * 1000, WhatsappApiServiceGenerator.getSharedClient().callTimeoutMillis() );
}

}