I have a method which is used to check if the given class is instance of perticular type.
Say for example myClass is an instance of DBClass I want to return true.
And the DBClass is dynamically defined by customer in the properties file.
So I am reading the properties file, getting the DBClass super type , loading it and checking if given class (i.e myClass) is instance of the DBClass.
And one thing is for sure that the DBCLass which i am trying to check for supertype will not be present in my classpath at running the test case as this dbClass is dynamic and customer specific.
I am not sure how to directly test it or cover it.I am not sure if I need to mock properties file?
I am using Junit and JMock.
Any suggestions on testing the method.
Method is written something like this.
public boolean isDBClass (final Class<?> myClass) {
//Following line reads the properties file and get the class name for db parent class.
String dbSuperClass = PropertiesReader.PropertyEnum.DB_CLASS_PARENT.toString();
// if myClass is subclass of dbSuperClass return true, false otherwise.
return loadClass(dbSuperClass).isAssignableFrom(myClass);
}
Well I have find out a work around currently.
I am providing the a dummy properties file which refers to the dummy class which is in my classpath.