Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some static analysis errors #110

Merged
merged 6 commits into from
Feb 12, 2023
Merged
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.11.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public String generateCurl(HttpRequest request) throws Exception {
private static class Headers {

List<Header> toProcess;
Set<String> ignored;
final Set<String> ignored;

public Headers(List<Header> toProcess) {
this.toProcess = toProcess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
import io.restassured.config.HttpClientConfig;
import io.restassured.config.RestAssuredConfig;
import io.restassured.specification.RequestSpecification;
import java.io.IOException;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HttpContext;
Expand All @@ -26,6 +23,7 @@
import org.junit.jupiter.api.Test;
import org.mockserver.client.MockServerClient;

@SuppressWarnings("deprecation") // AbstractHttpClient is deprecated but used by REST-assured
public class CurlRestAssuredConfigFactoryTest {

private static final int MOCK_PORT = 9999;
Expand Down Expand Up @@ -54,13 +52,10 @@ public void shouldIncludeCurlInterceptorWhenUpdatingExistingConfig() {
HttpClientConfig.httpClientConfig()
.setParam("TestParam", "TestValue")
.httpClientFactory(
new HttpClientConfig.HttpClientFactory() {
@Override
public HttpClient createHttpClient() {
DefaultHttpClient client = new DefaultHttpClient();
client.addRequestInterceptor(new MyRequestInerceptor());
return client;
}
() -> {
DefaultHttpClient client = new DefaultHttpClient();
client.addRequestInterceptor(new MyRequestInerceptor());
return client;
});
final RestAssuredConfig config = RestAssuredConfig.config().httpClient(httpClientConfig);

Expand Down Expand Up @@ -147,7 +142,6 @@ public void describeTo(Description description) {}
private static class MyRequestInerceptor implements HttpRequestInterceptor {

@Override
public void process(HttpRequest httpRequest, HttpContext httpContext)
throws HttpException, IOException {}
public void process(HttpRequest httpRequest, HttpContext httpContext) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public Path createFile() throws IOException {
public void deleteAll() {
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(this.dir)) {
for (Path fpath : directoryStream) {
//noinspection ResultOfMethodCallIgnored
fpath.toFile().delete();
}
} catch (IOException ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static io.restassured.RestAssured.given;
import static io.restassured.config.HttpClientConfig.httpClientConfig;
import static io.restassured.config.MultiPartConfig.multiPartConfig;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
import static org.mockserver.model.HttpRequest.request;
Expand All @@ -22,7 +21,6 @@
import java.util.List;
import java.util.function.Consumer;
import org.apache.commons.io.FileUtils;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.client.HttpClient;
Expand All @@ -34,8 +32,12 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockserver.client.MockServerClient;

@ExtendWith(MockitoExtension.class)
public class UsingWithRestAssuredTest {

private static final int MOCK_PORT = 9999;
Expand All @@ -45,6 +47,8 @@ public class UsingWithRestAssuredTest {
private static MockServerClient mockServer;
private static TemporaryFolder tempFolder;

@Mock public Consumer<String> curlConsumer;

private RestAssuredConfig getRestAssuredConfig(Consumer<String> curlConsumer) {
return config()
.httpClient(
Expand All @@ -63,9 +67,6 @@ public static void setupMock() throws IOException {
@Test
@Tag("end-to-end-samples")
public void cookiesTest() {

Consumer<String> curlConsumer = mock(Consumer.class);

given()
.redirects()
.follow(false)
Expand Down Expand Up @@ -95,9 +96,6 @@ public void cookiesTest() {
@Test
@Tag("end-to-end-samples")
public void cookieWithSpecialCharactersTest() {

Consumer<String> curlConsumer = mock(Consumer.class);

given()
.redirects()
.follow(false)
Expand Down Expand Up @@ -133,9 +131,6 @@ public void cookieWithSpecialCharactersTest() {
@Test
@Tag("end-to-end-samples")
public void customizedCookie() {

Consumer<String> curlConsumer = mock(Consumer.class);

List<Cookie> cookies = new ArrayList<>();
cookies.add(
new Cookie.Builder("token", "tokenValue")
Expand Down Expand Up @@ -170,9 +165,6 @@ public void customizedCookie() {
@Test
@Tag("end-to-end-samples")
public void basicIntegrationTest() {

Consumer<String> curlConsumer = mock(Consumer.class);

given()
.redirects()
.follow(false)
Expand All @@ -191,9 +183,6 @@ public void basicIntegrationTest() {
@Test
@Tag("end-to-end-samples")
public void shouldPrintPostRequestWithMultipartDataProperly() {

Consumer<String> curlConsumer = mock(Consumer.class);

given()
.baseUri(MOCK_BASE_URI)
.port(MOCK_PORT)
Expand All @@ -215,9 +204,6 @@ public void shouldPrintPostRequestWithMultipartDataProperly() {
@Test
@Tag("end-to-end-samples")
public void shouldPrintBody() {

Consumer<String> curlConsumer = mock(Consumer.class);

given()
.baseUri(MOCK_BASE_URI)
.port(MOCK_PORT)
Expand All @@ -238,9 +224,6 @@ public void shouldPrintBody() {
@Test
@Tag("end-to-end-samples")
public void shouldPrintBodyWithEncoding() {

Consumer<String> curlConsumer = mock(Consumer.class);

given()
.baseUri(MOCK_BASE_URI)
.port(MOCK_PORT)
Expand All @@ -263,9 +246,6 @@ public void shouldPrintBodyWithEncoding() {
@Test
@Tag("end-to-end-samples")
public void shouldPrintMultipartWithContentTypesForTypes() {

Consumer<String> curlConsumer = mock(Consumer.class);

given()
.baseUri(MOCK_BASE_URI)
.port(MOCK_PORT)
Expand All @@ -285,9 +265,6 @@ public void shouldPrintMultipartWithContentTypesForTypes() {

@Test
public void shouldPrintMultipartWithMixedType() {

Consumer<String> curlConsumer = mock(Consumer.class);

given()
.baseUri(MOCK_BASE_URI)
.port(MOCK_PORT)
Expand All @@ -308,8 +285,6 @@ public void shouldPrintMultipartWithMixedType() {

@Test
public void shouldPrintFileAsBinary() throws IOException {
Consumer<String> curlConsumer = mock(Consumer.class);

File tempFile = tempFolder.createFile().toFile();
FileUtils.writeStringToFile(tempFile, "{ 'message' : 'hello world'}", Charset.defaultCharset());

Expand All @@ -331,8 +306,6 @@ public void shouldPrintFileAsBinary() throws IOException {

@Test
public void shouldPrintForm() {
Consumer<String> curlConsumer = mock(Consumer.class);

given()
.baseUri(MOCK_BASE_URI)
.port(MOCK_PORT)
Expand All @@ -354,9 +327,6 @@ public void shouldPrintForm() {
@Test
@Tag("end-to-end-samples")
public void shouldPrintPut() {

Consumer<String> curlConsumer = mock(Consumer.class);

given()
.redirects()
.follow(false)
Expand Down Expand Up @@ -409,9 +379,7 @@ public CurlTestingInterceptor(Consumer<String> curlConsumer) {
}

@Override
public void process(HttpRequest request, HttpContext context)
throws HttpException, IOException {

public void process(HttpRequest request, HttpContext context) {
Options options =
Options.builder()
.printSingleliner()
Expand Down