Hi,

can anyone commit this testcase for RflectionUtils class

cheers !!

Sanka

********************************************************
********************************************************


package org.apache.bsf.test.utilTests;

import org.apache.bsf.util.Bean;
import org.apache.bsf.util.ReflectionUtils;

import junit.framework.TestCase;

/**
 * This is a testcase for ReflectionUtils class
 *
 * @author Sanka Samaranayake <[EMAIL PROTECTED]>
 * @author Nilupa Bandara     <[EMAIL PROTECTED]>
 *
 */

public class ReflectionUtilsTest extends TestCase {

        public void testAddEventListener() {
        }

        /*
         * Class under test for Bean createBean(ClassLoader, String, Class[],
Object[])
         */
        public void testCreateBeanClassLoaderStringClassArrayObjectArray() {

                String foo = new String("createBeanTest");

                try {
                        Bean bean = ReflectionUtils.createBean(null, 
"java.lang.String",
                                        new Class[] {String.class}, new Object[]{new 
String("createBeanTest")});
                        String bar = (String)bean.value;
                        assertEquals(bar, foo);

                } catch (Exception ex){
                        fail(ex.getMessage());

                }
        }

        /*
         * Class under test for Bean createBean(ClassLoader, String, Object[])
         */
        public void testCreateBeanClassLoaderStringObjectArray() {

                String foo = new String("createBeanTest");

                try {
                        Bean bean = ReflectionUtils.createBean(null, 
"java.lang.String",
                                        new Object[]{new String("createBean")});

                }catch(Exception ex){
                        fail(ex.getMessage());

                }
        }

        public void testGetField() {

                Integer foo = new Integer(1);
                Bean bar = null;

                try {
                        bar = ReflectionUtils.getField(foo, "TYPE");
                        assertEquals(bar.value, Integer.TYPE);

                }catch(Exception ex){
                        fail(ex.getMessage());

                }
        }

        public void testGetProperty() {

                MethodUtilsBean foo = new MethodUtilsBean();
                Bean bar = null;

                int[] values = new int[]{1};
                foo.setValues(values);

                try{
                        bar = ReflectionUtils.getProperty(foo, "values", null);
                        assertEquals(bar.value, values);

                }catch (Exception ex){
                        fail(ex.getMessage());

                }
                // for an indexed property ..
                try {
                        bar = ReflectionUtils.getProperty(foo, "values", new 
Integer(0));
                        assertEquals(bar.value, new Integer(values[0]));

                }catch (Exception ex){
                        fail(ex.getMessage());

                }
        }

        public void testSetField() {

                MethodUtilsBean foo = new MethodUtilsBean();
                int[] bar = new int[]{1};
                Bean bean = new Bean(bar.getClass(), bar);

                try{
                        ReflectionUtils.setField(foo, "values", bean, null);
                        assertEquals(bar, foo.values);

                }catch (Exception ex){
                        fail(ex.getMessage());

                }
        }

        public void testSetProperty() {

                MethodUtilsBean foo = new MethodUtilsBean();
                int[] bar = new int[]{1};

                try{
                        ReflectionUtils.setProperty(foo, "values", null, bar,
                                        bar.getClass(), null);
                        assertEquals(foo.getValues(), bar);

                } catch(Exception ex){
                        fail(ex.getMessage());

                }

                // tests for an indexed property ..
                try {
                        ReflectionUtils.setProperty(foo, "values", new Integer(0),
                                        new Integer(bar[0]), Integer.TYPE, null);
                        assertTrue(bar[0] == foo.getValues(0));

                }catch (Exception ex){
                        fail(ex.getMessage());

                }
        }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to