Message surgeonMsg2 = new Message("SurgeonMessage2");
CompositeMessagePartInstance contactPart = new CompositeMessagePartInstance(contactMsg.getName());
CompositeMessagePartInstance doctorPart = new CompositeMessagePartInstance(doctorMsg.getName());
CompositeMessagePartInstance surgeonPart1 = new CompositeMessagePartInstance(surgeonMsg1.getName());
CompositeMessagePartInstance surgeonPart2 = new CompositeMessagePartInstance(surgeonMsg2.getName());
ObjectMessagePartMapping contactMapping = new ObjectMessagePartMapping();
ObjectMessagePartMapping doctorMapping = new ObjectMessagePartMapping();
ObjectMessagePartMapping surgeonMapping1 = new ObjectMessagePartMapping();
ObjectMessagePartMapping surgeonMapping2 = new ObjectMessagePartMapping();
contactMsg.setRoot(contactPart);
doctorMsg.setRoot(doctorPart);
surgeonMsg1.setRoot(surgeonPart1);
surgeonMsg2.setRoot(surgeonPart2);
contactPart.setDeclarator(contactMsg);
doctorPart.setDeclarator(doctorMsg);
surgeonPart1.setDeclarator(surgeonMsg1);
surgeonPart2.setDeclarator(surgeonMsg2);
doctorMsg.setBaseMessage(contactMsg);
contactMsg.addDerivedMessage(doctorMsg);
surgeonMsg1.setBaseMessage(doctorMsg);
doctorMsg.addDerivedMessage(surgeonMsg1);
surgeonMsg2.setBaseMessage(doctorMsg);
doctorMsg.addDerivedMessage(surgeonMsg2);
contactPart.setMapping(contactMapping);
doctorPart.setMapping(doctorMapping);
surgeonPart1.setMapping(surgeonMapping1);
surgeonPart2.setMapping(surgeonMapping2);
contactMapping.setMetaclass(contactClass);
doctorMapping.setMetaclass(doctorClass);
surgeonMapping1.setMetaclass(surgeonClass);
surgeonMapping2.setMetaclass(surgeonClass);
contactMapping.init(contactPart);
doctorMapping.init(doctorPart);
surgeonMapping1.init(surgeonPart1);
surgeonMapping2.init(surgeonPart2);
contactMapping.finish(contactPart);
doctorMapping.finish(doctorPart);
surgeonMapping1.finish(surgeonPart1);
surgeonMapping2.finish(surgeonPart2);
assertEquals(contactMsg, contactMapping.findMessage(contactClass));
assertEquals(doctorMsg, contactMapping.findMessage(doctorClass));
assertEquals(doctorMsg, contactMapping.findMessage(surgeonClass));
assertEquals(doctorMsg, doctorMapping.findMessage(surgeonClass));
assertEquals(surgeonMsg1, surgeonMapping1.findMessage(surgeonClass));
assertEquals(surgeonMsg2, surgeonMapping2.findMessage(surgeonClass));
assertNull(doctorMapping.findMessage(contactClass));
assertNull(surgeonMapping1.findMessage(contactClass));
assertNull(surgeonMapping1.findMessage(doctorClass));
assertNull(surgeonMapping2.findMessage(contactClass));
assertNull(surgeonMapping2.findMessage(doctorClass));
assertEquals(contactMsg, ObjectMessageParser.findDerivedMessage(contactMsg, specialClass));
assertNull(ObjectMessageParser.findDerivedMessage(doctorMsg, specialClass));
assertEquals(doctorMsg, ObjectMessageParser.findDerivedMessage(contactMsg, doctorClass));