@Override public Context createChildContext() { return new ContextImpl(rootContext); }
@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 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)); }
@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); }
@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()); }
@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() { 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() { 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(); }
@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()); }
@BeforeClass public static void setupClass() throws Exception { context = new ContextImpl(); ModuleManager 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()); context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus()); CoreRegistry.setContext(context); }
@BeforeClass public static void setupClass() throws Exception { context = new ContextImpl(); ModuleManager 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()); context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus()); CoreRegistry.setContext(context); }
@BeforeClass public static void setupClass() throws Exception { context = new ContextImpl(); ModuleManager 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()); context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus()); CoreRegistry.setContext(context); }
@Before public void setup() { context = new ContextImpl(); context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus()); 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); }
@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 testRegionPositions() { CoreRegistry.setContext(new ContextImpl()); CoreRegistry.put(Config.class, new Config(new MockContext())); assertEquals(1, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(0, 0, 0))).length); assertEquals(1, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(31, 63, 31))).length); assertEquals(2, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 63, 31))).length); assertEquals(4, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 63, 32))).length); assertEquals(8, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 64, 32))).length); assertEquals(12, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(-1, 0, 0), new Vector3i(32, 64, 32))).length); Vector3i[] chunks = ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 63, 31))); assertEquals(new Vector3i(0, 0, 0), chunks[0]); assertEquals(new Vector3i(1, 0, 0), chunks[1]); } }