@Test void testConstructor() { Object payload = new Object(); CommandMessage<Object> message1 = asCommandMessage(payload); Map<String, Object> metaDataMap = Collections.singletonMap("key", "value"); MetaData metaData = MetaData.from(metaDataMap); GenericCommandMessage<Object> message2 = new GenericCommandMessage<>(payload, metaData); GenericCommandMessage<Object> message3 = new GenericCommandMessage<>(payload, metaDataMap); assertSame(MetaData.emptyInstance(), message1.getMetaData()); assertEquals(Object.class, message1.getPayload().getClass()); assertEquals(Object.class, message1.getPayloadType()); assertSame(metaData, message2.getMetaData()); assertEquals(Object.class, message2.getPayload().getClass()); assertEquals(Object.class, message2.getPayloadType()); assertNotSame(metaDataMap, message3.getMetaData()); assertEquals(metaDataMap, message3.getMetaData()); assertEquals(Object.class, message3.getPayload().getClass()); assertEquals(Object.class, message3.getPayloadType()); assertNotEquals(message1.getIdentifier(), message2.getIdentifier()); assertNotEquals(message1.getIdentifier(), message3.getIdentifier()); assertNotEquals(message2.getIdentifier(), message3.getIdentifier()); }
@SuppressWarnings("unchecked") public static <C> CommandMessage<C> asCommandMessage(Object command) { if (CommandMessage.class.isInstance(command)) { return (CommandMessage<C>) command; } return new GenericCommandMessage<>((C) command, MetaData.emptyInstance()); }
GenericCommandMessage extends MessageDecorator<T> implements CommandMessage<T> { @SuppressWarnings("unchecked") public static <C> CommandMessage<C> asCommandMessage(Object command) { if (CommandMessage.class.isInstance(command)) { return (CommandMessage<C>) command; } return new GenericCommandMessage<>((C) command, MetaData.emptyInstance()); } }
GenericCommandMessage extends MessageDecorator<T> implements CommandMessage<T> { @SuppressWarnings("unchecked") public static <C> CommandMessage<C> asCommandMessage(Object command) { if (CommandMessage.class.isInstance(command)) { return (CommandMessage<C>) command; } return new GenericCommandMessage<>((C) command, MetaData.emptyInstance()); } GenericCommandMessage(T payload);  GenericCommandMessage(T payload, Map<String, ?> metaData);  GenericCommandMessage(Message<T> delegate, String commandName); }
GenericCommandMessage extends MessageDecorator<T> implements CommandMessage<T> { @SuppressWarnings("unchecked") public static <C> CommandMessage<C> asCommandMessage(Object command) { if (CommandMessage.class.isInstance(command)) { return (CommandMessage<C>) command; } return new GenericCommandMessage<>((C) command, MetaData.emptyInstance()); } GenericCommandMessage(T payload);  GenericCommandMessage(T payload, Map<String, ?> metaData);  GenericCommandMessage(Message<T> delegate, String commandName); @SuppressWarnings("unchecked") static CommandMessage<C> asCommandMessage(Object command); @Override String getCommandName(); @Override GenericCommandMessage<T> withMetaData(Map<String, ?> metaData); @Override GenericCommandMessage<T> andMetaData(Map<String, ?> metaData); }
GenericCommandMessage extends MessageDecorator<T> implements CommandMessage<T> { @SuppressWarnings("unchecked") public static <C> CommandMessage<C> asCommandMessage(Object command) { if (CommandMessage.class.isInstance(command)) { return (CommandMessage<C>) command; } return new GenericCommandMessage<>((C) command, MetaData.emptyInstance()); } GenericCommandMessage(T payload);  GenericCommandMessage(T payload, Map<String, ?> metaData);  GenericCommandMessage(Message<T> delegate, String commandName); @SuppressWarnings("unchecked") static CommandMessage<C> asCommandMessage(Object command); @Override String getCommandName(); @Override GenericCommandMessage<T> withMetaData(Map<String, ?> metaData); @Override GenericCommandMessage<T> andMetaData(Map<String, ?> metaData);  }