@Test public void testGetModelAttributeFromMethod() { 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 modelAttribute = modelAttributeService.getModelAttributeFromMethod( this, method, req, res, portalRequest, bearer, preferences, definition); assertEquals("Incorrect modelAttribute", modelAttribute, returnValue); final Method brokenMethod; try { brokenMethod = getClass().getMethod("brokenSoffitModelAttributeMethod", parameterClasses); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } try { modelAttributeService.getModelAttributeFromMethod( this, brokenMethod, req, res, portalRequest, bearer, preferences, definition); fail("Expected IllegalStateException for void-declaring method"); } catch (IllegalStateException e) { } }
protected Object getModelAttributeFromMethod( Object bean, Method method, HttpServletRequest req, HttpServletResponse res, PortalRequest portalRequest, Bearer bearer, Preferences preferences, Definition definition) { if (method.getReturnType().equals(Void.TYPE)) { final String msg = "Methods annotated with SoffitModelAttribute must not specify a void return type; " + method.getName(); throw new IllegalStateException(msg); } final Object[] parameters = prepareMethodParameters( method, req, res, portalRequest, bearer, preferences, definition); try { final Object rslt = method.invoke(bean, parameters); return rslt; } catch (IllegalAccessException | InvocationTargetException e) { final String msg = "Failed to generate a model attribute by invoking '" + method.getName() + "' on the following bean: " + bean.toString(); throw new RuntimeException(msg); } }
ModelAttributeService { protected Object getModelAttributeFromMethod( Object bean, Method method, HttpServletRequest req, HttpServletResponse res, PortalRequest portalRequest, Bearer bearer, Preferences preferences, Definition definition) { if (method.getReturnType().equals(Void.TYPE)) { final String msg = "Methods annotated with SoffitModelAttribute must not specify a void return type; " + method.getName(); throw new IllegalStateException(msg); } final Object[] parameters = prepareMethodParameters( method, req, res, portalRequest, bearer, preferences, definition); try { final Object rslt = method.invoke(bean, parameters); return rslt; } catch (IllegalAccessException | InvocationTargetException e) { final String msg = "Failed to generate a model attribute by invoking '" + method.getName() + "' on the following bean: " + bean.toString(); throw new RuntimeException(msg); } } }
ModelAttributeService { protected Object getModelAttributeFromMethod( Object bean, Method method, HttpServletRequest req, HttpServletResponse res, PortalRequest portalRequest, Bearer bearer, Preferences preferences, Definition definition) { if (method.getReturnType().equals(Void.TYPE)) { final String msg = "Methods annotated with SoffitModelAttribute must not specify a void return type; " + method.getName(); throw new IllegalStateException(msg); } final Object[] parameters = prepareMethodParameters( method, req, res, portalRequest, bearer, preferences, definition); try { final Object rslt = method.invoke(bean, parameters); return rslt; } catch (IllegalAccessException | InvocationTargetException e) { final String msg = "Failed to generate a model attribute by invoking '" + method.getName() + "' on the following bean: " + bean.toString(); throw new RuntimeException(msg); } }  }
ModelAttributeService { protected Object getModelAttributeFromMethod( Object bean, Method method, HttpServletRequest req, HttpServletResponse res, PortalRequest portalRequest, Bearer bearer, Preferences preferences, Definition definition) { if (method.getReturnType().equals(Void.TYPE)) { final String msg = "Methods annotated with SoffitModelAttribute must not specify a void return type; " + method.getName(); throw new IllegalStateException(msg); } final Object[] parameters = prepareMethodParameters( method, req, res, portalRequest, bearer, preferences, definition); try { final Object rslt = method.invoke(bean, parameters); return rslt; } catch (IllegalAccessException | InvocationTargetException e) { final String msg = "Failed to generate a model attribute by invoking '" + method.getName() + "' on the following bean: " + bean.toString(); throw new RuntimeException(msg); } }  @PostConstruct void init(); }
ModelAttributeService { protected Object getModelAttributeFromMethod( Object bean, Method method, HttpServletRequest req, HttpServletResponse res, PortalRequest portalRequest, Bearer bearer, Preferences preferences, Definition definition) { if (method.getReturnType().equals(Void.TYPE)) { final String msg = "Methods annotated with SoffitModelAttribute must not specify a void return type; " + method.getName(); throw new IllegalStateException(msg); } final Object[] parameters = prepareMethodParameters( method, req, res, portalRequest, bearer, preferences, definition); try { final Object rslt = method.invoke(bean, parameters); return rslt; } catch (IllegalAccessException | InvocationTargetException e) { final String msg = "Failed to generate a model attribute by invoking '" + method.getName() + "' on the following bean: " + bean.toString(); throw new RuntimeException(msg); } }  @PostConstruct void init();  }