File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
main/java/io/intercom/api
test/java/io/intercom/api Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,12 @@ public IntercomException(ErrorCollection errorCollection) {
2121 }
2222
2323 public static String getMessage (ErrorCollection errorCollection ) {
24- String message = "" ;
25- if (errorCollection !=null && errorCollection .getErrors () != null && errorCollection .getErrors ().size () > 0 && errorCollection .getErrors ().get (0 ) != null ){
24+ String message = "Could not read error message from server" ;
25+ if (errorCollection !=null
26+ && errorCollection .getErrors () != null
27+ && errorCollection .getErrors ().size () > 0
28+ && errorCollection .getErrors ().get (0 ) != null
29+ && errorCollection .getErrors ().get (0 ).getMessage () != null ){
2630 message = errorCollection .getErrors ().get (0 ).getMessage ();
2731 }
2832 return message ;
Original file line number Diff line number Diff line change 1+ package io .intercom .api ;
2+
3+ import com .google .common .collect .Lists ;
4+ import org .junit .Test ;
5+
6+ import static org .junit .Assert .*;
7+
8+ public class IntercomExceptionTest {
9+
10+ @ Test
11+ public void testNullCollection () {
12+ assertEquals ("Could not read error message from server" , IntercomException .getMessage (null ));
13+ }
14+
15+ @ Test
16+ public void testBlankCollection () {
17+ ErrorCollection ec = new ErrorCollection ();
18+ assertEquals ("Could not read error message from server" , IntercomException .getMessage (ec ));
19+ }
20+
21+ @ Test
22+ public void testEmptyCollection () {
23+ try {
24+ new ErrorCollection (Lists .<Error >newArrayList ());
25+ fail ();
26+ } catch (IllegalArgumentException e ) {
27+ }
28+ final ErrorCollection ec = new ErrorCollection (Lists .newArrayList (new Error ()));
29+ assertEquals ("Could not read error message from server" , IntercomException .getMessage (ec ));
30+ }
31+
32+ }
You can’t perform that action at this time.
0 commit comments