I have a test сlass with a method where I add some data to the database and then retrieve it and check if the data is the same:
public class QueryImplTest {
@Autowired
Jdbc jdbcTemplate;
QueryImpl queryImpl = new QueryImpl(jdbcTemplate);
@Test
public void someTest() {
SomeObject someExpectedObject = new SomeObject(//object
queryImpl.saveSomeObject(someExpectedObject)
SomeObject someRealObject = jdbcTemplate.queryForObject(SELECT_OBJECT_QUERY, SomeObject.Class)
//all of the Assertions
}
And I get a Cannot invoke JdbcTemplate.update()(from saveSomeObject method) because this.jdbcTemplate is null
The QueryImpl class:
@Repository
public class QueryImpl {
private JdbcTemplate jdbcTemplate;
@Autowired
public QueryImpl(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
//methods and query strings
}