### Question:
PreferencesValidator { public static Optional<String> validateRestApiUriSyntax(Context context, String restApiUri) { if (Strings.isNullOrEmpty(restApiUri)) { return Optional.of(context.getString(R.string.invalid_rest_uri, restApiUri)); } URI uri; try { uri = URI.create(restApiUri); } catch (NullPointerException e) { return Optional.of(context.getString(R.string.invalid_rest_uri, restApiUri)); } catch (IllegalArgumentException e) { return Optional.of(context.getString(R.string.invalid_rest_uri, restApiUri)); } if (RestUriUtils.isV1Uri(uri)) { if (!RestUriUtils.hasToken(uri)) { return Optional.of(context.getString(R.string.rest_uri_missing_token, restApiUri)); } } return Optional.absent(); }  static Optional<String> validateMongoUriSyntax(Context context, String mongoUriString); static Optional<String> validateRestApiUriSyntax(Context context, String restApiUri);  }### Answer:
@Test public void testValidateRestApiUriSyntax_Invalid() { assertThat(PreferencesValidator.validateRestApiUriSyntax(getContext(), "\\invalid").get(), is(getContext().getString(R.string.invalid_rest_uri, "\\invalid"))); }
@Test public void testValidateRestApiUriSyntax_Valid() { assertThat(PreferencesValidator.validateRestApiUriSyntax(getContext(), "http: .isPresent(), is(false)); }
@Test public void testValidateRestApiUriSyntax_V1NoToken() { assertThat(PreferencesValidator.validateRestApiUriSyntax(getContext(), "http: .get(), is(getContext().getString(R.string.rest_uri_missing_token, "http: }
@Test public void testValidateRestApiUriSyntax_Empty() { assertThat(PreferencesValidator.validateRestApiUriSyntax(getContext(), "").get(), is(getContext().getString(R.string.invalid_rest_uri, ""))); }