Skip to content
Permalink
Browse files

Allows asClass in conditional components

Modify the parameter given to the template, in order to manage forced
types.
  • Loading branch information
a-peyrard committed Feb 11, 2015
1 parent b55740d commit 8d7865400e1c3d221fc8ce94bf550aaba5e2008b
@@ -13,9 +13,12 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.Comparator;
import java.util.Set;
import restx.factory.Factory;
import restx.factory.Name;
import restx.factory.NamedComponent;
import restx.factory.TestGreeting;
import restx.factory.conditional.components.TestConditionalComponent;
import restx.factory.conditional.components.TestInterfaces;
import restx.factory.conditional.components.TestModuleWithConditional;
@@ -124,4 +127,14 @@ public void should_find_conditional_component_when_condition_is_satisfied() {
conditional = factory.queryByName(Name.of(TestConditionalComponent.class, "conditional")).findOneAsComponent();
assertThat(conditional.isPresent()).isTrue();
}

@Test
public void should_use_asClass_parameter_for_conditional_components() {
overrideComponents().set("allow.comparator", "true");

Factory factory = Factory.newInstance();
Optional<NamedComponent<Comparator>> one = factory.queryByClass(Comparator.class).findOne();
assertThat(one.isPresent());
assertThat(one.get().getName().getClazz()).isEqualTo(Comparator.class);
}
}
@@ -0,0 +1,20 @@
package restx.factory.conditional.components;

/**
* @author apeyrard
*/

import java.util.Comparator;
import javax.inject.Named;
import restx.factory.Component;
import restx.factory.When;

@Component(asClass = Comparator.class)
@Named("test.comparator")
@When(name = "allow.comparator", value = "true")
public class TestConditionalAsClass implements Comparator {
@Override
public int compare(Object o1, Object o2) {
return 0;
}
}
@@ -464,7 +464,7 @@ private void generateMachineFile(ComponentClass componentClass, When when) throw
.put("machine", componentClass.name + "FactoryMachine")
.put("imports", ImmutableList.of(componentClass.fqcn))
.put("componentType", componentClass.name)
.put("componentInjectionType", componentClass.name)
.put("componentInjectionType", componentClass.producedName)
.put("priority", String.valueOf(componentClass.priority))
.put("whenName", when.name())
.put("whenValue", when.value())

0 comments on commit 8d78654

Please sign in to comment.
You can’t perform that action at this time.