0

I wrote myself aSortingBeanwhich is similiar to theCarsSortingBeanover here. I want to write a unit test for this class but I don't know how to do this. I got problems with the first line of the sort method. How can I successfully mock this?

I already found out, that there is something calledMockFacesContext:

@Test
public void testSort() throws Exception {
    facesContextMock = MockFacesContext.getMockContext(true);
    replay(facesContextMock);

    classUnderTest.sort();
}

With this test I am getting aNullPointerExceptionbecause theRequestParameterMapis not filled.

Can you give me any hint of how to solve this problem?

Chris311
  • 3,794
  • 9
  • 46
  • 80

1 Answers1

0

I'd say move sorting logic to other class that does not know about JSF context. Then, for example, create method setSortParameter(String) and fill it in unit test and in this bean.

I've had hard time playing with mock JSF contexts for a few years (using Shale framework + JSF 1.1) and I'm not going to do it any more.

Vytenis Bivainis
  • 2,308
  • 21
  • 28