Class HandlerResultAssert

java.lang.Object
org.assertj.core.api.AbstractAssert<SELF,ACTUAL>
org.assertj.core.api.AbstractObjectAssert<HandlerResultAssert,Object>
org.springframework.test.web.servlet.assertj.HandlerResultAssert
All Implemented Interfaces:
org.assertj.core.api.Assert<HandlerResultAssert,Object>, org.assertj.core.api.Descriptable<HandlerResultAssert>, org.assertj.core.api.ExtensionPoints<HandlerResultAssert,Object>

public class HandlerResultAssert extends org.assertj.core.api.AbstractObjectAssert<HandlerResultAssert,Object>
AssertJ assertions that can be applied to a handler or handler method.
Since:
6.2
Author:
Stephane Nicoll
  • Field Summary

    Fields inherited from class org.assertj.core.api.AbstractAssert

    actual, info, myself, objects, throwUnsupportedExceptionOnEquals
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    hasType(Class<?> type)
    Verify that the handler is of the given type.
    isInvokedOn(Class<T> controllerType, Function<T,Object> handlerMethod)
    Verify that the handler is managed by the given handlerMethod.
    Verify that the handler is managed by a method invocation, typically on a controller.
    Return a new assertion object that uses the Method that handles the request as the object to test.

    Methods inherited from class org.assertj.core.api.AbstractObjectAssert

    as, as, doesNotReturn, extracting, extracting, extracting, extracting, extracting, extracting, extractingForProxy, getComparatorsByType, hasAllNullFieldsOrProperties, hasAllNullFieldsOrPropertiesExcept, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, hasOnlyFields, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, newObjectAssert, returns, usingComparatorForFields, usingComparatorForType, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison

    Methods inherited from class org.assertj.core.api.AbstractAssert

    areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.assertj.core.api.Descriptable

    as, describedAs, describedAs
  • Constructor Details

    • HandlerResultAssert

      public HandlerResultAssert(@Nullable Object actual)
  • Method Details

    • method

      public MethodAssert method()
      Return a new assertion object that uses the Method that handles the request as the object to test.

      Verifies first that the handler is a method handler.

      Example:

      
       // Check that a GET to "/greet" is invoked on a "handleGreet" method name
       assertThat(mvc.perform(get("/greet")).handler().method().hasName("handleGreet");
       
    • isMethodHandler

      public HandlerResultAssert isMethodHandler()
      Verify that the handler is managed by a method invocation, typically on a controller.
    • isInvokedOn

      public <T> HandlerResultAssert isInvokedOn(Class<T> controllerType, Function<T,Object> handlerMethod)
      Verify that the handler is managed by the given handlerMethod.

      This creates a "mock" for the given controllerType and records the method invocation in the handlerMethod. The arguments used by the target method invocation can be null as the purpose of the mock is to identify the method that was invoked.

      Example:

      
       // If the method has a return type, you can return the result of the invocation
       assertThat(mvc.perform(get("/greet")).handler().isInvokedOn(
               GreetController.class, controller -> controller.sayGreet());
      
       // If the method has a void return type, the controller should be returned
       assertThat(mvc.perform(post("/persons/")).handler().isInvokedOn(
               PersonController.class, controller -> controller.createPerson(null, null));
       
      Parameters:
      controllerType - the controller to mock
      handlerMethod - the method
    • hasType

      public HandlerResultAssert hasType(Class<?> type)
      Verify that the handler is of the given type. For a controller method, this is the type of the controller.

      Example:

      
       // Check that a GET to "/greet" is managed by GreetController
       assertThat(mvc.perform(get("/greet")).handler().hasType(GreetController.class);
       
      Parameters:
      type - the expected type of the handler