AggregatePartClass extends AggregateClass<A> { public static <A extends AggregatePart> AggregatePartClass<A> asAggregatePartClass(Class<A> cls) { checkNotNull(cls); AggregatePartClass<A> result = (AggregatePartClass<A>) get(cls, AggregatePartClass.class, () -> new AggregatePartClass<>(cls)); return result; } private  AggregatePartClass(Class<A> cls); static AggregatePartClass<A> asAggregatePartClass(Class<A> cls); @SuppressWarnings("unchecked") // The type is ensured by the class declaration. Class<? extends AggregateRoot<?>> rootClass(); @SuppressWarnings("TypeParameterUnusedInFormals") // The returned type _is_ bound with the type of identifiers. R createRoot(BoundedContext bc, I aggregateId);  }
@Test @DisplayName("throw exception when aggregate part does not have appropriate constructor") void throwOnNoProperCtorAvailable() { AggregatePartClass<WrongAggregatePart> wrongPartClass = asAggregatePartClass(WrongAggregatePart.class); assertThrows(ModelError.class, wrongPartClass::constructor); }