title: Mocking a private constructor
body: <p>The <code>Site</code> class is provided to me by an external team and has a <strong>private</strong> constructor.</p>
  
  <pre><code>public class Site
  {
     int id;
     String brand;
  
     private Site(int id, String brand)
     {
        this.id = id;
        this.brand = brand;
     }
  }
  </code></pre>
  
  <p>The SiteUtil class (controlled by team) is</p>
  
  <pre><code>public class SiteUtil
  {
     public static Site getSite()
     {
       Site site;
       //Logic
       return site; 
     }
   }
  </code></pre>
  
  <p>The data the <code>getSite()</code> function applies it logic on requires a network call, therefore it needs to be mocked. It doesn't have a setter currently (maybe to maintain consistency with the data source, not so sure)</p>
  
  <p>I mock it as follows</p>
  
  <pre><code>Site mockSite = new Site(1,"Google");
  PowerMockito.when(SiteUtil.getSite(1)).thenReturn(mockSite);
  </code></pre>
  
  <p>The code above of course dosent compile as I use the public constructor.
  The solution I read was to mock the private constructor of <code>Site</code> object. I'm however at a loss on how to do that (First time writing unit tests!)</p>