title: How to catch/throw exception using PowerMockito
body: <p>I am writing  <code>JUnit</code> test case for a method which doesn't throw exception but this method invokes <code>parse()</code> method which throws <code>ParseException</code> and I need to catch it. I have created one test case where I am passing invalid date format and during debugging it goes in the parse method and then to the catch block but how can I explicitly throw <code>ParseException</code> in a test case and then compare the String in the log. Hope I am clear. </p>
  
  <p>Method under test. </p>
  
  <pre><code>public static String convertUTC( String strDate, String inputFormat, String outputFormat ) {
      String displayDateString = null;
  
      try {
          DateFormat inFormat = new SimpleDateFormat( inputFormat );
          inFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
          Date date = inFormat.parse( strDate );
  
          DateFormat outFormat = new SimpleDateFormat( outputFormat );
          outFormat.setTimeZone( TimeZone.getDefault() );
  
          displayDateString = formatDate(date, outputFormat);
      } catch ( ParseException pe ) {
          log.error( "DateUtil.convertUTC :Parse exception while parsing,"+strDate+" using format :"+inputFormat) ; 
      }
  
      return displayDateString;
  }
  </code></pre>
  
  <p>JUnit</p>
  
  <pre><code>@Test
  public void testConvertUTCParseException() {
      String incomingDate = "2012-08-15T22:56:02.038Z";
      String inputFormat = "MM/dd/yy hh:mm a z";
      String outputFormat = "MM/dd/yy hh:mm a z";
  
      assertEquals( null, DateUtils.convertUTC( incomingDate, inputFormat, outputFormat ) );
  }
  </code></pre>
  
  <p>Apart from the above test case I want to explicitly throw <code>ParseException</code> using PowerMockito and do the assert in the log to compare the text. The reason I cannot do it is because converUTC doesn't throw ParseException. </p>
  
  <p>I assume this throws exception but how can I compare the text in the log?</p>
  
  <pre><code>@SuppressWarnings("unchecked")
  @Test
  public void testCaughtParseException() throws Exception {
      PowerMockito.mockStatic( DateUtils.class );
      PowerMockito.when( DateUtils.convertUTC( Mockito.any( String.class ), Mockito.any( String.class ), Mockito.any( String.class ) ) ).thenThrow( ParseException.class );   
  }
  </code></pre>
  
  <p>Thanks.</p>