Skip to content

Commit 5fa4020

Browse files
committed
feat(test): add custom error handler for RestTemplate
* Implemented NoOpResponseErrorHandler to handle errors gracefully. * Updated setUpRestTemplate method to use the new error handler.
1 parent 664c339 commit 5fa4020

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

crud-spring/src/test/java/com/loiane/integration/AbstractIntegrationTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
import org.springframework.test.context.ActiveProfiles;
88
import org.junit.jupiter.api.BeforeEach;
99
import org.springframework.web.client.RestTemplate;
10+
import org.springframework.web.client.ResponseErrorHandler;
11+
import org.springframework.http.client.ClientHttpResponse;
1012
import org.springframework.web.util.DefaultUriBuilderFactory;
1113

14+
import java.io.IOException;
15+
1216
import com.loiane.config.TestContainersConfiguration;
1317

1418
/**
@@ -31,6 +35,14 @@ public abstract class AbstractIntegrationTest {
3135
void setUpRestTemplate() {
3236
restTemplate = new RestTemplate();
3337
restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory("http://localhost:" + port));
38+
restTemplate.setErrorHandler(new NoOpResponseErrorHandler());
39+
}
40+
41+
static class NoOpResponseErrorHandler implements ResponseErrorHandler {
42+
@Override
43+
public boolean hasError(ClientHttpResponse response) throws IOException {
44+
return false;
45+
}
3446
}
3547

3648
/**

0 commit comments

Comments
 (0)