You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-dev@jakarta.apache.org by Sanka Samaranayake <sa...@opensource.lk> on 2004/06/21 04:58:19 UTC

Testcase for MethodUtils class

Hi,

can anyone commit this testcase for MethodUtils class

Regards !!

Sanka

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


package org.apache.bsf.test.utilTests;

import org.apache.bsf.util.MethodUtils;

import junit.framework.TestCase;

/**
 * This is a testcase for MethodUtils class
 *
 * @author Sanka Samaranayake <sa...@opensource.lk>
 * @author Nilupa Bandara     <ni...@opensource.lk>
 *
 */
public class MethodUtilsTest extends TestCase {

	public void testGetConstructor() {
		try{
			MethodUtils.getConstructor(MethodUtilsBean.class,null);
		}catch(NoSuchMethodException nsme){
			fail(nsme.getMessage());
		}

		try{
			MethodUtils.getConstructor(MethodUtilsBean.class,
					new Class[]{String.class});
			fail("calling a non existing constructor with parms");
		}catch(NoSuchMethodException nsme){
		}

	}

	/*
	 * Class under test for Method getMethod(Class, String, Class[], boolean)
	 */
	public void testGetMethodClassStringClassArrayboolean() {

		try {
			MethodUtils.getMethod(MethodUtilsBean.class, "setValues",
					new Class[]{Integer.TYPE, Integer.TYPE}, false);
		} catch (NoSuchMethodException nsme) {
			fail("should not throw an exception when there is a exact method");
		}

		try {
			MethodUtils.getMethod(MethodUtilsBean.class, "setValues",
					new Class[]{Integer.TYPE, Short.TYPE}, false);
		}catch (NoSuchMethodException nsme){
			fail("should not throw an exception when there is an appropriate" +
					"method");
		}

		try {
			MethodUtils.getMethod(MethodUtilsBean.class, "setValues",
					new Class[] {Integer.TYPE, String.class}, false);
			fail("should throw a NoSuchMethodException for a non " +
					"existing method");
		}catch (NoSuchMethodException nsme){
		}
	}

	/*
	 * Class under test for Method getMethod(Object, String, Class[])
	 */
	public void testGetMethodObjectStringClassArray() {

		MethodUtilsBean bean = new MethodUtilsBean();
		try {
			MethodUtils.getMethod(bean, "getValues", new Class[]{Integer.TYPE});
		} catch (NoSuchMethodException nsme) {
			fail("should not throw an exception when there is a excat match");
		}

		try {
			MethodUtils.getMethod(bean, "getValues", new Class[]{Short.TYPE});

		}catch (NoSuchMethodException nsme) {
			fail("should not throw an exception when there is an appropriate" +
					"method");
		}

		try {
			MethodUtils.getMethod(bean,"getValues", new Class[]{String.class});
			fail("should throw a NoSuchMethodException");
		} catch (NoSuchMethodException nsme){
		}

	}

}




---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-dev-help@jakarta.apache.org