@Test public void ensureValidKeyFailsTest() { String[] invalidKeys = new String[]{ "\"", "'", "slice\\dice", "valid?no", "yüce", "*xyz", "with space", "<script>", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1" }; for (String key : invalidKeys) { try { Validator.ensureValidKey(key); } catch (ValidationException ex) { continue; } fail("Key validation should have failed for: " + key); } }
public static void ensureValidKey(String key) { if (!validKey(key)) { throw new ValidationException(String.format("Invalid key: %s", key)); } }
Validator { public static void ensureValidKey(String key) { if (!validKey(key)) { throw new ValidationException(String.format("Invalid key: %s", key)); } } }
Validator { public static void ensureValidKey(String key) { if (!validKey(key)) { throw new ValidationException(String.format("Invalid key: %s", key)); } } Validator(); }
Validator { public static void ensureValidKey(String key) { if (!validKey(key)) { throw new ValidationException(String.format("Invalid key: %s", key)); } } Validator(); @SuppressWarnings("WeakerAccess") static boolean validIndexName(String indexName); static void ensureValidIndexName(String indexName); @SuppressWarnings("WeakerAccess") static boolean validFieldName(String fieldName); static void ensureValidFieldName(String fieldName); @SuppressWarnings("WeakerAccess") static boolean validLabel(String label); static void ensureValidLabel(String label); @SuppressWarnings("WeakerAccess") static boolean validKey(String key); static void ensureValidKey(String key); }
Validator { public static void ensureValidKey(String key) { if (!validKey(key)) { throw new ValidationException(String.format("Invalid key: %s", key)); } } Validator(); @SuppressWarnings("WeakerAccess") static boolean validIndexName(String indexName); static void ensureValidIndexName(String indexName); @SuppressWarnings("WeakerAccess") static boolean validFieldName(String fieldName); static void ensureValidFieldName(String fieldName); @SuppressWarnings("WeakerAccess") static boolean validLabel(String label); static void ensureValidLabel(String label); @SuppressWarnings("WeakerAccess") static boolean validKey(String key); static void ensureValidKey(String key);  }