public static Date getDateFromStringByFormat( String dateString, String dateFormat ) throws ParseException {
    if ( dateFormat == null ) {
      throw new ParseException( "Unknown date format. Format is null. ", 0 );
    }
    if ( dateString == null ) {
      throw new ParseException( "Unknown date string. Date string is null. ", 0 );
    }
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat( dateFormat );
    simpleDateFormat.setLenient( false ); // Don't automatically convert invalid date.
    return simpleDateFormat.parse( dateString );
  }
@Test
  public void testGetDateFromStringByFormat() throws ParseException {
    assertEquals( SAMPLE_DATE, DateDetector.getDateFromStringByFormat( SAMPLE_DATE_STRING, SAMPLE_DATE_FORMAT ) );
    try {
      DateDetector.getDateFromStringByFormat( SAMPLE_DATE_STRING, null );
    } catch ( ParseException e ) {
      // expected exception
    }
    try {
      DateDetector.getDateFromStringByFormat( null, SAMPLE_DATE_FORMAT );
    } catch ( ParseException e ) {
      // expected exception
    }
  }