title: PowerMock - Mock a Singleton with a Private Constructor
body: <p>I'm using PowerMock with EasyMock, and wondered how I might mock a singleton with a private constructor?</p>
  
  <p>Let's say I have the following class:</p>
  
  <pre><code>public class Singleton {
      private static Singleton singleton = new Singleton();
      private Singleton() { }
  
      public static Singleton getInstance() {
          return singleton;
      }
  
      public int crazyServerStuff() { ... }
  }
  </code></pre>
  
  <p>And a class which uses this:</p>
  
  <pre><code>public class Thing {
      public Thing() {}
  
      public int doStuff(Singleton s) {
          return s.crazyServerStuff() + 42;
      }
  }
  </code></pre>
  
  <p>How might I mock the <code>crazyServerStuff</code> method?</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  @PrepareForTest(Singleton.class)
  public class ThingTest extends AndroidTestCase {
      @Test
      public void testDoStuff() {
          MemberModifier.suppress(MemberModifier.constructor(Singleton.class));
          Singleton mockSingleton = PowerMock.createMock(Singleton.class);
  
          ...
      }
  }
  </code></pre>
  
  <p>But I get the error <code>java.lang.IllegalArgumentException: No visible constructors in class Singleton</code></p>
  
  <p>Does anyone know what I'm missing?</p>