I'm trying to mock this dao and I'm getting a NPE. I'm not sure if I'm not mocking something correctly or I'm using something inappropriately. I have this dao below:
@Repository
public class PersonDaoImpl extends AbstractDao implements PersonDao {
private static final String SQL = "select * from personTable";
@Override
public List<Person> getAllPerson() {
PersonRowMapper personRowMapper = new PersonRowMapper ();
List<Person> personList = getNamedParameterJdbcTemplate().query(SQL, personRowMapper);
return personList ;
}
And this is my junit
public class PersonDaoImplTest {
@Mock
protected NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Mock
protected PersonRowMapper personRowMapper;
@InjectMocks
private PersonDaoImpl personDaoImpl;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void shouldReturnPerson() {
when(namedParameterJdbcTemplate.query(anyString(), Matchers.<RowMapper<PersonRowMapper>> any())).thenReturn(anyList());
List<Person> resultList = personDaoImpl.getAllPerson();
assertTrue(!resultList.isEmpty());
}
It throws NPE on List<Person> resultList = personDaoImpl.getAllPerson();
What am I missing or not mocking correctly? Any help would be appreciated
Aucun commentaire:
Enregistrer un commentaire