File tree Expand file tree Collapse file tree 5 files changed +89
-0
lines changed
main/java/com/optimizely/ab/config/parser
test/java/com/optimizely/ab/config/parser Expand file tree Collapse file tree 5 files changed +89
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,9 @@ final class GsonConfigParser implements ConfigParser {
3333
3434 @ Override
3535 public ProjectConfig parseProjectConfig (@ Nonnull String json ) throws ConfigParseException {
36+ if (json == null || json .length () == 0 ) {
37+ throw new ConfigParseException ("Unable to parse datafile: " + json );
38+ }
3639 Gson gson = new GsonBuilder ()
3740 .registerTypeAdapter (ProjectConfig .class , new ProjectConfigGsonDeserializer ())
3841 .registerTypeAdapter (Audience .class , new AudienceGsonDeserializer ())
Original file line number Diff line number Diff line change @@ -86,4 +86,26 @@ public void validJsonRequiredFieldMissingExceptionWrapping() throws Exception {
8686 GsonConfigParser parser = new GsonConfigParser ();
8787 parser .parseProjectConfig ("{\" valid\" : \" json\" }" );
8888 }
89+
90+ /**
91+ * Verify that empty string JSON results in a {@link ConfigParseException} being thrown.
92+ */
93+ @ Test
94+ public void emptyJsonExceptionWrapping () throws Exception {
95+ thrown .expect (ConfigParseException .class );
96+
97+ GsonConfigParser parser = new GsonConfigParser ();
98+ parser .parseProjectConfig ("" );
99+ }
100+
101+ /**
102+ * Verify that null JSON results in a {@link ConfigParseException} being thrown.
103+ */
104+ @ Test
105+ public void nullJsonExceptionWrapping () throws Exception {
106+ thrown .expect (ConfigParseException .class );
107+
108+ GsonConfigParser parser = new GsonConfigParser ();
109+ parser .parseProjectConfig (null );
110+ }
89111}
Original file line number Diff line number Diff line change @@ -86,4 +86,26 @@ public void validJsonRequiredFieldMissingExceptionWrapping() throws Exception {
8686 JacksonConfigParser parser = new JacksonConfigParser ();
8787 parser .parseProjectConfig ("{\" valid\" : \" json\" }" );
8888 }
89+
90+ /**
91+ * Verify that empty string JSON results in a {@link ConfigParseException} being thrown.
92+ */
93+ @ Test
94+ public void emptyJsonExceptionWrapping () throws Exception {
95+ thrown .expect (ConfigParseException .class );
96+
97+ JacksonConfigParser parser = new JacksonConfigParser ();
98+ parser .parseProjectConfig ("" );
99+ }
100+
101+ /**
102+ * Verify that null JSON results in a {@link ConfigParseException} being thrown.
103+ */
104+ @ Test
105+ public void nullJsonExceptionWrapping () throws Exception {
106+ thrown .expect (ConfigParseException .class );
107+
108+ JacksonConfigParser parser = new JacksonConfigParser ();
109+ parser .parseProjectConfig (null );
110+ }
89111}
Original file line number Diff line number Diff line change @@ -86,4 +86,26 @@ public void validJsonRequiredFieldMissingExceptionWrapping() throws Exception {
8686 JsonConfigParser parser = new JsonConfigParser ();
8787 parser .parseProjectConfig ("{\" valid\" : \" json\" }" );
8888 }
89+
90+ /**
91+ * Verify that empty string JSON results in a {@link ConfigParseException} being thrown.
92+ */
93+ @ Test
94+ public void emptyJsonExceptionWrapping () throws Exception {
95+ thrown .expect (ConfigParseException .class );
96+
97+ JsonConfigParser parser = new JsonConfigParser ();
98+ parser .parseProjectConfig ("" );
99+ }
100+
101+ /**
102+ * Verify that null JSON results in a {@link ConfigParseException} being thrown.
103+ */
104+ @ Test
105+ public void nullJsonExceptionWrapping () throws Exception {
106+ thrown .expect (ConfigParseException .class );
107+
108+ JsonConfigParser parser = new JsonConfigParser ();
109+ parser .parseProjectConfig (null );
110+ }
89111}
Original file line number Diff line number Diff line change @@ -86,4 +86,24 @@ public void validJsonRequiredFieldMissingExceptionWrapping() throws Exception {
8686 JsonSimpleConfigParser parser = new JsonSimpleConfigParser ();
8787 parser .parseProjectConfig ("{\" valid\" : \" json\" }" );
8888 }
89+ /**
90+ * Verify that empty string JSON results in a {@link ConfigParseException} being thrown.
91+ */
92+ @ Test
93+ public void emptyJsonExceptionWrapping () throws Exception {
94+ thrown .expect (ConfigParseException .class );
95+
96+ JsonSimpleConfigParser parser = new JsonSimpleConfigParser ();
97+ parser .parseProjectConfig ("" );
98+ }
99+ /**
100+ * Verify that null JSON results in a {@link ConfigParseException} being thrown.
101+ */
102+ @ Test
103+ public void nullJsonExceptionWrapping () throws Exception {
104+ thrown .expect (ConfigParseException .class );
105+
106+ JsonSimpleConfigParser parser = new JsonSimpleConfigParser ();
107+ parser .parseProjectConfig (null );
108+ }
89109}
You can’t perform that action at this time.
0 commit comments