Skip to content

Commit

Permalink
request timeout can be null but not negative
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed May 8, 2024
1 parent 06af301 commit 4c53737
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions unirest/src/main/java/kong/unirest/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ public Config connectTimeout(int inMillies) {
* @return this builder
* @throws IllegalArgumentException if the duration is non-positive
*/
public Config requestTimeout(int inMillies){
if(inMillies < 1){
public Config requestTimeout(Integer inMillies){
if(inMillies != null && inMillies < 1){
throw new IllegalArgumentException("request timeout must be a positive integer");
}
this.requestTimeout = inMillies;
Expand Down
16 changes: 10 additions & 6 deletions unirest/src/test/java/kong/unirest/core/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

package kong.unirest.core;

import kong.unirest.core.Client;
import kong.unirest.core.Config;
import kong.unirest.core.Proxy;
import kong.unirest.core.UnirestConfigException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand All @@ -40,8 +36,7 @@
import java.util.concurrent.TimeUnit;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

@ExtendWith(MockitoExtension.class)
class ConfigTest {
Expand Down Expand Up @@ -138,6 +133,15 @@ void isRunningIfAsyncClientIsRunning() {
assertTrue(config.isRunning());
}

@Test
void requestTimeoutCannotBeNegative() {
config.requestTimeout(null);
config.requestTimeout(42);

assertThrows(IllegalArgumentException.class, () -> config.requestTimeout(0));
assertThrows(IllegalArgumentException.class, () -> config.requestTimeout(-5));
}

private void assertProxy(String host, Integer port, String username, String password) {
assertEquals(host, config.getProxy().getHost());
assertEquals(port, config.getProxy().getPort());
Expand Down

0 comments on commit 4c53737

Please sign in to comment.