@VisibleForTesting
  static Number convert(Date date, TimeUnit timeUnit, FieldSpec.DataType dataType) {
    long convertedTime = timeUnit.convert(date.getTime(), TimeUnit.MILLISECONDS);
    if (dataType == FieldSpec.DataType.LONG || dataType == FieldSpec.DataType.TIMESTAMP) {
      return convertedTime;
    }
    if (dataType == FieldSpec.DataType.INT) {
      return (int) convertedTime;
    }
    throw new IllegalArgumentException("Time column can be only INT, LONG or TIMESTAMP: " + dataType);
  }
@Test
  public void testConvert() {
    int oneHourInMillis = 60 * 60 * 1000;
    Date date = new Date(oneHourInMillis + 1);

    // seconds
    Number convertedTime = TimeGenerator.convert(date, TimeUnit.SECONDS, FieldSpec.DataType.LONG);
    assertTrue(convertedTime instanceof Long);
    assertEquals(3600L, convertedTime);

    // seconds (timestamp)
    convertedTime = TimeGenerator.convert(date, TimeUnit.SECONDS, FieldSpec.DataType.TIMESTAMP);
    assertTrue(convertedTime instanceof Long);
    assertEquals(3600L, convertedTime);

    // minutes
    convertedTime = TimeGenerator.convert(date, TimeUnit.MINUTES, FieldSpec.DataType.INT);
    assertTrue(convertedTime instanceof Integer);
    assertEquals(60, convertedTime);

    // check hours
    convertedTime = TimeGenerator.convert(date, TimeUnit.HOURS, FieldSpec.DataType.INT);
    assertTrue(convertedTime instanceof Integer);
    assertEquals(1, convertedTime);
  }