ToHelper { public Class<?> getToSubType(Class<?> toType, Object domainObject) { DomainClassDelegate domainClassDelegate = toType.getAnnotation(DomainClassDelegate.class); if (null != domainClassDelegate) { for (Class<?> delegate : domainClassDelegate.delegates()) { Class<?> delegateDomain = getDomainClass(delegate); if (delegateDomain.isInstance(domainObject)) { toType = delegate; } } } return toType; }  void setClassReplacer(ClassReplacer classReplacer); boolean isTo(Object object); boolean isToClass(Class<?> toClass); Class<?> getDomainClass(Class<?> toClass); Class<?> getToSubType(Class<?> toType, Object domainObject);  }
@Test public void getToSubTypeNoDomainClassDelegates() throws Exception { assertThat(toHelper.getToSubType(PersonTo.class, new PersonTo())).isEqualTo(PersonTo.class); }
@Test public void getToSubTypeWithDomainClassDelegates() throws Exception { assertThat(toHelper.getToSubType(AbstractHumanTo.class, new FemaleHumanDomain())). isEqualTo(FemaleHumanTo.class); assertThat(toHelper.getToSubType(AbstractHumanTo.class, new MaleHumanDomain())).isEqualTo(MaleHumanTo.class); assertThat(toHelper.getToSubType(AbstractHumanTo.class, new Object())).isEqualTo(AbstractHumanTo.class); assertThat(toHelper.getToSubType(AbstractHumanTo.class, new MaleHumanDomain(){})).isEqualTo(MaleHumanTo.class); }