code: public static boolean isExpectedException(final Class<? extends Exception> expectedClass,
              final String expectedMessage, final Exception ex) {
          if (!isExpectedType(expectedClass, ex)) {
              return false;
          }
          if ((expectedClass != null) && (expectedMessage != null) && (ex != null)) {
              return Objects.equals(expectedMessage, ex.getMessage());
          }
          return true;
      }
docs: Determines if an exception has an expected type and message in a null-safe way.
  
  @param expectedClass
  Expected exception type.
  @param expectedMessage
  Expected message.
  @param ex
  Exception to test.
  
  @return TRUE if the object is exactly of the same class and has the same message, else FALSE.