Example usage for org.springframework.messaging.handler.annotation.support MethodArgumentNotValidException MethodArgumentNotValidException

List of usage examples for org.springframework.messaging.handler.annotation.support MethodArgumentNotValidException MethodArgumentNotValidException

Introduction

In this page you can find the example usage for org.springframework.messaging.handler.annotation.support MethodArgumentNotValidException MethodArgumentNotValidException.

Prototype

public MethodArgumentNotValidException(Message<?> message, MethodParameter parameter) 

Source Link

Document

Create a new instance with the invalid MethodParameter .

Usage

From source file:org.springframework.amqp.rabbit.listener.ErrorHandlerTests.java

@Test
public void testFatalsAreRejected() throws Exception {
    ConditionalRejectingErrorHandler handler = new ConditionalRejectingErrorHandler();
    Log logger = spy(TestUtils.getPropertyValue(handler, "logger", Log.class));
    willDoNothing().given(logger).warn(anyString(), any(Throwable.class));
    new DirectFieldAccessor(handler).setPropertyValue("logger", logger);
    handler.handleError(new ListenerExecutionFailedException("intended", new RuntimeException()));

    try {/*from   w  ww.  ja  v a 2  s .c o  m*/
        handler.handleError(
                new ListenerExecutionFailedException("intended", new MessageConversionException("")));
        fail("Expected exception");
    } catch (AmqpRejectAndDontRequeueException e) {
    }

    try {
        handler.handleError(new ListenerExecutionFailedException("intended",
                new org.springframework.messaging.converter.MessageConversionException("")));
        fail("Expected exception");
    } catch (AmqpRejectAndDontRequeueException e) {
    }

    Message<?> message = mock(Message.class);
    MethodParameter mp = new MethodParameter(Foo.class.getMethod("foo", String.class), 0);
    try {
        handler.handleError(new ListenerExecutionFailedException("intended",
                new MethodArgumentNotValidException(message, mp)));
        fail("Expected exception");
    } catch (AmqpRejectAndDontRequeueException e) {
    }

    try {
        handler.handleError(new ListenerExecutionFailedException("intended",
                new MethodArgumentTypeMismatchException(message, mp, "")));
        fail("Expected exception");
    } catch (AmqpRejectAndDontRequeueException e) {
    }
}