I am unit testing a class AuthController, which has this constructor
@Autowired
public AuthController(DynamicBeanFactory beanService) {
Sysout(beanService); //here null is coming - Point-1
}
In Test Class, I have done:
@Mock
DynamicBeanFactory beanService;
@InjectMocks
AuthController authController(beanService);
- Below @Test are there -
Now when I am running this :
the value of beanService inside constructor above at point-1
is coming null.
Also, when I am doing @Autowired at place of @InjectMocks it works.
Below I have shared some questions people asked.
Q) What is AuthController?
A) It's just a class having that constructor I have shared above.
Q) What is Dynamic Bean Factory ?
A) It's a Service class something like this below :
@Service
public class DynamicBeanFactory
@Autowired
public DynamicBeanFactory(BeanFactory beanFactory) {
this.beanFactory = beanFactory)
}
}