KeyTypeManager { final Class<?> firstSupportedPrimitiveClass() { return firstPrimitiveClass; } @SafeVarargs // Safe because we do not reference the array (see Effective Java ed. 3, Item 32). protected  KeyTypeManager(Class<KeyProtoT> clazz, PrimitiveFactory<?, KeyProtoT>... factories); final Class<KeyProtoT> getKeyClass(); abstract String getKeyType(); abstract int getVersion(); abstract KeyMaterialType keyMaterialType(); abstract KeyProtoT parseKey(ByteString byteString); abstract void validateKey(KeyProtoT keyProto); final P getPrimitive(KeyProtoT key, Class<P> primitiveClass); final Set<Class<?>> supportedPrimitives(); KeyFactory<?, KeyProtoT> keyFactory();  }
@Test public void firstSupportedPrimitiveClass() throws Exception { KeyTypeManager<AesGcmKey> keyManager = new TestKeyTypeManager( new TestKeyTypeManager.PrimitiveFactory<Primitive1, AesGcmKey>(Primitive1.class) { @Override public Primitive1 getPrimitive(AesGcmKey key) { return new Primitive1(key.getKeyValue()); } }, new TestKeyTypeManager.PrimitiveFactory<Primitive2, AesGcmKey>(Primitive2.class) { @Override public Primitive2 getPrimitive(AesGcmKey key) { return new Primitive2(key.getKeyValue().size()); } }); assertThat(keyManager.firstSupportedPrimitiveClass()).isEqualTo(Primitive1.class); }
@Test public void firstSupportedPrimitiveClass_returnsVoid() throws Exception { KeyTypeManager<AesGcmKey> keyManager = new TestKeyTypeManager(); assertThat(keyManager.firstSupportedPrimitiveClass()).isEqualTo(Void.class); }