Reflection and JUnit question

25 views
Skip to first unread message

Patrick Fong

unread,
May 13, 2012, 5:39:43 AM5/13/12
to google-a...@googlegroups.com
Hi 

I have two classes, DBKeyImpl which implements DBKey and extends AbstractDBImpl. AbstractDBImpl extends AbstractDB which has a method which returns the PersistenceManager

public abstract class AbstractDBImpl extends AbstractDB {

@Override

protected PersistenceManager getPmf()

{

return PMF.get().getPersistenceManager();

}

}

DBKeyImpl extends AbstractDBImpl calls the getPmf(). I want to write a JUnit which tests DBKeyImpl


public class DBKeyEventOldTest extends BaseTest

{

public void testAdd()

{


KeyObject keyObject = new KeyObject();

keyObject.setKey("key");

keyObject.setUserid("userId");

DBKey dbKey = new DBKeyImpl();

dbKey.save(keyObject);

...

}

}

GAE does not support sun.reflect.Reflection, so we can't use Reflection.getCallerClass(arg0)

In order to test the DBKeyImpl and the PersistenceManager, you will use a mocked up PersistenceManager

Is it possible for me to find the calling class (via reflection) - ie the test class for me to determine the calling class, so that I can use the mocked up PersistenceManager?

One work around for this is for me to extend my Testclass to DBKeyImpl and override the PersistenceManager. This is a hack and is tightly coupled. 

Cheers
Patrick

Patrick Fong

unread,
May 14, 2012, 2:09:04 AM5/14/12
to google-a...@googlegroups.com


Just fig'ed out - go back to elementary SD principles, mock it up. 
Reply all
Reply to author
Forward
0 new messages