I am trying to add some unit tests to a JSF application. This application didnt rely heavily on any best practices, so many service methods use the FacesContext
to
I believe the best solution is not presented here. Here we go
@RunWith(PowerMockRunner.class)
@PrepareForTest({ FacesContext.class})
public class MyTestClass{
@Mock
private FacesContext facesContext;
@Before
public void init() throws Exception {
PowerMockito.mockStatic(FacesContext.class);
PowerMockito.when(FacesContext.getCurrentInstance()).thenReturn(facesContext);
}
And you need to import all the PowerMockito bundle in your pom.xml
org.mockito
mockito-all
${mockito.version}
test
org.powermock
powermock-api-mockito
${powermock.version}
test
org.powermock
powermock-module-junit4
${powermock.version}
test