I am creating a test platform for a protocol project based on Apache MINA. In MINA, when you receive packets, the method messageReceived()receives an object. Ideally, I would like to use the JUnit method assertClass(), however it does not exist. I play around trying to figure out what is the closest I can get. I'm trying to find something similar to instanceof.
I currently have:
public void assertClass(String msg, Class expected, Object given) {
if(!expected.isInstance(given)) Assert.fail(msg);
}
To trigger this:
assertClass("Packet type is correct", SomePacket.class, receivedPacket);
This works without problems, however, experimenting and playing with it, my interest was reached by the peak of the operator instanceof.
if (receivedPacket instanceof SomePacket) { .. }
SomePacket ? , , ?! , SomePacket , assertClass(), SomePacket.class, SomePacket?