use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.
the class VectorEventSerializer method setup.
@BeforeEach
public void setup() throws Exception {
ContextImpl context = new ContextImpl();
CoreRegistry.setContext(context);
ModuleManager moduleManager = ModuleManagerFactory.create();
context.put(ModuleManager.class, moduleManager);
context.put(ReflectFactory.class, reflectFactory);
context.put(CopyStrategyLibrary.class, copyStrategies);
ModuleTypeRegistry typeRegistry = new ModuleTypeRegistry(moduleManager.getEnvironment());
TypeHandlerLibrary typeHandlerLibrary = TypeHandlerLibraryImpl.forModuleEnvironment(moduleManager, typeRegistry);
entitySystemLibrary = new EntitySystemLibrary(context, typeHandlerLibrary);
serializer = new EventSerializer(entitySystemLibrary.getEventLibrary(), typeHandlerLibrary);
registerEvent(Vector3fTestEvent.class);
serializer.setIdMapping(eventMap);
}
use of org.terasology.engine.context.internal.ContextImpl in project Terasology by MovingBlocks.
the class EventSystemReplayImplTest method setup.
@BeforeEach
public void setup() {
ContextImpl context = new ContextImpl();
CoreRegistry.setContext(context);
Reflections reflections = new Reflections(getClass().getClassLoader());
TypeHandlerLibrary serializationLibrary = new TypeHandlerLibraryImpl(reflections);
EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, serializationLibrary);
PojoEntityManager entityManager = new PojoEntityManager();
entityManager.setComponentLibrary(entitySystemLibrary.getComponentLibrary());
entityManager.setPrefabManager(new PojoPrefabManager(context));
NetworkSystem networkSystem = mock(NetworkSystem.class);
when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
recordAndReplayCurrentStatus = new RecordAndReplayCurrentStatus();
RecordedEventStore eventStore = new RecordedEventStore();
RecordAndReplayUtils recordAndReplayUtils = new RecordAndReplayUtils();
CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
ModuleManager moduleManager = mock(ModuleManager.class);
when(moduleManager.getEnvironment()).thenReturn(mock(ModuleEnvironment.class));
RecordAndReplaySerializer recordAndReplaySerializer = new RecordAndReplaySerializer(entityManager, eventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, mock(TypeRegistry.class));
recordAndReplayCurrentStatus.setStatus(RecordAndReplayStatus.REPLAYING);
entity = entityManager.create();
Long id = entity.getId();
eventStore.add(new RecordedEvent(id, new AttackButton(), 1, 1));
eventStore.add(new RecordedEvent(id, new AttackButton(), 2, 2));
eventStore.add(new RecordedEvent(id, new AttackButton(), 3, 3));
List<Class<?>> selectedClassesToReplay = new ArrayList<>();
selectedClassesToReplay.add(InputEvent.class);
eventSystem = new EventSystemReplayImpl(entitySystemLibrary.getEventLibrary(), networkSystem, entityManager, eventStore, recordAndReplaySerializer, recordAndReplayUtils, selectedClassesToReplay, recordAndReplayCurrentStatus);
entityManager.setEventSystem(eventSystem);
handler = new TestEventHandler();
eventSystem.registerEventHandler(handler);
}
use of org.terasology.engine.context.internal.ContextImpl 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.internal.ContextImpl in project Terasology by MovingBlocks.
the class InjectionHelperTest method setUp.
@BeforeEach
public void setUp() {
serviceA = new ServiceAImpl();
serviceB = new ServiceBImpl();
// injection helper uses the core registry,
// make sure the shared classes are not used over multiple tests
CoreRegistry.setContext(new ContextImpl());
}
use of org.terasology.engine.context.internal.ContextImpl 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());
}
Aggregations