@Test
public void validateKey_notValid_throws() throws Exception {

  HmacKey validKey = factory.createKey(makeHmacKeyFormat(16, 10, HashType.SHA1));
  try {
    manager.validateKey(
        HmacKey.newBuilder(validKey)
            .setKeyValue(ByteString.copyFrom(Random.randBytes(15)))
            .build());
    fail();
  } catch (GeneralSecurityException e) {
    // expected
  }
  try {
    manager
        .validateKey(
            HmacKey.newBuilder(validKey)
                .setParams(HmacParams.newBuilder(validKey.getParams()).setTagSize(0).build())
                .build());
    fail();
  } catch (GeneralSecurityException e) {
    // expected
  }
  try {
    manager
        .validateKey(
            HmacKey.newBuilder(validKey)
                .setParams(HmacParams.newBuilder(validKey.getParams()).setTagSize(9).build())
                .build());
    fail();
  } catch (GeneralSecurityException e) {
    // expected
  }
  try {
    manager
        .validateKey(
            HmacKey.newBuilder(validKey)
                .setParams(HmacParams.newBuilder(validKey.getParams()).setTagSize(21).build())
                .build());
    fail();
  } catch (GeneralSecurityException e) {
    // expected
  }
  try {
    manager
        .validateKey(
            HmacKey.newBuilder(validKey)
                .setParams(HmacParams.newBuilder(validKey.getParams()).setTagSize(32).build())
                .build());
    fail();
  } catch (GeneralSecurityException e) {
    // expected
  }
}