IgniteMessageFactoryImpl implements IgniteMessageFactory { @Override public @Nullable Message create(short directType) { Supplier<Message> supplier = msgSuppliers[directTypeToIndex(directType)]; if (supplier == null) throw new IgniteException("Invalid message type: " + directType); return supplier.get(); } IgniteMessageFactoryImpl(MessageFactory[] factories); @Override void register(short directType, Supplier<Message> supplier); @Override @Nullable Message create(short directType); short[] registeredDirectTypes();  }
@Test public void testCreate() { MessageFactory[] factories = {new TestMessageFactoryPovider(), new TestMessageFactory()}; IgniteMessageFactoryImpl msgFactory = new IgniteMessageFactoryImpl(factories); Message msg; msg = msgFactory.create(TEST_MSG_1_TYPE); assertTrue(msg instanceof TestMessage1); msg = msgFactory.create(TEST_MSG_2_TYPE); assertTrue(msg instanceof TestMessage2); msg = msgFactory.create(TEST_MSG_42_TYPE); assertTrue(msg instanceof TestMessage42); short[] directTypes = msgFactory.registeredDirectTypes(); assertArrayEquals(directTypes, new short[] {TEST_MSG_1_TYPE, TEST_MSG_2_TYPE, TEST_MSG_42_TYPE}); }
@Test(expected = IgniteException.class) public void testCreate_UnknownMessageType() { MessageFactory[] factories = {new TestMessageFactoryPovider(), new TestMessageFactory()}; IgniteMessageFactory msgFactory = new IgniteMessageFactoryImpl(factories); msgFactory.create(UNKNOWN_MSG_TYPE); }