When object factory fails to construct a prefab automatically (e.g. because the type is abstract or non-instantiable), an exception is thrown which explains very little about the problem and difficult to enterpret.
Receiver class nl.jqno.equalsverifier.internal.reflection.PublicKey$$DynamicSubclass$41294f8$ does not define or inherit an implementation of the resolved method 'abstract byte[] getEncoded()' of interface java.security.Key.
java.lang.AbstractMethodError: Receiver class nl.jqno.equalsverifier.internal.reflection.PublicKey$$DynamicSubclass$41294f8$ does not define or inherit an implementation of the resolved method 'abstract byte[] getEncoded()' of interface java.security.Key.
at core.security.PublicKeyEncoding.encodeX509(PublicKeyEncoding.java:47)
at core.state.EncryptionKeysMapper.encodePublicKey(EncryptionKeysMapper.java:34)
at core.state.EncryptionKeysMapperImpl.encryptionKeysToPublicKeyEntity(EncryptionKeysMapperImpl.java:52)
at core.state.EncryptionKeysMapperImpl.toEntity(EncryptionKeysMapperImpl.java:25)
at core.state.EndpointAppKeysMapperImpl.toEntity(EndpointAppKeysMapperImpl.java:29)
at state.EndpointAppKeysMapperTest.testTransitive(EndpointAppKeysMapperTest.java:33)
Such exception should be wrapped into a higher-level exception explaining the problem and possible solution (i.e., Consider introducing a prefab for PublicKey)
Minimal reproducible example
public class EndpointAppKeys {
private CipherSuite cipherSuite;
private EncryptionKeys clientKeys;
}
public class EncryptionKeys {
private PublicKey publicKey; // <-- PublicKey is interface. It declares but never defines `public byte[] getEncoded()`, hence the failure to instantiate the mock
}
@ExtendWith(RedAndBlueExtension.class)
public class EndpointAppKeysMapperTest {
@Test
void testTransitive(@RedInstance EndpointAppKeys red, @BlueInstance EndpointAppKeys blue) {
...
}
}
Confusing error message when a prefab is needed
When object factory fails to construct a prefab automatically (e.g. because the type is abstract or non-instantiable), an exception is thrown which explains very little about the problem and difficult to enterpret.
Such exception should be wrapped into a higher-level exception explaining the problem and possible solution (i.e.,
Consider introducing a prefab for PublicKey
)Minimal reproducible example