File tree Expand file tree Collapse file tree 3 files changed +44
-5
lines changed
main/java/graphql/kickstart/spring/webclient/boot
test/java/graphql/kickstart/spring/webclient/boot Expand file tree Collapse file tree 3 files changed +44
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import java .util .List ;
4
4
import lombok .EqualsAndHashCode ;
5
- import lombok .RequiredArgsConstructor ;
5
+ import lombok .NonNull ;
6
6
import lombok .Value ;
7
7
8
8
@ Value
9
9
@ EqualsAndHashCode (callSuper = false )
10
- @ RequiredArgsConstructor
11
10
public class GraphQLErrorsException extends RuntimeException {
12
11
13
12
transient List <GraphQLError > errors ;
13
+ String message ;
14
14
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 ();
18
21
}
19
22
20
23
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ lombok.addLombokGeneratedAnnotation = true
You can’t perform that action at this time.
0 commit comments