KeyValueStoreHelper { public static boolean isValidKey(@Nullable final String key) { return key != null && key.length() > 0 && !key.startsWith(".") && !key.endsWith(".") && !key.contains("..") && VALID_KEY_CHARACTERS_PATTERN.matcher(key).matches(); } private  KeyValueStoreHelper(); static boolean isValidKey(@Nullable final String key);  }
@Test public void testIsValidKey() { Assert.assertFalse(KeyValueStoreHelper.isValidKey(null)); Assert.assertFalse(KeyValueStoreHelper.isValidKey("")); Assert.assertFalse(KeyValueStoreHelper.isValidKey(".")); Assert.assertFalse(KeyValueStoreHelper.isValidKey("..")); Assert.assertFalse(KeyValueStoreHelper.isValidKey(".a.")); Assert.assertFalse(KeyValueStoreHelper.isValidKey("a.")); Assert.assertFalse(KeyValueStoreHelper.isValidKey(".a")); Assert.assertFalse(KeyValueStoreHelper.isValidKey("$")); Assert.assertFalse(KeyValueStoreHelper.isValidKey("=")); Assert.assertFalse(KeyValueStoreHelper.isValidKey("a.b..c")); Assert.assertTrue(KeyValueStoreHelper.isValidKey("a")); Assert.assertTrue(KeyValueStoreHelper.isValidKey("a.b")); Assert.assertTrue(KeyValueStoreHelper.isValidKey("a.b.c")); Assert.assertTrue(KeyValueStoreHelper.isValidKey("a-b-c")); Assert.assertTrue(KeyValueStoreHelper.isValidKey("a_b_c")); Assert.assertTrue(KeyValueStoreHelper.isValidKey("a._-b")); Assert.assertTrue(KeyValueStoreHelper.isValidKey("____")); Assert.assertTrue(KeyValueStoreHelper.isValidKey("----")); }