@Test
  public void noBuilderSetMonitoringAnnotations_monitoringClientGetsAnnotationsWithKeysetInfo()
      throws Exception {
    MutableMonitoringRegistry.globalInstance().clear();
    FakeMonitoringClient fakeMonitoringClient = new FakeMonitoringClient();
    MutableMonitoringRegistry.globalInstance().registerMonitoringClient(fakeMonitoringClient);

    Keyset keyset =
        TestUtil.createKeyset(
            TestUtil.createKey(
                TestUtil.createAesGcmKeyData(Hex.decode("000102030405060708090a0b0c0d0e0f")),
                42,
                KeyStatusType.ENABLED,
                OutputPrefixType.TINK));
    byte[] message = Random.randBytes(123);
    MonitoringAnnotations annotations =
        MonitoringAnnotations.newBuilder().add("annotation_name", "annotation_value").build();
    KeysetHandle handleWithAnnotations = KeysetHandle.fromKeysetAndAnnotations(keyset, annotations);
    EncryptOnly encryptOnlyWithAnnotations = handleWithAnnotations.getPrimitive(EncryptOnly.class);
    Object unused = encryptOnlyWithAnnotations.encrypt(message);
    List<FakeMonitoringClient.LogEntry> entries = fakeMonitoringClient.getLogEntries();
    assertThat(entries).hasSize(1);
    assertThat(entries.get(0).getKeysetInfo().getAnnotations()).isEqualTo(annotations);
  }
Tests that when encryption failed an exception is thrown.
java_src/src/test/java/com/google/crypto/tink/KeysetHandleTest.java