@Test public void testPrepareMethodParameters() { final ModelAttributeService modelAttributeService = new ModelAttributeService(); final Class[] parameterClasses = new Class[] {HttpServletRequest.class, PortalRequest.class, Bearer.class}; final Method method; try { method = getClass().getMethod("soffitModelAttributeMethod", parameterClasses); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } final HttpServletRequest req = Mockito.mock(HttpServletRequest.class); final HttpServletResponse res = Mockito.mock(HttpServletResponse.class); final PortalRequest portalRequest = Mockito.mock(PortalRequest.class); final Bearer bearer = Mockito.mock(Bearer.class); final Preferences preferences = Mockito.mock(Preferences.class); final Definition definition = Mockito.mock(Definition.class); final Object[] parameters = modelAttributeService.prepareMethodParameters( method, req, res, portalRequest, bearer, preferences, definition); assertEquals( "parameterClasses and parameters arrays must be the same length", parameterClasses.length, parameters.length); for (int i = 0; i < parameters.length; i++) { assertTrue("Mismatched parameter type", parameterClasses[i].isInstance(parameters[i])); } }
protected Object[] prepareMethodParameters( Method method, HttpServletRequest req, HttpServletResponse res, PortalRequest portalRequest, Bearer bearer, Preferences preferences, Definition definition) { final Class<?>[] parameterTypes = method.getParameterTypes(); final Object[] rslt = new Object[parameterTypes.length]; for (int i = 0; i < rslt.length; i++) { final Class<?> pType = parameterTypes[i]; if (HttpServletRequest.class.equals(pType)) { rslt[i] = req; } else if (HttpServletResponse.class.equals(pType)) { rslt[i] = res; } else if (PortalRequest.class.equals(pType)) { rslt[i] = portalRequest; } else if (Bearer.class.equals(pType)) { rslt[i] = bearer; } else if (Preferences.class.equals(pType)) { rslt[i] = preferences; } else if (Definition.class.equals(pType)) { rslt[i] = definition; } else { final String msg = "Unsupported parameter type for SoffitModelAttribute method: " + pType; throw new UnsupportedOperationException(msg); } } return rslt; }
ModelAttributeService { protected Object[] prepareMethodParameters( Method method, HttpServletRequest req, HttpServletResponse res, PortalRequest portalRequest, Bearer bearer, Preferences preferences, Definition definition) { final Class<?>[] parameterTypes = method.getParameterTypes(); final Object[] rslt = new Object[parameterTypes.length]; for (int i = 0; i < rslt.length; i++) { final Class<?> pType = parameterTypes[i]; if (HttpServletRequest.class.equals(pType)) { rslt[i] = req; } else if (HttpServletResponse.class.equals(pType)) { rslt[i] = res; } else if (PortalRequest.class.equals(pType)) { rslt[i] = portalRequest; } else if (Bearer.class.equals(pType)) { rslt[i] = bearer; } else if (Preferences.class.equals(pType)) { rslt[i] = preferences; } else if (Definition.class.equals(pType)) { rslt[i] = definition; } else { final String msg = "Unsupported parameter type for SoffitModelAttribute method: " + pType; throw new UnsupportedOperationException(msg); } } return rslt; } }
ModelAttributeService { protected Object[] prepareMethodParameters( Method method, HttpServletRequest req, HttpServletResponse res, PortalRequest portalRequest, Bearer bearer, Preferences preferences, Definition definition) { final Class<?>[] parameterTypes = method.getParameterTypes(); final Object[] rslt = new Object[parameterTypes.length]; for (int i = 0; i < rslt.length; i++) { final Class<?> pType = parameterTypes[i]; if (HttpServletRequest.class.equals(pType)) { rslt[i] = req; } else if (HttpServletResponse.class.equals(pType)) { rslt[i] = res; } else if (PortalRequest.class.equals(pType)) { rslt[i] = portalRequest; } else if (Bearer.class.equals(pType)) { rslt[i] = bearer; } else if (Preferences.class.equals(pType)) { rslt[i] = preferences; } else if (Definition.class.equals(pType)) { rslt[i] = definition; } else { final String msg = "Unsupported parameter type for SoffitModelAttribute method: " + pType; throw new UnsupportedOperationException(msg); } } return rslt; }  }
ModelAttributeService { protected Object[] prepareMethodParameters( Method method, HttpServletRequest req, HttpServletResponse res, PortalRequest portalRequest, Bearer bearer, Preferences preferences, Definition definition) { final Class<?>[] parameterTypes = method.getParameterTypes(); final Object[] rslt = new Object[parameterTypes.length]; for (int i = 0; i < rslt.length; i++) { final Class<?> pType = parameterTypes[i]; if (HttpServletRequest.class.equals(pType)) { rslt[i] = req; } else if (HttpServletResponse.class.equals(pType)) { rslt[i] = res; } else if (PortalRequest.class.equals(pType)) { rslt[i] = portalRequest; } else if (Bearer.class.equals(pType)) { rslt[i] = bearer; } else if (Preferences.class.equals(pType)) { rslt[i] = preferences; } else if (Definition.class.equals(pType)) { rslt[i] = definition; } else { final String msg = "Unsupported parameter type for SoffitModelAttribute method: " + pType; throw new UnsupportedOperationException(msg); } } return rslt; }  @PostConstruct void init(); }
ModelAttributeService { protected Object[] prepareMethodParameters( Method method, HttpServletRequest req, HttpServletResponse res, PortalRequest portalRequest, Bearer bearer, Preferences preferences, Definition definition) { final Class<?>[] parameterTypes = method.getParameterTypes(); final Object[] rslt = new Object[parameterTypes.length]; for (int i = 0; i < rslt.length; i++) { final Class<?> pType = parameterTypes[i]; if (HttpServletRequest.class.equals(pType)) { rslt[i] = req; } else if (HttpServletResponse.class.equals(pType)) { rslt[i] = res; } else if (PortalRequest.class.equals(pType)) { rslt[i] = portalRequest; } else if (Bearer.class.equals(pType)) { rslt[i] = bearer; } else if (Preferences.class.equals(pType)) { rslt[i] = preferences; } else if (Definition.class.equals(pType)) { rslt[i] = definition; } else { final String msg = "Unsupported parameter type for SoffitModelAttribute method: " + pType; throw new UnsupportedOperationException(msg); } } return rslt; }  @PostConstruct void init();  }