public void setCalendar( int recordsFilter, GregorianCalendar startDate, GregorianCalendar endDate ) throws KettleException {
    this.startDate = startDate;
    this.endDate = endDate;
    this.recordsFilter = recordsFilter;
    if ( this.startDate == null || this.endDate == null ) {
      throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.Error.EmptyStartDateOrEndDate" ) );
    }
    if ( this.startDate.getTime().compareTo( this.endDate.getTime() ) >= 0 ) {
      throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.Error.WrongDates" ) );
    }
    // Calculate difference in days
    long diffDays =
      ( this.endDate.getTime().getTime() - this.startDate.getTime().getTime() ) / ( 24 * 60 * 60 * 1000 );
    if ( diffDays > 30 ) {
      throw new KettleException( BaseMessages.getString( PKG, "SalesforceInput.Error.StartDateTooOlder" ) );
    }
  }
@Test
  public void testSetCalendar() {
    SalesforceConnection conn = mock( SalesforceConnection.class, Mockito.CALLS_REAL_METHODS );

    // Test valid data
    try {
      conn.setCalendar( new Random().nextInt( SalesforceConnectionUtils.recordsFilterDesc.length ),
          new GregorianCalendar( 2016, Calendar.JANUARY, 1 ), new GregorianCalendar( 2016, Calendar.JANUARY, 31 ) );
      // No errors detected
    } catch ( KettleException e ) {
      fail();
    }

    // Test reversed dates (should fail)
    try {
      conn.setCalendar( new Random().nextInt( SalesforceConnectionUtils.recordsFilterDesc.length ),
          new GregorianCalendar( 2016, Calendar.JANUARY, 31 ), new GregorianCalendar( 2016, Calendar.JANUARY, 1 ) );
      fail();
    } catch ( KettleException expected ) {
      // Ignore, expected result
    }

    // Test null start date (should fail)
    try {
      conn.setCalendar( new Random().nextInt( SalesforceConnectionUtils.recordsFilterDesc.length ),
          null, new GregorianCalendar( 2016, Calendar.JANUARY, 31 ) );
      fail();
    } catch ( KettleException expected ) {
      // Ignore, expected result
    }

    // Test null end date (should fail)
    try {
      conn.setCalendar( new Random().nextInt( SalesforceConnectionUtils.recordsFilterDesc.length ),
          new GregorianCalendar( 2016, Calendar.JANUARY, 1 ), null );
      fail();
    } catch ( KettleException expected ) {
      // Ignore, expected result
    }
  }