title: How to set object that is being refereed in private inner class while creating Junit?
body: <p>I have 2 java classes.</p>
  
  <pre><code>1) class1.java
  
  public class class1
  {
    private class ParameterVariable
    {
     class2 c1;
     String s;
     ParameterVariable(String s)
     {
          this.s =s;
     }
    }
  
  
     public void methodToTest(String s)
     {
          try
          {
              ParameterVariable pv = new ParameterVariable(s)
              if(StringUtils.isNotEmpty(pv.c1.getPartNo()))
              {
                 // Some Code
              }
          }
          finally
          {
          // Some code
          }
  
  
     }
  }
  
  2) class2.java
  public class class2
  {
      // pojo class
      String partNo;
      public String getPartNo()
      {
          return partNo;
      }
      public void setPartNo(String partNo)
      {
          this.partNo = partNo;
      }
  }
  </code></pre>
  
  <p>Now I want to create a Junit test case for my method. I am not able to get runtime value for class2 object.
  Here is my work</p>
  
  <pre><code>private class1 = null;
  
  protected Object createParamterVariableObject ( String s ) throws ClassNotFoundException,  InstantiationException, 
                                                                                                                      IllegalAccessException,  InvocationTargetException, 
                                                                                                                      NoSuchMethodException, SecurityException
  {
      Class clazz = Whitebox.getInnerClassType(class1.class, "ParameterVariable");
      Constructor constructorForParameterVariable = clazz.getConstructor(String.java)
  
      Object parameterVariableObject = constructorForParameterVariable.newInstance(String.java)
      return parameterVariableObject;
  }
  
  @Test
  public void junitTestCase() throws Exception 
  {
    String s = "Sample";
    Class clazz = null;
      Object parameterVariableObject = null;
    class2 cls2Object = new clsObject;
  
      try
      {
          parameterVariableObject = createParamterVariableObject(s);
  
          clazz = Whitebox.getInnerClassType(SupersedeImpl.class, "ParameterVariable");
      }
      catch (Exception e)
      {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      class2 c2Object = new class2();
      c2Object.setPartNo("NEW_PART_NO");
      Field C1Field = (Field) parameterVariableObject.getClass().getDeclaredField("c1");
      C1Field.set(parameterVariableObject, C1Field);
  
      PowerMockito.whenNew(clazz).withArguments(s).thenReturn(parameterVariableObject);
  
      class1 = PowerMockito.spy(class1);
  
      class1.methodToTest(s);
  
      // some assertion
  }
  </code></pre>
  
  <p>I want to set some mocking value of part no that is object of class2. 
  Because my method is based on it.
  I am getting null using these code. Can you please help me?</p>