protected void assertSetProperty(Object bean, String property, Object newValue) throws Exception { PropertyDescriptor descriptor = getDescriptor(bean, property); Method method = descriptor.getWriteMethod(); assertTrue("has setter method", method != null); Object[] args = {newValue}; Object value = invokeMethod(bean, method, args); assertEquals("should return null", null, value); assertGetProperty(bean, property, newValue); }
/** * Asserts that the script runs without any exceptions */ protected void assertScript(String text) throws Exception { assertScript(text, getTestClassName()); }
protected void assertField(Class aClass, String name, int modifiers, ClassNode type) throws Exception { Field field = aClass.getDeclaredField(name); assertTrue("Found field called: " + name, field != null); assertEquals("Name", name, field.getName()); assertEquals("Type", type.getName(), field.getType().getName()); assertEquals("Modifiers", modifiers, field.getModifiers()); }
protected Object invokeMethod(Object bean, Method method, Object[] args) throws Exception { try { return method.invoke(bean, args); } catch (InvocationTargetException e) { fail("InvocationTargetException: " + e.getTargetException()); return null; } }
protected GroovyObject compile(String fileName) throws Exception { Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName))); GroovyObject object = (GroovyObject) groovyClass.newInstance(); assertTrue(object != null); return object; } }
protected void setUp() throws Exception { super.setUp(); source = SourceUnit.create("dummy.groovy", ""); verifier = new ClassCompletionVerifier(source); }
protected PropertyDescriptor getDescriptor(Object bean, String property) throws Exception { BeanInfo info = Introspector.getBeanInfo(bean.getClass()); PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getName().equals(property)) { return descriptor; } } fail("Could not find property: " + property + " on bean: " + bean); return null; }
protected void assertGetProperty(Object bean, String property, Object expected) throws Exception { PropertyDescriptor descriptor = getDescriptor(bean, property); Method method = descriptor.getReadMethod(); assertTrue("has getter method", method != null); Object[] args = { }; Object value = invokeMethod(bean, method, args); /* System.out.println("Expected: " + expected); System.out.println("Value: " + value); if (expected == null) { System.out.println("Expected is null"); } if (value == null) { System.out.println("value is null"); } */ assertEquals("property value", expected, value); }