SenBotReferenceService { public <T> void addReference(Class<T> referenceClass, String referenceName, T referenceObject) { Map<String, T> refMap = getObjectReferenceMap(referenceClass); PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(referenceObject.getClass()); for(PropertyDescriptor descriptor : propertyDescriptors) { if(String.class.equals(descriptor.getPropertyType())) { String findProp = referenceClass.getSimpleName() + "." + referenceName + "." + descriptor.getName(); String foundValue = SpringPropertiesExposer.getProperty(findProp); if(foundValue != null) { try { org.apache.commons.beanutils.BeanUtils.setProperty(referenceObject, descriptor.getName(), foundValue); } catch (Exception e) { throw new RuntimeException("Exception while setting " + descriptor.getName() + " on " + referenceObject, e); } } } } refMap.put(referenceName, referenceObject); } SenBotReferenceService(String populatorClassName,
    		CucumberManager cucumberManager); void addUser(String refName, GenericUser user); void addPageReference(String pageReference, String pageUrl); void addLocatorReference(String locatorReference, By locator); By getElementLocatorForElementReference(String elementReference); By getElementLocatorForElementReference(String elementReference, String apendix); void addPageRepresentationReference(String name, Class clazz); GenericUser getUserForUserReference(String userReference); String getUrlForPageReference(String pageReference); Class getPageRepresentationReference(String pageRepresentationReference); T getPageRepresentationInstance(Class<T> referenceClassType); String namespaceString(String plainString); void addReference(Class<T> referenceClass, String referenceName, T referenceObject); Map<String, T> getObjectReferenceMap(Class<T> referenceClass); T getReference(Class<T> referenceClass, String referenceName); static final String NAME_SPACE_PREFIX; static final String SCENARIO_NAME_SPACE_PREFIX; }
@Test public void testAddReference() throws IllegalAccessException, InvocationTargetException { SenBotReferenceService referenceService = SenBotContext.getSenBotContext().getReferenceService(); MockRefObject expected = new MockRefObject(); referenceService.addReference(MockRefObject.class, "mock_ref", expected); MockRefObject found = (MockRefObject) referenceService.getReference(MockRefObject.class, "mock_ref"); assertEquals(expected, found); }