I'm mocking Abstract class but it gives an error that i can't instantiate the abstract class. I guess i'm missing some basics of mocking. So why can't i mock abstract class?
@Repository
public abstract class AbstractAccountDaoImpl implements AccountDao{
@Autowired
SimpleJdbcCall simpleJdbcCall;
@Override
public List<Account> getAccounts(String id){
SimpleJdbcCall simpleJdbcCall = getNewSimpleJdbcCall()
.withProcedureName(getAccountsProc)
.declareParameters(new SqlParameter("account_id", Types.VARCHAR));
Object[] params = new Object[] {id};
simpleJdbcCall.returningResultSet("result", new AccountRowMapper());
Map<String, Object> map = simpleJdbcCall.execute(params);
return (List<Account>) map.get("result");
}
Below is my junit:
public class AbstractAccountDaoImplTest {
private String IDS = "IDS";
@InjectMocks
private AbstractAccountDaoImpl abstractAccountDaoImpl;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void shouldReturnAccounts() {
Map<String, Object> map = new HashMap<>();
map.put("result", Arrays.asList(new Account(), new Account()));
simpleJdbcCallDefaultMock(simpleJdbcCallProvider, map);
List<Account> resultList = abstractAccountDaoImpl.getAccounts(IDS);
assertEquals(2, resultList.size());
}
public static void simpleJdbcCallDefaultMock(SimpleJdbcCallProvider simpleJdbcCallProvider, Map<String, Object> map) {
SimpleJdbcCall simpleJdbcCall = Mockito.mock(SimpleJdbcCall.class);
when(simpleJdbcCallProvider.getNewSimpleJdbcCall()).thenReturn(simpleJdbcCall);
}
How can I mock this using Mockito? Or do i need to use something else to mock this? If I mock from mockito, it gives me an error cannot instantiate AbstractAccountDaoImpl.
Any advice?
Aucun commentaire:
Enregistrer un commentaire