@Test public void validateKey() throws Exception {

  String key = null;
  try {
    key = "has_space ";
    cache.edit(key);
    fail("Exepcting an IllegalArgumentException as the key was invalid.");
  } catch (IllegalArgumentException iae) {
    assertThat(iae.getMessage()).isEqualTo(
        "keys must match regex [a-z0-9_-]{1,64}: \"" + key + "\"");
  }
  try {
    key = "has_CR\r";
    cache.edit(key);
    fail("Exepcting an IllegalArgumentException as the key was invalid.");
  } catch (IllegalArgumentException iae) {
    assertThat(iae.getMessage()).isEqualTo(
        "keys must match regex [a-z0-9_-]{1,64}: \"" + key + "\"");
  }
  try {
    key = "has_LF\n";
    cache.edit(key);
    fail("Exepcting an IllegalArgumentException as the key was invalid.");
  } catch (IllegalArgumentException iae) {
    assertThat(iae.getMessage()).isEqualTo(
        "keys must match regex [a-z0-9_-]{1,64}: \"" + key + "\"");
  }
  try {
    key = "has_invalid/";
    cache.edit(key);
    fail("Exepcting an IllegalArgumentException as the key was invalid.");
  } catch (IllegalArgumentException iae) {
    assertThat(iae.getMessage()).isEqualTo(
        "keys must match regex [a-z0-9_-]{1,64}: \"" + key + "\"");
  }
  try {
    key = "has_invalid\u2603";
    cache.edit(key);
    fail("Exepcting an IllegalArgumentException as the key was invalid.");
  } catch (IllegalArgumentException iae) {
    assertThat(iae.getMessage()).isEqualTo(
        "keys must match regex [a-z0-9_-]{1,64}: \"" + key + "\"");
  }
  try {
    key = "this_is_way_too_long_this_is_way_too_long_this_is_way_too_long_this_is_way_too_long";
    cache.edit(key);
    fail("Exepcting an IllegalArgumentException as the key was too long.");
  } catch (IllegalArgumentException iae) {
    assertThat(iae.getMessage()).isEqualTo(
        "keys must match regex [a-z0-9_-]{1,64}: \"" + key + "\"");
  }
  // Test valid cases.
  // Exactly 64.
  key = "0123456789012345678901234567890123456789012345678901234567890123";
  cache.edit(key).abort();
  // Contains all valid characters.
  key = "abcdefghijklmnopqrstuvwxyz_0123456789";
  cache.edit(key).abort();
  // Contains dash.
  key = "-20384573948576";
  cache.edit(key).abort();
}