Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9c6f977

Browse files
committedDec 24, 2020
Improve coverage
1 parent 60155d6 commit 9c6f977

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed
 

‎graphql-webclient/src/main/java/graphql/kickstart/spring/webclient/boot/GraphQLErrorsException.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22

33
import java.util.List;
44
import lombok.EqualsAndHashCode;
5-
import lombok.RequiredArgsConstructor;
5+
import lombok.NonNull;
66
import lombok.Value;
77

88
@Value
99
@EqualsAndHashCode(callSuper = false)
10-
@RequiredArgsConstructor
1110
public class GraphQLErrorsException extends RuntimeException {
1211

1312
transient List<GraphQLError> errors;
13+
String message;
1414

15-
@Override
16-
public String getMessage() {
17-
return errors.get(0).getMessage();
15+
public GraphQLErrorsException(@NonNull List<GraphQLError> errors) {
16+
if (errors.isEmpty()) {
17+
throw new IllegalArgumentException("errors must not be empty");
18+
}
19+
this.errors = errors;
20+
this.message = errors.get(0).getMessage();
1821
}
1922

2023
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package graphql.kickstart.spring.webclient.boot;
2+
3+
import static java.util.Collections.emptyList;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
6+
import java.util.List;
7+
import org.junit.jupiter.api.Test;
8+
9+
@SuppressWarnings("ThrowableNotThrown")
10+
class GraphQLErrorsExceptionTest {
11+
12+
@Test
13+
void construct_nullArg_throwsException() {
14+
//noinspection ConstantConditions
15+
assertThrows(NullPointerException.class, () -> new GraphQLErrorsException(null));
16+
}
17+
18+
@Test
19+
void construct_emptyArg_throwsException() {
20+
List<GraphQLError> emptyList = emptyList();
21+
assertThrows(IllegalArgumentException.class, () -> new GraphQLErrorsException(emptyList));
22+
}
23+
24+
@Test
25+
void construct_errors_returnsErrorsAndFirstMessage() {
26+
var error = new GraphQLError();
27+
error.setMessage("testmessage");
28+
var errors = List.of(error);
29+
GraphQLErrorsException e = new GraphQLErrorsException(errors);
30+
assertEquals(errors, e.getErrors());
31+
assertEquals("testmessage", e.getMessage());
32+
assertEquals("testmessage", e.getLocalizedMessage());
33+
}
34+
35+
}

‎lombok.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lombok.addLombokGeneratedAnnotation = true

0 commit comments

Comments
 (0)
Please sign in to comment.