Skip to content

Commit 2ee3290

Browse files
committed
Improve coverage
1 parent 16469f3 commit 2ee3290

File tree

4 files changed

+71
-9
lines changed

4 files changed

+71
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package graphql.kickstart.spring.webclient.boot;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import java.util.Set;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
class OAuth2ClientRegistrationRepositoryConfigurationTest {
10+
11+
private OAuth2ClientRegistrationRepositoryConfiguration configuration;
12+
13+
@BeforeEach
14+
void setup() {
15+
configuration = new OAuth2ClientRegistrationRepositoryConfiguration();
16+
}
17+
18+
@Test
19+
void clientRegistrationRepository_nullRegistration_returnsNull() {
20+
var properties = new OAuth2ClientRegistrationProperties();
21+
var repository = configuration.clientRegistrationRepository(properties);
22+
assertNull(repository);
23+
}
24+
25+
@Test
26+
void clientRegistrationRepository_withRegistration_returns() {
27+
var properties = new OAuth2ClientRegistrationProperties();
28+
properties.setClientId("client-id");
29+
properties.setClientSecret("client-secret");
30+
properties.setRedirectUri("redirect-uri");
31+
properties.setScope(Set.of("profile"));
32+
properties.setClientName("client-name");
33+
properties.setAuthorizationUri("authorization-uri");
34+
properties.setTokenUri("token-uri");
35+
properties.setUserInfoUri("user-info-uri");
36+
properties.setJwkSetUri("jwk-set-uri");
37+
properties.setProvider("provider");
38+
properties.setUserNameAttribute("username-attribute");
39+
properties.setIssuerUri("issuer-uri");
40+
var repository = configuration.clientRegistrationRepository(properties);
41+
assertNotNull(repository);
42+
}
43+
44+
}

graphql-webclient/src/main/java/graphql/kickstart/spring/webclient/boot/GraphQLRequestBuilder.java

-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ public class GraphQLRequestBuilder {
1818
GraphQLRequestBuilder() {
1919
}
2020

21-
public GraphQLRequestBuilder header(String name, String value) {
22-
headers.add(name, value);
23-
return this;
24-
}
25-
2621
public GraphQLRequestBuilder header(String name, String... values) {
2722
headers.addAll(name, Arrays.asList(values));
2823
return this;

graphql-webclient/src/main/java/graphql/kickstart/spring/webclient/boot/GraphQLResponse.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class GraphQLResponse {
2525

2626
JsonNode tree = readTree(rawResponse);
2727
errors = readErrors(tree);
28-
data = tree.hasNonNull("data") ? tree.get("data") : null;
28+
data = tree.get("data");
2929
}
3030

3131
private JsonNode readTree(String rawResponse) {
@@ -52,7 +52,7 @@ private JavaType constructListType(Class<?> type) {
5252
}
5353

5454
public <T> T get(String fieldName, Class<T> type) {
55-
if (data != null && data.hasNonNull(fieldName)) {
55+
if (data.hasNonNull(fieldName)) {
5656
return objectMapper.convertValue(data.get(fieldName), type);
5757
}
5858
return null;
@@ -63,14 +63,14 @@ public <T> T getFirst(Class<T> type) {
6363
}
6464

6565
private Optional<JsonNode> getFirstDataEntry() {
66-
if (data != null && !data.isEmpty()) {
66+
if (!data.isEmpty()) {
6767
return Optional.ofNullable(data.fields().next().getValue());
6868
}
6969
return Optional.empty();
7070
}
7171

7272
public <T> List<T> getList(String fieldName, Class<T> type) {
73-
if (data != null && data.hasNonNull(fieldName)) {
73+
if (data.hasNonNull(fieldName)) {
7474
return convertList(data.get(fieldName), type);
7575
}
7676
return emptyList();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package graphql.kickstart.spring.webclient.boot;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
8+
class GraphQLRequestBuilderTest {
9+
10+
private GraphQLRequestBuilder builder;
11+
12+
@BeforeEach
13+
void setup() {
14+
builder = GraphQLRequest.builder();
15+
}
16+
17+
@Test
18+
void operationName_addsToRequest() {
19+
GraphQLRequest request = builder.operationName("some-operation").build();
20+
assertEquals("some-operation", request.getRequestBody().getOperationName());
21+
}
22+
23+
}

0 commit comments

Comments
 (0)