Hello Team,
We have recently migrated from Jdev 11g to 12c and we are using JMockit testing framework for our existing JUnit test cases within our product. We do have a certain test case testing JSFUtils methods which are primarily used in UI scenarios and it started throwing null pointer exception despite us not making any code change within that test case.
Test Case:
@Test
public void testAddFacesMessage_null() {
RichTree comp = new RichTree();
comp.setId("tree1Id");
final UIViewRoot root = new UIViewRoot();
root.setId("root");
root.getChildren().add(comp); // The Error is thrown at this line
new NonStrictExpectations() {
FacesContext fc;
{
fc.getViewRoot();
returns(root);
FacesContext.getCurrentInstance();
returns(fc);
}
};
JSFUtil.addFacesMessage("root", null, FacesMessage.SEVERITY_ERROR);
// make sure msg does not get displayed
new Verifications() {
FacesContext fc;
{
fc.addMessage((String)any, (FacesMessage)any);
times = 0;
}
};
}
Error:
java.lang.NullPointerException: null
org.apache.myfaces.trinidad.component.UIXComponentBase._publishPostAddToViewEvent(UIXComponentBase.java:1805)
org.apache.myfaces.trinidad.component.UIXComponentBase.setParent(UIXComponentBase.java:825)
javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:2700)
javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:2672)
Any idea what is missing from the above test case?