use of org.terasology.context.Context in project Terasology by MovingBlocks.
the class InjectionHelperTest method testConstructorInjectionNotAllParametersPopulated.
@Test
public void testConstructorInjectionNotAllParametersPopulated() {
Context context = new ContextImpl();
context.put(ServiceA.class, serviceA);
// context.put(ServiceB.class, serviceB);
ConstructorAB constructorAB = InjectionHelper.createWithConstructorInjection(ConstructorAB.class, context);
// the two-arg constructor can't be populated because serviceB is not available
// there is no fallback for a constructor with only serviceA, so the default constructor is called
assertThat(constructorAB.getServiceA(), is(nullValue()));
assertThat(constructorAB.getServiceB(), is(nullValue()));
}
use of org.terasology.context.Context in project Terasology by MovingBlocks.
the class InjectionHelperTest method testDefaultConstructorInjection.
@Test
public void testDefaultConstructorInjection() {
Context context = new ContextImpl();
context.put(ServiceA.class, serviceA);
context.put(ServiceB.class, serviceB);
ConstructorAB constructorAB = InjectionHelper.createWithConstructorInjection(ConstructorAB.class, context);
// the two-arg constructor should be used as it has the most parameters and all can be populated
assertThat(constructorAB.getServiceA(), is(serviceA));
assertThat(constructorAB.getServiceB(), is(serviceB));
}
use of org.terasology.context.Context in project Terasology by MovingBlocks.
the class InputSystemTests method setUp.
@Before
public void setUp() {
Context context = new ContextImpl();
setUpLocalPlayer(context);
setUpDisplayDevice(context);
setUpBindsManager(context);
setUpTargetSystem(context);
context.put(Time.class, new TimeSystem());
inputSystem = new InputSystem();
InjectionHelper.inject(inputSystem, context);
testKeyboard = new TestKeyboard();
inputSystem.setKeyboardDevice(testKeyboard);
clientEntityKeyEvents = new ArrayList<>();
characterEntityKeyEvents = new ArrayList<>();
}
Aggregations