@Test @SuppressWarnings("ResultOfMethodCallIgnored") public void getErrorTextShouldReturnTextWhenJsonIsInvalid() throws Exception { final String actual = underTest.getErrorText("{{}}"); assertThat(actual) .overridingErrorMessage("Expected value returned by getErrorText is not empty, but was <%s>", actual) .isNotEmpty(); verify(bundle).message("error.message.validator.json.invalid"); }
@Nullable @Override public String getErrorText(@Nullable String json) { if (Strings.isNullOrEmpty(json)) { return bundle.message("error.message.validator.json.empty"); } try { final JsonElement root = parser.parse(json); if (root.isJsonNull() || root.isJsonPrimitive()) { return bundle.message("error.message.validator.json.primitive"); } } catch (JsonSyntaxException e) { return bundle.message("error.message.validator.json.invalid"); } catch (JsonParseException e) { return bundle.message("error.message.validator.json.parse"); } return null; }
JsonValidator implements InputValidatorEx { @Nullable @Override public String getErrorText(@Nullable String json) { if (Strings.isNullOrEmpty(json)) { return bundle.message("error.message.validator.json.empty"); } try { final JsonElement root = parser.parse(json); if (root.isJsonNull() || root.isJsonPrimitive()) { return bundle.message("error.message.validator.json.primitive"); } } catch (JsonSyntaxException e) { return bundle.message("error.message.validator.json.invalid"); } catch (JsonParseException e) { return bundle.message("error.message.validator.json.parse"); } return null; } }
JsonValidator implements InputValidatorEx { @Nullable @Override public String getErrorText(@Nullable String json) { if (Strings.isNullOrEmpty(json)) { return bundle.message("error.message.validator.json.empty"); } try { final JsonElement root = parser.parse(json); if (root.isJsonNull() || root.isJsonPrimitive()) { return bundle.message("error.message.validator.json.primitive"); } } catch (JsonSyntaxException e) { return bundle.message("error.message.validator.json.invalid"); } catch (JsonParseException e) { return bundle.message("error.message.validator.json.parse"); } return null; } @Inject  JsonValidator(@Nonnull Json2JavaBundle bundle, @Nonnull JsonParser parser); }
JsonValidator implements InputValidatorEx { @Nullable @Override public String getErrorText(@Nullable String json) { if (Strings.isNullOrEmpty(json)) { return bundle.message("error.message.validator.json.empty"); } try { final JsonElement root = parser.parse(json); if (root.isJsonNull() || root.isJsonPrimitive()) { return bundle.message("error.message.validator.json.primitive"); } } catch (JsonSyntaxException e) { return bundle.message("error.message.validator.json.invalid"); } catch (JsonParseException e) { return bundle.message("error.message.validator.json.parse"); } return null; } @Inject  JsonValidator(@Nonnull Json2JavaBundle bundle, @Nonnull JsonParser parser); @Nullable @Override String getErrorText(@Nullable String json); @Override boolean checkInput(@Nullable String json); @Override @SuppressWarnings("SimplifiableIfStatement") boolean canClose(@Nullable String json); }
JsonValidator implements InputValidatorEx { @Nullable @Override public String getErrorText(@Nullable String json) { if (Strings.isNullOrEmpty(json)) { return bundle.message("error.message.validator.json.empty"); } try { final JsonElement root = parser.parse(json); if (root.isJsonNull() || root.isJsonPrimitive()) { return bundle.message("error.message.validator.json.primitive"); } } catch (JsonSyntaxException e) { return bundle.message("error.message.validator.json.invalid"); } catch (JsonParseException e) { return bundle.message("error.message.validator.json.parse"); } return null; } @Inject  JsonValidator(@Nonnull Json2JavaBundle bundle, @Nonnull JsonParser parser); @Nullable @Override String getErrorText(@Nullable String json); @Override boolean checkInput(@Nullable String json); @Override @SuppressWarnings("SimplifiableIfStatement") boolean canClose(@Nullable String json);  }