title: How can I surpass or skip a method using JUNIT?
body: <p>I have a block of code for which I need to test .Lets say </p>
  
  <pre><code>Class MainClass{    
     public void startProcess() {     
        ----Some Logic to generate fileName; 
            uploadFile(fileName);     
         }
  
    private static void uploadFile(String key) {    
        fileUpload();    
        deleteFile();    
    }    
  }
  </code></pre>
  
  <p>I want to write a JUNIT test which will call startProcess but either skip the uploadFile line or just ignore any lines present in uploadFile method .</p>
  
  <p>I tried to use powerMock but it doesnt work . Below is my code </p>
  
  <pre><code>@RunWith(PowerMockRunner.class)
  @PrepareForTest(MainClass.class)
  public class MainClassTest {         
     @Test
     public void teststartProcess() throws Exception {
       processor=PowerMock.createPartialMock(MainClass.class,"uploadFile");
       PowerMock.expectPrivate(processor , "uploadFile", "xyz").andAnswer(
         new IAnswer&lt;Void&gt;() {
         @Override
         public Void answer() throws Throwable {
           System.out.println("Invoked!");
           return null;
         }
      }).atLeastOnce();
    }
  }
  </code></pre>
  
  <p>But it does't override the method uploadFile to just print invoked . It calls fileUpload and deleteFile instead of just skipping the lines and print invoke .</p>
  
  <p>My basic goal is to mock the method uploadFile to just print </p>
  
  <pre><code>private void uploadFile(String key) {
    System.out.println("Invoked");
  }
  </code></pre>
  
  <p>I know it's possible using Mockito but we can use either PowerMock or EasyMock . </p>