DefaultTypeDeterminator implements TypeDeterminator { @SuppressWarnings("unchecked") @Override public <T> Class<T> determineClass(Class<T> type, Class<? extends T>[] candidates, Annotation qualifier, ClassLoader classLoader) { String namePrefix = ""; if (qualifier != null) { if (qualifier instanceof Named) { namePrefix = ((Named) qualifier).value(); } else { namePrefix = qualifier.annotationType().getSimpleName(); } if (candidates != null) { for (Class<? extends T> candidate : candidates) { if (candidate.getSimpleName().toLowerCase().startsWith(namePrefix.toLowerCase())) { LOGGER.debug("determineClass - returning decent {} for {}", candidate, type); return (Class<T>) candidate; } } } } LOGGER.debug("determineClass - returning {} for {}", type, type); return type; }  @SuppressWarnings("unchecked") @Override Class<T> determineClass(Class<T> type, Class<? extends T>[] candidates, Annotation qualifier, ClassLoader classLoader);  }
@Test public void determineClass_WithoutQualifier() { assertEquals(type, defaultTypeDeterminator.determineClass(type, candidates, null, classLoader)); }
@SuppressWarnings("unchecked") @Test public void determineClass_WithQualifier_NoCandidate() { candidates = new Class[] {}; assertEquals(type, defaultTypeDeterminator.determineClass(type, candidates, anno, classLoader)); }
@SuppressWarnings("unchecked") @Test public void determineClass_WithQualifier_WithCandidate() { candidates = new Class[] { SingleBean.class }; assertEquals(SingleBean.class, defaultTypeDeterminator.determineClass(type, candidates, anno, classLoader)); }
@SuppressWarnings("unchecked") @Test public void determineClass_WithQualifier_MultiCandidate() { candidates = new Class[] { SingleBean.class, MultiBean.class }; assertEquals(SingleBean.class, defaultTypeDeterminator.determineClass(type, candidates, anno, classLoader)); }