@Test
  public void allComponentsNotMarkedAsRetainedRemovedOnBlockChange() {
    worldStub.setBlock(Vector3i.zero(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0));
    entity.addComponent(new ForceBlockActiveComponent());
    entity.addComponent(new RetainedOnBlockChangeComponent(2));

    worldProvider.setBlock(Vector3i.zero(), BlockManager.getAir());

    assertTrue(entity.hasComponent(RetainedOnBlockChangeComponent.class));
    assertFalse(entity.hasComponent(ForceBlockActiveComponent.class));
  }
  @Test
  public void testChangedComponentsRevertedBeforeCleanUp() {
    worldStub.setBlock(Vector3i.zero(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0));
    StringComponent comp = entity.getComponent(StringComponent.class);
    comp.value = "Moo";
    entity.saveComponent(comp);

    LifecycleEventChecker checker =
        new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);

    worldProvider.update(1.0f);
    assertEquals(
        Lists.newArrayList(new EventInfo(OnChangedComponent.newInstance(), entity)),
        checker.receivedEvents);
  }
  @Test
  public void testEntityExtraComponentsRemovedBeforeCleanUpForBlocksWithPrefabs() {
    worldStub.setBlock(Vector3i.zero(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0));
    entity.addComponent(new IntegerComponent(1));

    LifecycleEventChecker checker =
        new LifecycleEventChecker(entityManager.getEventSystem(), IntegerComponent.class);

    worldProvider.update(1.0f);
    assertEquals(
        Lists.newArrayList(
            new EventInfo(BeforeDeactivateComponent.newInstance(), entity),
            new EventInfo(BeforeRemoveComponent.newInstance(), entity)),
        checker.receivedEvents);
  }
  @Test
  public void testEntityMissingComponentsAddedBeforeCleanUp() {
    worldStub.setBlock(Vector3i.zero(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0));
    entity.removeComponent(StringComponent.class);

    LifecycleEventChecker checker =
        new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);

    worldProvider.update(1.0f);
    assertEquals(
        Lists.newArrayList(
            new EventInfo(OnAddedComponent.newInstance(), entity),
            new EventInfo(OnActivatedComponent.newInstance(), entity)),
        checker.receivedEvents);
  }
  @Test
  public void testActiveBlockNotCleanedUp() {
    Block testBlock = new Block();
    testBlock.setKeepActive(true);
    BlockFamily blockFamily = new SymmetricFamily(new BlockUri("test:keepActive"), testBlock);
    blockManager.addBlockFamily(blockFamily, true);
    worldStub.setBlock(Vector3i.zero(), testBlock);

    BlockEventChecker checker = new BlockEventChecker();
    entityManager.getEventSystem().registerEventHandler(checker);

    EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0));
    worldProvider.update(1.0f);
    assertTrue(blockEntity.exists());
    assertTrue(blockEntity.isActive());
    assertTrue(checker.addedReceived);
    assertTrue(checker.activateReceived);
  }