Search in sources :

Example 1 with ContextImpl

use of org.terasology.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class TreeTests method setup.

@Before
public void setup() {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    // Needed only as long as #1536 is unresolved
    context.put(Config.class, new Config(new MockContext()));
    blockManager = Mockito.mock(BlockManager.class);
    Block air = blockManager.getBlock(BlockManager.AIR_ID);
    biomeManager = Mockito.mock(BiomeManager.class);
    Mockito.when(blockManager.getBlock(Matchers.<BlockUri>any())).thenReturn(air);
    Mockito.when(blockManager.getBlock(Matchers.<String>any())).thenReturn(air);
    context.put(BlockManager.class, blockManager);
}
Also used : BiomeManager(org.terasology.world.biomes.BiomeManager) MockContext(org.terasology.context.internal.MockContext) Config(org.terasology.config.Config) BlockManager(org.terasology.world.block.BlockManager) Block(org.terasology.world.block.Block) ContextImpl(org.terasology.context.internal.ContextImpl) Before(org.junit.Before)

Example 2 with ContextImpl

use of org.terasology.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class ComponentSerializerTest method setup.

@Before
public void setup() {
    context = new ContextImpl();
    context.put(ModuleManager.class, moduleManager);
    CoreRegistry.setContext(context);
    TypeSerializationLibrary serializationLibrary = new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary);
    serializationLibrary.add(Vector3f.class, new Vector3fTypeHandler());
    serializationLibrary.add(Quat4f.class, new Quat4fTypeHandler());
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    EngineEntityManager entityManager = context.get(EngineEntityManager.class);
    entityManager.getComponentLibrary().register(new SimpleUri("test", "gettersetter"), GetterSetterComponent.class);
    entityManager.getComponentLibrary().register(new SimpleUri("test", "string"), StringComponent.class);
    entityManager.getComponentLibrary().register(new SimpleUri("test", "integer"), IntegerComponent.class);
    ComponentLibrary componentLibrary = entityManager.getComponentLibrary();
    componentSerializer = new ComponentSerializer(componentLibrary, serializationLibrary);
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) Vector3fTypeHandler(org.terasology.persistence.typeHandling.mathTypes.Vector3fTypeHandler) NetworkSystem(org.terasology.network.NetworkSystem) SimpleUri(org.terasology.engine.SimpleUri) ComponentLibrary(org.terasology.entitySystem.metadata.ComponentLibrary) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) Quat4fTypeHandler(org.terasology.persistence.typeHandling.mathTypes.Quat4fTypeHandler) ContextImpl(org.terasology.context.internal.ContextImpl) ComponentSerializer(org.terasology.persistence.serializers.ComponentSerializer) Before(org.junit.Before)

Example 3 with ContextImpl

use of org.terasology.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class InjectionHelperTest method testConstructorInjectionNoDefaultConstructorForFallback.

@Test(expected = NoSuchElementException.class)
public void testConstructorInjectionNoDefaultConstructorForFallback() {
    Context context = new ContextImpl();
    context.put(ServiceA.class, serviceA);
    // context.put(ServiceB.class, serviceB);
    // there is only one constructor for serviceB which is not present on the context.
    // a default constructor is not available, so the injection fails.
    InjectionHelper.createWithConstructorInjection(ConstructorB.class, context);
}
Also used : Context(org.terasology.context.Context) ContextImpl(org.terasology.context.internal.ContextImpl) Test(org.junit.Test)

Example 4 with ContextImpl

use of org.terasology.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class InjectionHelperTest method testConstructorInjectionNotAllParametersPopulatedFallback.

@Test
public void testConstructorInjectionNotAllParametersPopulatedFallback() {
    Context context = new ContextImpl();
    context.put(ServiceA.class, serviceA);
    // context.put(ServiceB.class, serviceB);
    ConstructorA_AB constructorA_AB = InjectionHelper.createWithConstructorInjection(ConstructorA_AB.class, context);
    // the one-arg constructor is used as it can be populated  with serviceA which is available
    assertThat(constructorA_AB.getServiceA(), is(serviceA));
    assertThat(constructorA_AB.getServiceB(), is(nullValue()));
}
Also used : Context(org.terasology.context.Context) ContextImpl(org.terasology.context.internal.ContextImpl) Test(org.junit.Test)

Example 5 with ContextImpl

use of org.terasology.context.internal.ContextImpl in project Terasology by MovingBlocks.

the class BindsSubsystemTest method setUp.

@Before
public void setUp() {
    bindsSubsystem = new BindsSubsystem();
    bindsConfiguration = new BindsConfigAdapter(new BindsConfig());
    context = new ContextImpl();
    context.put(BindsConfiguration.class, bindsConfiguration);
    bindsSubsystem.preInitialise(context);
    setUpMockModuleEnvironment();
}
Also used : BindsConfigAdapter(org.terasology.engine.subsystem.config.BindsSubsystem.BindsConfigAdapter) BindsConfig(org.terasology.config.BindsConfig) ContextImpl(org.terasology.context.internal.ContextImpl) Before(org.junit.Before)

Aggregations

ContextImpl (org.terasology.context.internal.ContextImpl)21 Before (org.junit.Before)10 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)7 Context (org.terasology.context.Context)6 ModuleManager (org.terasology.engine.module.ModuleManager)6 Prefab (org.terasology.entitySystem.prefab.Prefab)6 PrefabData (org.terasology.entitySystem.prefab.PrefabData)6 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)6 Test (org.junit.Test)5 BeforeClass (org.junit.BeforeClass)4 NetworkSystem (org.terasology.network.NetworkSystem)4 TypeSerializationLibrary (org.terasology.persistence.typeHandling.TypeSerializationLibrary)4 Config (org.terasology.config.Config)3 ComponentLibrary (org.terasology.entitySystem.metadata.ComponentLibrary)3 PojoPrefabManager (org.terasology.entitySystem.prefab.internal.PojoPrefabManager)3 MockContext (org.terasology.context.internal.MockContext)2 SimpleUri (org.terasology.engine.SimpleUri)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 EntitySystemLibrary (org.terasology.entitySystem.metadata.EntitySystemLibrary)2 Quat4fTypeHandler (org.terasology.persistence.typeHandling.mathTypes.Quat4fTypeHandler)2