@Override
 public UriComponents linkToMethod(Method method, Object... argumentValues) {
   String mapping = MvcUrlUtils.getMethodMapping(method);
   UriComponentsBuilder builder =
       ServletUriComponentsBuilder.fromCurrentServletMapping().path(mapping);
   Map<String, Object> uriVars = new HashMap<String, Object>();
   return applyContributers(builder, method, argumentValues, uriVars);
 }
  @Override
  public UriComponents linkToMethodOn(Object mockController) {

    Assert.isInstanceOf(ControllerMethodValues.class, mockController);
    ControllerMethodValues controllerMethodValues = (ControllerMethodValues) mockController;

    Method method = controllerMethodValues.getControllerMethod();
    Object[] argumentValues = controllerMethodValues.getArgumentValues();

    Map<String, Object> uriVars = new HashMap<String, Object>();
    addTypeLevelUriVaris(controllerMethodValues, uriVars);

    String mapping = MvcUrlUtils.getMethodMapping(method);
    UriComponentsBuilder builder =
        ServletUriComponentsBuilder.fromCurrentServletMapping().path(mapping);

    return applyContributers(builder, method, argumentValues, uriVars);
  }
  private void addTypeLevelUriVaris(ControllerMethodValues info, Map<String, Object> uriVariables) {

    Object[] values = info.getTypeLevelUriVariables();
    if (!ObjectUtils.isEmpty(values)) {

      String mapping =
          MvcUrlUtils.getTypeLevelMapping(info.getControllerMethod().getDeclaringClass());

      List<String> names = new UriTemplate(mapping).getVariableNames();
      Assert.isTrue(
          names.size() == values.length,
          "The provided type-level URI template variables "
              + Arrays.toString(values)
              + " do not match the template "
              + mapping);

      for (int i = 0; i < names.size(); i++) {
        uriVariables.put(names.get(i), values[i]);
      }
    }
  }
 @Override
 public UriComponentsBuilder linkToController(Class<?> controllerClass) {
   String mapping = MvcUrlUtils.getTypeLevelMapping(controllerClass);
   return ServletUriComponentsBuilder.fromCurrentServletMapping().path(mapping);
 }