dcsimg
How to test a method which takes an interface object as the argument?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   vikas_kumar
Posted On:   Saturday, October 14, 2006 02:20 AM

I want to write a junit test for the method getExceptionHandlerInfoList below. It takes an argument Node. How do I call this method from the junit test case and what shall be the code for the test case? public class ConfigXMLParserHelper { private static transient Logger logger=Logger.getLogger(ConfigXMLParserHelper.class); public static Set getExceptionHandlerInfoList(Node rootElement) { Set exceptionHandlerInfoList=null; if(logger.isDebugEnabled()) { logger.debug("Inside getExceptionHandlerInfoList"); } if(rootElement!=null) { NodeList exceptionList=rootElement.getChildNodes(); //expected N   More>>
			
I want to write a junit test for the method
getExceptionHandlerInfoList below. It takes an argument
Node. How do I call this method from the junit test case
and what shall be the code for the test case?




public class ConfigXMLParserHelper
{
private static transient Logger logger=Logger.getLogger(ConfigXMLParserHelper.class);

public static Set getExceptionHandlerInfoList(Node rootElement)
{
Set exceptionHandlerInfoList=null;
if(logger.isDebugEnabled())
{
logger.debug("Inside getExceptionHandlerInfoList");
}
if(rootElement!=null)
{
NodeList exceptionList=rootElement.getChildNodes();
//expected Node's that have a name of exception.
if(exceptionList!=null && exceptionList.getLength()>0)
{
if(logger.isDebugEnabled())
{
logger.debug("one or more exceptions defined in CONFIG_XML");
}
for(int i=0;i
{
Node currentExceptionNode=exceptionList.item(i);
String exceptionClassName=null;
String exceptionHandlerClassName=null;
if(currentExceptionNode!=null && currentExceptionNode.getNodeName()!=null && currentExceptionNode.getNodeName().equals("exception"))
{
NamedNodeMap attributeMap=currentExceptionNode.getAttributes();
if(attributeMap!=null && attributeMap.getLength()>0)
{
Node exceptionClassAttribute=attributeMap.getNamedItem("class");
if(exceptionClassAttribute!=null)
{
exceptionClassName=exceptionClassAttribute.getNodeValue();
if(logger.isDebugEnabled())
{
logger.debug("class value defined for exception is "+exceptionClassName);
}
}
}
NodeList exceptionHandlerNodeList=currentExceptionNode.getChildNodes();
if(exceptionHandlerNodeList!=null && exceptionHandlerNodeList.getLength()>0)
{
if(logger.isDebugEnabled())
{
logger.debug("exceptionHandler defined for currentException");
}
for(int k=0;k
{
Node currentExceptionHandlerNode=exceptionHandlerNodeList.item(k);
if(currentExceptionHandlerNode!=null && currentExceptionHandlerNode.getNodeName()!=null && currentExceptionHandlerNode.getNodeName().equals("handler"))
{
NamedNodeMap handlerAttributeMap=currentExceptionHandlerNode.getAttributes();
if(handlerAttributeMap!=null && handlerAttributeMap.getLength()>0)
{
Node handlerNode=handlerAttributeMap.getNamedItem("class");
if(handlerNode!=null)
{
exceptionHandlerClassName=handlerNode.getNodeValue();
if(logger.isDebugEnabled())
{
logger.debug("exception handler defined is "+exceptionHandlerClassName);
}
}
}
}
}
}
}
if(exceptionHandlerClassName!=null && exceptionClassName!=null)
{
ExceptionHandlerInfo currentExceptionHandlerInfo=new ExceptionHandlerInfo();
currentExceptionHandlerInfo.setExceptionHandlerClassName(exceptionHandlerClassName);
currentExceptionHandlerInfo.setExceptionClassName(exceptionClassName);
if(exceptionHandlerInfoList==null)
{
exceptionHandlerInfoList=new HashSet();
}
exceptionHandlerInfoList.add(currentExceptionHandlerInfo);
}
}
}
}
if(logger.isDebugEnabled())
{
logger.debug("exiting getExceptionHandlerInfoList");
}
return exceptionHandlerInfoList;
}
}
   <<Less
About | Sitemap | Contact