@Test
public void testGenerateNew() throws Exception {

  KeyTemplate kt = AesGcmKeyManager.aes128GcmTemplate();
  KeysetHandle handle = KeysetHandle.generateNew(kt);
  Keyset keyset = handle.getKeyset();
  assertThat(keyset.getKeyCount()).isEqualTo(1);
  Keyset.Key key = keyset.getKey(0);
  assertThat(keyset.getPrimaryKeyId()).isEqualTo(key.getKeyId());
  assertThat(key.getStatus()).isEqualTo(KeyStatusType.ENABLED);
  assertThat(key.getOutputPrefixType()).isEqualTo(OutputPrefixType.TINK);
  assertThat(key.hasKeyData()).isTrue();
  assertThat(key.getKeyData().getTypeUrl()).isEqualTo(kt.getTypeUrl());
  AesGcmKeyFormat aesGcmKeyFormat =
      AesGcmKeyFormat.parseFrom(kt.getValue(), ExtensionRegistryLite.getEmptyRegistry());
  AesGcmKey aesGcmKey =
      AesGcmKey.parseFrom(key.getKeyData().getValue(), ExtensionRegistryLite.getEmptyRegistry());
  assertThat(aesGcmKey.getKeyValue().size()).isEqualTo(aesGcmKeyFormat.getKeySize());
}