jakarta-bsf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sanka Samaranayake" <sa...@opensource.lk>
Subject Testcase for MethodUtils class
Date Mon, 21 Jun 2004 02:58:19 GMT
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 <sanka@opensource.lk>
 * @author Nilupa Bandara     <nilupa@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


Mime
View raw message