I've been working on an application and need to write junit tests for the layer above the Data Access object - I need to mock the data access object and stub values to return for each method. I have tried using mockito but it doesn't seem to work, I think because it has a private constructor.
I have:
Mockito.mock(dataAccessObject.class);
Mockito.when(mockDAO.methodToStub()).thenReturn(returnValue)
but it doesnt return the specified returnValue when called.
This is the dataAccessObject I'm tring to mock:
public class DataAccessBean extends NewDataAccessBean
implements ISQLDataAccessBean {
// Instance of ISQLDataAccessBean
private static ISQLDataAccessBean instance = null;
static ISQLDataAccessBean getInstance() throws TrapDABException {
if (instance == null) {
instance = new DataAccessBean ();
}
return instance;
}
private DataAccessBean () throws DAOException {
super("JNDI_LOOKUP","ALIAS");
}
The Methods I am trying to stub values for are all public but when they are called using the mocked object, they return null..
Does anyone know a better test framework to use for this? I have also looked at powermockito plugin but have not been able to get that working either.