title: Instantiating a Class with private constructor using Java/Mockito/PowerMockito
body: <p>I am writing a test case using <code>JUnit</code> and the method under test takes a final class with a private constructor as a parameter. Since I cannot instantiate it with the <code>new</code> keyword I tried using <code>Mockito</code> but found out that <code>Mockito</code> doesn't like <code>final class</code>. I went to use <code>PowerMockito</code> which seemed reasonable to me but <code>PowerMockito.mockStatic(Field.class);</code> is a void method and I need a reference of <code>Field</code> so that I can pass it as an argument while invoking the method. </p>
  
  <p>I want to catch <code>IllegalArgumentException</code> but first I need to pass reference of <code>Field</code> as an argument</p>
  
  <p>Method under test</p>
  
  <pre><code>public boolean accept(Field field) { 
      if( ignoreNulls ) {
          try {
              if( field.get( super.getObject() ) == null ) {
                  return false;
              }
          } catch (IllegalArgumentException e) {
          } catch (IllegalAccessException e) {
          }
      }
  
      return super.accept(field); 
  } 
  </code></pre>
  
  <p>JUnit test case</p>
  
  <pre><code>   @Test(expected=IllegalArgumentException.class)
      public void testAccept() throws Exception {
        DefaultToStringBuilder builder = new DefaultToStringBuilder(new Object());
        PowerMockito.mockStatic(Field.class);
  
        builder.accept(?);
  }
  </code></pre>
  
  <p>I am not sure how should I be doing this.</p>
  
  <p>Thanks in advance</p>