Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JDev 12c - JMockit - FacesContext is throwing null

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?

This post has been answered by Vivek Sridhar-Oracle on Apr 1 2024
Jump to Answer
Comments
Post Details
Added on Mar 29 2024
1 comment
147 views