@Test public void coerce_context() { ComponentEventCallback handler = mockComponentEventHandler(); ComponentPageElementResources resources = mockComponentPageElementResources(); EventContext context = mockEventContext(); Integer value = new Integer(27); Logger logger = mockLogger(); ComponentModel model = mockComponentModel(); train_isDebugEnabled(logger, false); train_toClass(resources, "java.lang.Integer", Integer.class); train_getCount(context, 2); train_get(context, Integer.class, 0, value); replay(); ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, resources, false, model, logger); assertSame(event.coerceContext(0, "java.lang.Integer"), value); verify(); }
@SuppressWarnings("unchecked") public Object coerceContext(int index, String desiredTypeName) { if (index >= context.getCount()) throw new IllegalArgumentException(String.format("Method %s has more parameters than there are context values for this component event.", getMethodDescription())); try { Class desiredType = elementResources.toClass(desiredTypeName); return context.get(desiredType, index); } catch (Exception ex) { throw new IllegalArgumentException(String.format("Exception in method %s, parameter #%d: %s", getMethodDescription(), index + 1, ex), ex); } }
ComponentEventImpl extends EventImpl implements ComponentEvent { @SuppressWarnings("unchecked") public Object coerceContext(int index, String desiredTypeName) { if (index >= context.getCount()) throw new IllegalArgumentException(String.format("Method %s has more parameters than there are context values for this component event.", getMethodDescription())); try { Class desiredType = elementResources.toClass(desiredTypeName); return context.get(desiredType, index); } catch (Exception ex) { throw new IllegalArgumentException(String.format("Exception in method %s, parameter #%d: %s", getMethodDescription(), index + 1, ex), ex); } } }
ComponentEventImpl extends EventImpl implements ComponentEvent { @SuppressWarnings("unchecked") public Object coerceContext(int index, String desiredTypeName) { if (index >= context.getCount()) throw new IllegalArgumentException(String.format("Method %s has more parameters than there are context values for this component event.", getMethodDescription())); try { Class desiredType = elementResources.toClass(desiredTypeName); return context.get(desiredType, index); } catch (Exception ex) { throw new IllegalArgumentException(String.format("Exception in method %s, parameter #%d: %s", getMethodDescription(), index + 1, ex), ex); } } ComponentEventImpl(String eventType, String originatingComponentId, EventContext context,
            ComponentEventCallback handler, ComponentPageElementResources elementResources,
            boolean exactParameterCountMatch, ComponentModel model, Logger logger); }
ComponentEventImpl extends EventImpl implements ComponentEvent { @SuppressWarnings("unchecked") public Object coerceContext(int index, String desiredTypeName) { if (index >= context.getCount()) throw new IllegalArgumentException(String.format("Method %s has more parameters than there are context values for this component event.", getMethodDescription())); try { Class desiredType = elementResources.toClass(desiredTypeName); return context.get(desiredType, index); } catch (Exception ex) { throw new IllegalArgumentException(String.format("Exception in method %s, parameter #%d: %s", getMethodDescription(), index + 1, ex), ex); } } ComponentEventImpl(String eventType, String originatingComponentId, EventContext context,
            ComponentEventCallback handler, ComponentPageElementResources elementResources,
            boolean exactParameterCountMatch, ComponentModel model, Logger logger); @Override String toString(); boolean matches(String eventType, String componentId, int parameterCount); @SuppressWarnings("unchecked") Object coerceContext(int index, String desiredTypeName); Object[] getContext(); EventContext getEventContext(); }
ComponentEventImpl extends EventImpl implements ComponentEvent { @SuppressWarnings("unchecked") public Object coerceContext(int index, String desiredTypeName) { if (index >= context.getCount()) throw new IllegalArgumentException(String.format("Method %s has more parameters than there are context values for this component event.", getMethodDescription())); try { Class desiredType = elementResources.toClass(desiredTypeName); return context.get(desiredType, index); } catch (Exception ex) { throw new IllegalArgumentException(String.format("Exception in method %s, parameter #%d: %s", getMethodDescription(), index + 1, ex), ex); } } ComponentEventImpl(String eventType, String originatingComponentId, EventContext context,
            ComponentEventCallback handler, ComponentPageElementResources elementResources,
            boolean exactParameterCountMatch, ComponentModel model, Logger logger); @Override String toString(); boolean matches(String eventType, String componentId, int parameterCount); @SuppressWarnings("unchecked") Object coerceContext(int index, String desiredTypeName); Object[] getContext(); EventContext getEventContext();  }