Hello , i have a small spring application developed with springboot , im currenty trying to test this method of one of my beans:
public void init() {
if(this.currentCard!=null || this.currentDeck !=null) {
return;
}
Map<String, String> params;
FacesContext context = FacesContext.getCurrentInstance();
params = context.getExternalContext().getRequestParameterMap();
long id = Long.parseLong(params.get("id"));
...
...
...
}```
my problem is that this method takes a parameter it needs from context (id) :
``` Map<String, String> params;
FacesContext context = FacesContext.getCurrentInstance();
params = context.getExternalContext().getRequestParameterMap();```
normally the parameter is passed trough clicking a button in the web interface
and i have no idea how to mock this parameter while doing unit tests.
this is the beginning of my test:
``` @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
@Test
@DisplayName("Testing if the bean is correctly initialized")
@WithMockUser(username = "admin", authorities = {"ADMIN", "STUDENT"})
void testInit() {
this.applicationContext.getAutowireCapableBeanFactory().autowireBean(this.bean);
bean.init();
....
....
}```
this is the error im getting :
```java.lang.NullPointerException: Cannot invoke "javax.faces.context.FacesContext.getExternalContext()" because "context" is null```
ive looked online for solutions but im somewhat at a loss as i only recently started using spring , would be really thankfull for any help
thank you