MessageProcessor implements ITask, IMessageProcessor, IManagedTask, IShutdownAwareTask { @Override public <T> T getAs(final Class<T> clazz) throws InvalidArgumentException { if (!clazz.isInstance(this)) { throw new InvalidArgumentException("Cannot represent message processor as " + clazz.getCanonicalName()); } return (T) this; } MessageProcessor(final IQueue<ITask> taskQueue, final IMessageProcessingSequence messageProcessingSequence, final IObject config); @Override void process(final IObject theMessage, final IObject theContext); @Override void pauseProcess(); @Override void continueProcess(final Throwable e); @Override void signal(final String signalName); @Override IObject getContext(); @Override IObject getResponse(); @Override IObject getMessage(); @Override IMessageProcessingSequence getSequence(); @Override IObject getEnvironment(); @Override void pushEnvironment(final IObject newEnvironment); @Override void resetEnvironment(); @Override void setConfig(final IObject config); @Override void execute(); @Override T getAs(final Class<T> clazz); @Override void notifyShuttingDown(); @Override void notifyIgnored(); @Override void setShutdownStatus(final Object status); @Override Object getShutdownStatus();  }
@Test public void Should_haveAssociatedShutdownAwareTask() throws Exception { MessageProcessor messageProcessor = new MessageProcessor(taskQueueMock, messageProcessingSequenceMock, configurationMock); IShutdownAwareTask shutdownAwareTask = messageProcessor.getAs(IShutdownAwareTask.class); assertNotNull(shutdownAwareTask); }
@Test(expected = InvalidArgumentException.class) public void Should_throwWhenAssociatedObjectOfUnknownClassRequired() throws Exception { new MessageProcessor(taskQueueMock, messageProcessingSequenceMock, configurationMock).getAs(IObject.class); }