Testing if `Forge2DGame` has a given callback.
What could be improved
Include "something " (see Possible Solutions) that allows testing if a given Forge2DGame has registered a given ContactCallback.
Why should this be improved
To allow writing tests that ensure a given ContactCallback has been registered.
Any risks?
No
More information
Possible Solutions
- Make
_contactCallbacksinForge2DGameand_callbacksinContactCallbackspublic with@visibeForTesting - Define a method in
Forge2DGamethat allows checking if a callback is registered (hasCallback). Defining the same method forContactCallbacks. - Exposing
_callbacksfromContactCallbacksandcontactCallbacksfromForge2DGameentirely and deprecatingregister,deregisterandclearsince it can be done withadd,removeand `clear. - Exposing a getter with an
UnmodifiableListView(read-only list) in bothContactCallbacksandForge2DGame.
Please if you have other possible solutions consider joining the issue. Or even if you have a preference for one of the above also join this issue. Any contribution is helpful!
I am highly interested in working on a PR for this.
We should go over #1322 and see if that is feasible first, so that the tests aren't in vane. Are you interested in taking over #1322? What is left is basically convert the examples to the new method, update the docs and write some tests for it.
@alestiago just double checking, are you interested in taking #1322? It's of course totally fine if you are not. :slightly_smiling_face:
I might be interested @spydon, do you know why #1322 is still open? Is this only due to required doc changes, tests and feasibility?
I might be interested @spydon, do you know why #1322 is still open? Is this only due to required doc changes, tests and feasibility?
Yes, but that "only" might be pretty big. 😄 We should deprecate the other way too.
One can test a Forge2DGame has a given callback with something like:
void beginContact(Forge2DGame game, BodyComponent bodyA, BodyComponent bodyB) {
assert(
bodyA.body.fixtures.isNotEmpty && bodyB.body.fixtures.isNotEmpty,
'Bodies require fixtures to contact each other.',
);
final fixtureA = bodyA.body.fixtures.first;
final fixtureB = bodyB.body.fixtures.first;
final contact = Contact.init(fixtureA, 0, fixtureB, 0);
game.world.contactManager.contactListener?.beginContact(contact);
}
And then testing that the side effects are matched.