### Question:
MagnetInstanceManager implements InstanceManager { @Override public <T> @Nullable InstanceFactory<T> getFilteredInstanceFactory( Class<T> type, String classifier, FactoryFilter factoryFilter ) { Range range = getOptionalRange(type, classifier); if (range == null) { return null; } if (range.getCount() == 1) { InstanceFactory factory = factories[range.getFrom()]; if (factoryFilter.filter(factory)) { return factory; } return null; } InstanceFactory<T> factory = null; for (int index = range.getFrom(), afterLast = range.getFrom() + range.getCount(); index < afterLast; index++) { InstanceFactory<T> candidate = factories[index]; if (factoryFilter.filter(candidate)) { if (factory != null) { throw new IllegalStateException( String.format( "Multiple implementations of type %s (classifier: %s) can be injected," + " while single implementation is expected. Overloaded factories: %s, %s", type, classifier, factory, candidate ) ); } factory = candidate; } } return factory; } MagnetInstanceManager(); @Override InstanceFactory<T> getInstanceFactory(
        Class<T> instanceType, String classifier, Class<InstanceFactory<T>> factoryType
    ); @Override InstanceFactory<T> getFilteredInstanceFactory(
        Class<T> type, String classifier, FactoryFilter factoryFilter
    ); @Override List<InstanceFactory<T>> getManyInstanceFactories(
        Class<T> type, String classifier, FactoryFilter factoryFilter
    );  }### Answer:
@Test public void getOptionalFactory_Classified_Existing_SingleTypeInstance() { InstanceFactory<Type3> factory = instManager.getFilteredInstanceFactory( Type3.class, CLASSIFIER_LOCAL, factoryFilter); assertThat(factory).isNotNull(); }
@Test public void getOptionalFactory_Classified_Existing_ManyTypeInstances() { InstanceFactory<Type1> factory = instManager.getFilteredInstanceFactory( Type1.class, CLASSIFIER_LOCAL, factoryFilter); assertThat(factory).isNotNull(); }
@Test public void getOptionalFactory_NotClassified_Existing() { InstanceFactory<Type1> factory = instManager.getFilteredInstanceFactory( Type1.class, Classifier.NONE, factoryFilter); assertThat(factory).isNotNull(); }
@Test public void getOptionalFactory_Classified_NotExisting() { InstanceFactory<String> factory = instManager.getFilteredInstanceFactory( String.class, CLASSIFIER_LOCAL, factoryFilter); assertThat(factory).isNull(); }
@Test public void getOptionalFactory_NotClassified_NotExisting() { InstanceFactory<String> factory = instManager.getFilteredInstanceFactory( String.class, Classifier.NONE, factoryFilter); assertThat(factory).isNull(); }