### Question:
KeyPair { public static KeyPair onlyPublic(final PublicKey publicKey) { return new KeyPair(Optional.empty(), publicKey, CryptoEngines.defaultEngine()); } private  KeyPair(
      final Optional<PrivateKey> privateKey, final PublicKey publicKey, CryptoEngine engine); static KeyPair random(); static KeyPair random(CryptoEngine engine); static KeyPair fromPrivate(final PrivateKey privateKey, final CryptoEngine engine); static KeyPair onlyPublic(final PublicKey publicKey); static KeyPair onlyPublic(final PublicKey publicKey, final CryptoEngine engine); static KeyPair fromPrivate(final PrivateKey privateKey); PrivateKey getPrivateKey(); PublicKey getPublicKey(); boolean hasPrivateKey();  }### Answer:
@Test void ctorFailsIfPublicKeyIsNotCompressed() { final KeyPairContext context = new KeyPairContext(); final PublicKey publicKey = Mockito.mock(PublicKey.class); Mockito.when(context.analyzer.isKeyCompressed(publicKey)).thenReturn(false); IllegalArgumentException exception = Assertions.assertThrows( IllegalArgumentException.class, () -> KeyPair.onlyPublic(publicKey, context.engine)); Assertions.assertEquals("PublicKey must be in compressed form", exception.getMessage()); }