Mocking FacesContext

前端 未结 7 993
执念已碎
执念已碎 2021-02-18 19:20

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

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-18 20:05

    You can return a mock context via FacesContext.getCurrentInstance by invoking setCurrentInstance(FacesContext) before running the test. The method is protected, but you can access it either via reflection or by extending FacesContext. There is a sample implementation using Mockito here.

提交回复
热议问题