use of org.terasology.engine.context.Context in project Terasology by MovingBlocks.
the class ComponentSystemManagerTest method setUp.
@BeforeEach
public void setUp() {
Context context = mock(Context.class);
EntityManager entityManager = mock(EntityManager.class);
when(entityManager.getEventSystem()).thenReturn(mock(EventSystem.class));
when(context.get(EntityManager.class)).thenReturn(entityManager);
console = mock(Console.class);
when(context.get(Console.class)).thenReturn(console);
systemUnderTest = new ComponentSystemManager(context);
}
use of org.terasology.engine.context.Context in project Terasology by MovingBlocks.
the class VisualCharacterSystemTest method setup.
@BeforeEach
public void setup() throws Exception {
this.system = new VisualCharacterSystem();
Context context = new ContextImpl();
this.localPlayer = Mockito.mock(LocalPlayer.class);
context.put(LocalPlayer.class, localPlayer);
Mockito.doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return clientEntityReturnedByLocalPlayer;
}
}).when(localPlayer).getClientEntity();
this.entityManager = Mockito.mock(EntityManager.class);
Mockito.doReturn(Mockito.mock(EntityBuilder.class)).when(entityManager).newBuilder();
context.put(EntityManager.class, this.entityManager);
InjectionHelper.inject(system, context);
system.setCreateAndAttachVisualEntityStrategy((entityBuilder, characterEntity) -> Mockito.mock(EntityRef.class));
}
use of org.terasology.engine.context.Context in project Terasology by MovingBlocks.
the class InjectionHelperTest method testConstructorInjectionNoDefaultConstructorForFallback.
@Test
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.
Assertions.assertThrows(NoSuchElementException.class, () -> InjectionHelper.createWithConstructorInjection(ConstructorB.class, context));
}
use of org.terasology.engine.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
assertNull(constructorAB.getServiceA());
assertNull(constructorAB.getServiceB());
}
use of org.terasology.engine.context.Context in project Terasology by MovingBlocks.
the class WorldPreGenerationScreen method setEnvironment.
/**
* A function called before the screen comes to the forefront to setup the environment
* and extract necessary objects from the new Context.
*
* @param subContext The new environment created in {@link UniverseSetupScreen}
* @throws UnresolvedWorldGeneratorException The creation of a world generator can throw this Exception
*/
public void setEnvironment(Context subContext) throws UnresolvedWorldGeneratorException {
context = subContext;
environment = context.get(ModuleEnvironment.class);
context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
worldList = context.get(UniverseSetupScreen.class).getWorldsList();
selectedWorld = context.get(UniverseSetupScreen.class).getSelectedWorld();
worldNames = context.get(UniverseSetupScreen.class).worldNames();
setWorldGenerators();
worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
worldsDropdown.setOptions(worldNames);
genTexture();
List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
if (previewZones.isEmpty()) {
previewGen = new FacetLayerPreview(environment, worldGenerator);
}
}
Aggregations