@Override public Context createChildContext() { return new ContextImpl(rootContext); }
@Before public void setup() { ContextImpl context = new ContextImpl(); context.put(ModuleManager.class, moduleManager); context.put(NetworkSystem.class, mock(NetworkSystem.class)); context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus()); CoreRegistry.setContext(context); EntitySystemSetupUtil.addReflectionBasedLibraries(context); EntitySystemSetupUtil.addEntityManagementRelatedClasses(context); entityManager = context.get(EngineEntityManager.class); }
@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); extraDataManager = new ExtraBlockDataManager(); Mockito.when(blockManager.getBlock(Matchers.<BlockUri>any())).thenReturn(air); Mockito.when(blockManager.getBlock(Matchers.<String>any())).thenReturn(air); context.put(BlockManager.class, blockManager); }
@Before public void setup() throws Exception { ContextImpl context = new ContextImpl(); CoreRegistry.setContext(context); ModuleManager moduleManager = ModuleManagerFactory.create(); ReflectFactory reflectFactory = new ReflectionReflectFactory(); CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory); TypeSerializationLibrary lib = new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary); lib.add(Vector3f.class, new Vector3fTypeHandler()); lib.add(Quat4f.class, new Quat4fTypeHandler()); entitySystemLibrary = new EntitySystemLibrary(context, lib); componentLibrary = entitySystemLibrary.getComponentLibrary(); ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager(); assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs"); assetTypeManager.switchEnvironment(moduleManager.getEnvironment()); context.put(AssetManager.class, assetTypeManager.getAssetManager()); prefabManager = new PojoPrefabManager(context); }
@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())); }
@Before public void setup() throws Exception { ContextImpl context = new ContextImpl(); context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus()); CoreRegistry.setContext(context); ModuleManager moduleManager = ModuleManagerFactory.create(); context.put(ModuleManager.class, moduleManager); EntitySystemSetupUtil.addReflectionBasedLibraries(context); ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager(); assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs"); ComponentLibrary componentLibrary = context.get(ComponentLibrary.class); TypeSerializationLibrary typeSerializationLibrary = context.get(TypeSerializationLibrary.class); PrefabFormat prefabFormat = new PrefabFormat(componentLibrary, typeSerializationLibrary); assetTypeManager.registerCoreFormat(Prefab.class, prefabFormat); assetTypeManager.switchEnvironment(moduleManager.getEnvironment()); context.put(AssetManager.class, assetTypeManager.getAssetManager()); NetworkSystem networkSystem = mock(NetworkSystem.class); when(networkSystem.getMode()).thenReturn(NetworkMode.NONE); context.put(NetworkSystem.class, networkSystem); EntitySystemSetupUtil.addEntityManagementRelatedClasses(context); prefabManager = new PojoPrefabManager(context); }
this.rootContext = new ContextImpl(); rootContext.put(GameEngine.class, this); this.timeSubsystem = timeSubsystem;
@Before public void prepare() { context = new ContextImpl(); context.put(ReflectFactory.class, reflectFactory); context.put(CopyStrategyLibrary.class, copyStrategies); }
@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); }
@Before 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)); }
@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())); }
@Before 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()); }
ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules()); if (result.isSuccess()) { subContext = new ContextImpl(context); CoreRegistry.setContext(subContext); environment = moduleManager.loadEnvironment(result.getModules(), false);
@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)); }
@BeforeClass public static void setUpClass() throws Exception { Config config = new Config(new MockContext()); CoreRegistry.setContext(new ContextImpl()); CoreRegistry.put(Config.class, config); }
@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<>(); }
@Before public void setUp() { bindsSubsystem = new BindsSubsystem(); bindsConfiguration = new BindsConfigAdapter(new BindsConfig()); context = new ContextImpl(); context.put(BindsConfiguration.class, bindsConfiguration); bindsSubsystem.preInitialise(context); setUpMockModuleEnvironment(); }
@Before public void setup() { ContextImpl context = new ContextImpl(); CoreRegistry.setContext(context); ReflectFactory reflectFactory = new ReflectionReflectFactory(); CopyStrategyLibrary copyStrategies = new CopyStrategyLibrary(reflectFactory); TypeSerializationLibrary serializationLibrary = new TypeSerializationLibrary(reflectFactory, copyStrategies); EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, serializationLibrary); compLibrary = entitySystemLibrary.getComponentLibrary(); entityManager = new PojoEntityManager(); entityManager.setComponentLibrary(entitySystemLibrary.getComponentLibrary()); entityManager.setPrefabManager(new PojoPrefabManager(context)); NetworkSystem networkSystem = mock(NetworkSystem.class); when(networkSystem.getMode()).thenReturn(NetworkMode.NONE); EventCatcher eventCatcher = new EventCatcher(null, null); RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = new RecordAndReplayCurrentStatus(); eventSystem = new EventSystemImpl(entitySystemLibrary.getEventLibrary(), networkSystem, eventCatcher, recordAndReplayCurrentStatus); entityManager.setEventSystem(eventSystem); entity = entityManager.create(); }
protected void reset(Set<Name> moduleNames) throws Exception { this.context = new ContextImpl(); RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = new RecordAndReplayCurrentStatus(); context.put(RecordAndReplayCurrentStatus.class, recordAndReplayCurrentStatus); CoreRegistry.setContext(context); setupPathManager(); setupConfig(); setupModuleManager(moduleNames); setupDisplay(); setupAudio(); AssetManager assetManager = setupAssetManager(); setupBlockManager(assetManager); setupExtraDataManager(context); setupCollisionManager(); setupNetwork(); setupEntitySystem(); setupStorageManager(); setupComponentManager(); setupWorldProvider(); setupCelestialSystem(); loadPrefabs(); }
@BeforeClass public static void setupClass() throws Exception { context = new ContextImpl(); CoreRegistry.setContext(context); context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus()); moduleManager = ModuleManagerFactory.create(); context.put(ModuleManager.class, moduleManager); ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager(); assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs"); assetTypeManager.switchEnvironment(moduleManager.getEnvironment()); context.put(AssetManager.class, assetTypeManager.getAssetManager()); }