Skip to content

Instantly share code, notes, and snippets.

@DaanVanYperen
Created May 16, 2019 19:53
Show Gist options
  • Save DaanVanYperen/507888e83d9b1ff9d35810f671595360 to your computer and use it in GitHub Desktop.
Save DaanVanYperen/507888e83d9b1ff9d35810f671595360 to your computer and use it in GitHub Desktop.
public class ExampleTest {
public static class PetOwner extends Component {
public PetOwner() {}
@LinkPolicy(LinkPolicy.Policy.CHECK_SOURCE_AND_TARGETS)
@EntityId public IntBag pets =new IntBag();
}
Entity junkdog;
Entity yak;
@Test
public void When_monitored_intbag_Should_detach_deleted_entities() {
class System1 extends BaseSystem {
@Override
protected void processSystem() {
junkdog = world.createEntity();
yak = world.createEntity();
PetOwner junkdogPetOwner = junkdog.edit().create(PetOwner.class);
junkdogPetOwner.pets.add(yak.getId());
}
}
class System2 extends BaseSystem {
@Override
protected void processSystem() {
world.deleteEntity(yak);
}
}
class System3 extends BaseSystem {
@Override
protected void processSystem() {
Assertions.assertEquals(0, junkdog.getComponent(PetOwner.class).pets.size());
}
}
new World(new WorldConfigurationBuilder()
.with(new EntityLinkManager(), new System1(), new System2(), new System3()).build()).process();
}
public static class Pet extends Component {
public Pet() {}
@EntityId public int id=-1;
}
@Test
public void When_monitored_int_Should_detach_deleted_entities() {
class System1 extends BaseSystem {
@Override
protected void processSystem() {
junkdog = world.createEntity();
yak = world.createEntity();
Pet pet = yak.edit().create(Pet.class);
pet.id = junkdog.getId();
}
}
class System2 extends BaseSystem {
@Override
protected void processSystem() {
world.deleteEntity(junkdog);
}
}
class System3 extends BaseSystem {
@Override
protected void processSystem() {
Assertions.assertEquals(-1, yak.getComponent(Pet.class).id);
}
}
new World(new WorldConfigurationBuilder()
.with(new EntityLinkManager(), new System1(), new System2(), new System3()).build()).process();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment