### Question:
SitePreferenceWebArgumentResolver implements WebArgumentResolver { public Object resolveArgument(MethodParameter param, NativeWebRequest request) throws Exception { if (SitePreference.class.isAssignableFrom(param.getParameterType())) { return SitePreferenceUtils.getCurrentSitePreference(request); } else { return WebArgumentResolver.UNRESOLVED; } }  Object resolveArgument(MethodParameter param, NativeWebRequest request);  }### Answer:
@Test public void resolveNormal() throws Exception { request.setAttribute(SitePreferenceHandler.CURRENT_SITE_PREFERENCE_ATTRIBUTE, SitePreference.NORMAL, WebRequest.SCOPE_REQUEST); MethodParameter parameter = new MethodParameter(getClass().getMethod("handlerMethod", SitePreference.class), 0); Object resolved = resolver.resolveArgument(parameter, request); assertEquals(SitePreference.NORMAL, resolved); }
@Test public void resolveMobile() throws Exception { request.setAttribute(SitePreferenceHandler.CURRENT_SITE_PREFERENCE_ATTRIBUTE, SitePreference.MOBILE, WebRequest.SCOPE_REQUEST); MethodParameter parameter = new MethodParameter(getClass().getMethod("handlerMethod", SitePreference.class), 0); Object resolved = resolver.resolveArgument(parameter, request); assertEquals(SitePreference.MOBILE, resolved); }
@Test public void resolveTablet() throws Exception { request.setAttribute(SitePreferenceHandler.CURRENT_SITE_PREFERENCE_ATTRIBUTE, SitePreference.TABLET, WebRequest.SCOPE_REQUEST); MethodParameter parameter = new MethodParameter(getClass().getMethod("handlerMethod", SitePreference.class), 0); Object resolved = resolver.resolveArgument(parameter, request); assertEquals(SitePreference.TABLET, resolved); }
@Test public void unresolvedNormal() throws Exception { request.setAttribute(SitePreferenceHandler.CURRENT_SITE_PREFERENCE_ATTRIBUTE, SitePreference.NORMAL, WebRequest.SCOPE_REQUEST); MethodParameter parameter = new MethodParameter(getClass().getMethod("handlerMethodUnresolved", String.class), 0); Object resolved = resolver.resolveArgument(parameter, request); assertSame(WebArgumentResolver.UNRESOLVED, resolved); }
@Test public void unresolvedMobile() throws Exception { request.setAttribute(SitePreferenceHandler.CURRENT_SITE_PREFERENCE_ATTRIBUTE, SitePreference.MOBILE, WebRequest.SCOPE_REQUEST); MethodParameter parameter = new MethodParameter(getClass().getMethod("handlerMethodUnresolved", String.class), 0); Object resolved = resolver.resolveArgument(parameter, request); assertSame(WebArgumentResolver.UNRESOLVED, resolved); }
@Test public void unresolvedTablet() throws Exception { request.setAttribute(SitePreferenceHandler.CURRENT_SITE_PREFERENCE_ATTRIBUTE, SitePreference.TABLET, WebRequest.SCOPE_REQUEST); MethodParameter parameter = new MethodParameter(getClass().getMethod("handlerMethodUnresolved", String.class), 0); Object resolved = resolver.resolveArgument(parameter, request); assertSame(WebArgumentResolver.UNRESOLVED, resolved); }