Below is my JUnit test code where I'm getting Null pointer Exception
public class MybatisApplicationTests {
@Autowired
UserService userService;
@Test
public void deleteUserByIdTest() {
UserController uc = new UserController();
Long id = 3L;
assertEquals(1,uc.deleteUserById(id));
}
Below is my controller UserService.java
@DeleteMapping("/deleteUserById/{id}")
public int deleteUserById(@PathVariable("id") Long id) {
System.out.println("delete meth called");
userService.deleteUserById(id);
return 1;
}
And below is my ServiceImpl.java
@Override
public int deleteUserById(Long id) {
System.out.println("delete meth service called");
userMapper.deleteUserById(id);
return 1;
}
I've tried in all possible ways, but I'm getting NullPointerException
as an error. Help me to resolve the error & thanks in advance.