Skip to content

Commit 3527e41

Browse files
committed
fix: Fix failing unit tests
1 parent c567d61 commit 3527e41

3 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/main/java/dev/dochia/cli/core/model/HttpResponse.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
import dev.dochia.cli.core.model.ann.Exclude;
66
import dev.dochia.cli.core.util.KeyValuePair;
77
import dev.dochia.cli.core.util.WordUtils;
8-
import java.io.IOException;
9-
import java.net.ProtocolException;
10-
import java.util.Arrays;
11-
import java.util.Collections;
12-
import java.util.List;
13-
import java.util.Locale;
14-
import java.util.Optional;
158
import lombok.Builder;
169
import lombok.Getter;
1710

11+
import java.io.IOException;
12+
import java.net.ProtocolException;
13+
import java.util.*;
14+
1815
/**
1916
* Model class used to hold http response details.
2017
*/
@@ -101,7 +98,7 @@ public boolean containsHeader(String name) {
10198
* @return A key-value pair representing the header, or {@code null} if no such header is found.
10299
*/
103100
public KeyValuePair<String, String> getHeader(String name) {
104-
return headers.stream()
101+
return Optional.ofNullable(headers).orElse(List.of()).stream()
105102
.filter(header -> WordUtils.matchesAsLowerCase(header.getKey(), name))
106103
.findFirst()
107104
.orElse(null);

src/test/java/dev/dochia/cli/core/playbook/body/CustomHttpMethodsPlaybookTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import dev.dochia.cli.core.playbook.executor.SimpleExecutor;
77
import dev.dochia.cli.core.report.TestCaseListener;
88
import dev.dochia.cli.core.report.TestReportsGenerator;
9+
import dev.dochia.cli.core.util.KeyValuePair;
910
import io.quarkus.test.junit.QuarkusTest;
1011
import io.quarkus.test.junit.mockito.InjectSpy;
1112
import io.swagger.v3.oas.models.PathItem;
@@ -51,7 +52,7 @@ void shouldCallServiceAndReportErrorWhenServiceRespondsWith200() {
5152
@Test
5253
void shouldCallServiceAndReportInfoWhenServiceRespondsWith405() {
5354
PlaybookData data = PlaybookData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).requestContentTypes(List.of("application/json")).build();
54-
HttpResponse httpResponse = HttpResponse.builder().body("{}").responseCode(405).httpMethod("POST").build();
55+
HttpResponse httpResponse = HttpResponse.builder().body("{}").responseCode(405).httpMethod("POST").headers(List.of(new KeyValuePair<>("Allow","GET"))).build();
5556
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(httpResponse);
5657

5758
customHttpMethodsPlaybook.run(data);
@@ -71,7 +72,7 @@ void shouldCallServiceAndReportWarnWhenServiceRespondsWith400() {
7172
@Test
7273
void shouldRunOncePerPath() {
7374
PlaybookData data = PlaybookData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).path("/test").requestContentTypes(List.of("application/json")).build();
74-
HttpResponse httpResponse = HttpResponse.builder().body("{}").responseCode(405).httpMethod("POST").build();
75+
HttpResponse httpResponse = HttpResponse.builder().body("{}").responseCode(405).headers(List.of(new KeyValuePair<>("Allow","GET"))).httpMethod("POST").build();
7576
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(httpResponse);
7677

7778
customHttpMethodsPlaybook.run(data);

src/test/java/dev/dochia/cli/core/playbook/body/NonRestHttpMethodsPlaybookTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import dev.dochia.cli.core.playbook.executor.SimpleExecutor;
77
import dev.dochia.cli.core.report.TestCaseListener;
88
import dev.dochia.cli.core.report.TestReportsGenerator;
9+
import dev.dochia.cli.core.util.KeyValuePair;
910
import io.quarkus.test.junit.QuarkusTest;
1011
import io.quarkus.test.junit.mockito.InjectSpy;
1112
import io.swagger.v3.oas.models.PathItem;
@@ -51,7 +52,7 @@ void shouldCallServiceAndReportErrorWhenServiceRespondsWith200() {
5152
@Test
5253
void shouldCallServiceAndReportInfoWhenServiceRespondsWith405() {
5354
PlaybookData data = PlaybookData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).requestContentTypes(List.of("application/json")).build();
54-
HttpResponse httpResponse = HttpResponse.builder().body("{}").responseCode(405).httpMethod("POST").build();
55+
HttpResponse httpResponse = HttpResponse.builder().body("{}").responseCode(405).headers(List.of(new KeyValuePair<>("Allow","GET"))).httpMethod("POST").build();
5556
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(httpResponse);
5657

5758
nonRestHttpMethodsPlaybook.run(data);
@@ -71,7 +72,7 @@ void shouldCallServiceAndReportWarnWhenServiceRespondsWith400() {
7172
@Test
7273
void shouldRunOncePerPath() {
7374
PlaybookData data = PlaybookData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).path("/test").requestContentTypes(List.of("application/json")).build();
74-
HttpResponse httpResponse = HttpResponse.builder().body("{}").responseCode(405).httpMethod("POST").build();
75+
HttpResponse httpResponse = HttpResponse.builder().body("{}").responseCode(405).headers(List.of(new KeyValuePair<>("Allow","GET"))).httpMethod("POST").build();
7576
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(httpResponse);
7677

7778
nonRestHttpMethodsPlaybook.run(data);

0 commit comments

Comments
 (0)