/** * Cleans up all resources (similar to AutoCloseable) * * @throws Exception if something goes wrong */ public void close() throws Exception { CoreRegistry.setContext(null); context = null; }
/** * Create a Context implementation instance an assign it to CoreRegistry before testing. */ @Before public void setup() { context = new ContextImplementation(); CoreRegistry.setContext(context); }
@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); }
/** * Check if the context is changed with setContext method. */ @Test public void testContextChange() { CoreRegistry.setContext(new ContextImplementation()); assertNotEquals(CoreRegistry.get(Context.class), context); }
private void resetEnvironment() { CoreRegistry.setContext(context); if (environment != null) { EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class); environmentSwitchHandler.handleSwitchBackFromPreviewEnvironment(subContext); environment.close(); environment = null; } previewGen.close(); WorldConfigurator worldConfig = worldGenerator.getConfigurator(); Map<String, Component> params = worldConfig.getProperties(); if (params != null) { config.setModuleConfigs(worldGenerator.getUri(), params); } }
@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()); }
/** * Check if CoreRegistry returns null on its methods when the context is not defined. */ @Test public void testNullReturnOnMissingContext() { CoreRegistry.setContext(null); assertEquals(CoreRegistry.put(Integer.class, 10), null); assertEquals(CoreRegistry.get(Integer.class), null); }
@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); }
/** * Check if the CoreRegistry is calling the methods of its Context */ @Test public void testContextMethodsCalled() { // Load value in context Integer value = 10; CoreRegistry.put(Integer.class, value); assertEquals(value, context.get(Integer.class)); assertEquals(context.get(Integer.class), CoreRegistry.get(Integer.class)); // Change context CoreRegistry.setContext(new ContextImplementation()); assertNotEquals(CoreRegistry.get(Context.class), context); assertEquals(CoreRegistry.get(Integer.class), null); // Restore first context CoreRegistry.setContext(context); assertEquals(CoreRegistry.get(Integer.class), value); }
@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()); }
@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() 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); }
@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]); } }