Search in sources :

Example 11 with Context

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()));
}
Also used : Context(org.terasology.context.Context) ContextImpl(org.terasology.context.internal.ContextImpl) Test(org.junit.Test)

Example 12 with Context

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));
}
Also used : Context(org.terasology.context.Context) ContextImpl(org.terasology.context.internal.ContextImpl) Test(org.junit.Test)

Example 13 with Context

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<>();
}
Also used : Context(org.terasology.context.Context) ContextImpl(org.terasology.context.internal.ContextImpl) TimeSystem(org.terasology.engine.subsystem.headless.device.TimeSystem) Before(org.junit.Before)

Aggregations

Context (org.terasology.context.Context)13 ContextImpl (org.terasology.context.internal.ContextImpl)7 Test (org.junit.Test)4 Before (org.junit.Before)3 HashMap (java.util.HashMap)2 DisplayDevice (org.terasology.engine.subsystem.DisplayDevice)2 EntityManager (org.terasology.entitySystem.entity.EntityManager)2 Metrics (org.terasology.telemetry.Metrics)2 TelemetryCategory (org.terasology.telemetry.TelemetryCategory)2 Metric (org.terasology.telemetry.metrics.Metric)2 Lists (com.google.common.collect.Lists)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Callable (java.util.concurrent.Callable)1 Collectors (java.util.stream.Collectors)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 Logger (org.slf4j.Logger)1