clean up the UT
This commit is contained in:
parent
f58d963dbd
commit
a53d0970ea
@ -1,7 +1,5 @@
|
||||
package com.google.refine.tests.expr.functions.date;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
@ -17,7 +15,6 @@ import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.expr.EvalError;
|
||||
import com.google.refine.grel.ControlFunctionRegistry;
|
||||
import com.google.refine.grel.Function;
|
||||
import com.google.refine.tests.RefineTest;
|
||||
@ -59,114 +56,6 @@ public class DatePartTests extends RefineTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateDatePart() throws ParseException {
|
||||
Assert.assertTrue(invoke("datePart") instanceof EvalError);
|
||||
|
||||
// 2018-4-30 23:55:44, cannot use new Date(2018 - 1900, 4 - 1, 30, 23, 55, 44). use below way to get a UTC date:
|
||||
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
Date source = isoFormat.parse("2018-04-30T23:55:44");
|
||||
|
||||
// hours
|
||||
Assert.assertEquals(invoke("datePart", source, "hours"), 23);
|
||||
Assert.assertEquals(invoke("datePart", source, "hour"), 23);
|
||||
Assert.assertEquals(invoke("datePart", source, "h"), 23);
|
||||
|
||||
// minutes
|
||||
Assert.assertEquals(invoke("datePart", source, "minutes"), 55);
|
||||
Assert.assertEquals(invoke("datePart", source, "minute"), 55);
|
||||
Assert.assertEquals(invoke("datePart", source, "min"), 55);
|
||||
|
||||
// seconds
|
||||
Assert.assertEquals(invoke("datePart", source, "seconds"), 44);
|
||||
Assert.assertEquals(invoke("datePart", source, "sec"), 44);
|
||||
Assert.assertEquals(invoke("datePart", source, "s"), 44);
|
||||
|
||||
// milliseconds
|
||||
Assert.assertEquals(invoke("datePart", source, "milliseconds"), 0);
|
||||
Assert.assertEquals(invoke("datePart", source, "ms"), 0);
|
||||
Assert.assertEquals(invoke("datePart", source, "S"), 0);
|
||||
|
||||
// years
|
||||
Assert.assertEquals(invoke("datePart", source, "years"), 2018);
|
||||
Assert.assertEquals(invoke("datePart", source, "year"), 2018);
|
||||
|
||||
// months
|
||||
Assert.assertEquals(invoke("datePart", source, "months"), 4);
|
||||
Assert.assertEquals(invoke("datePart", source, "month"), 4);
|
||||
|
||||
// weeks
|
||||
Assert.assertEquals(invoke("datePart", source, "weeks"), 5);
|
||||
Assert.assertEquals(invoke("datePart", source, "week"), 5);
|
||||
Assert.assertEquals(invoke("datePart", source, "w"), 5);
|
||||
|
||||
// days, day, d
|
||||
Assert.assertEquals(invoke("datePart", source, "days"), 30);
|
||||
Assert.assertEquals(invoke("datePart", source, "day"), 30);
|
||||
Assert.assertEquals(invoke("datePart", source, "d"), 30);
|
||||
|
||||
// weekday
|
||||
Assert.assertEquals(invoke("datePart", source, "weekday"), "Monday");
|
||||
|
||||
// time
|
||||
Assert.assertEquals(invoke("datePart", source, "time"), 1525132544000l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalendarDatePart() throws ParseException {
|
||||
// 2018-4-30 23:55:44
|
||||
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
Date dt = isoFormat.parse("2018-04-30T23:55:44");
|
||||
Calendar source = dateToCalendar(dt);
|
||||
source.set(Calendar.MILLISECOND, 789);
|
||||
|
||||
// hours
|
||||
Assert.assertEquals(invoke("datePart", source, "hours"), 23);
|
||||
Assert.assertEquals(invoke("datePart", source, "hour"), 23);
|
||||
Assert.assertEquals(invoke("datePart", source, "h"), 23);
|
||||
|
||||
// minutes
|
||||
Assert.assertEquals(invoke("datePart", source, "minutes"), 55);
|
||||
Assert.assertEquals(invoke("datePart", source, "minute"), 55);
|
||||
Assert.assertEquals(invoke("datePart", source, "min"), 55);
|
||||
|
||||
// seconds
|
||||
Assert.assertEquals(invoke("datePart", source, "seconds"), 44);
|
||||
Assert.assertEquals(invoke("datePart", source, "sec"), 44);
|
||||
Assert.assertEquals(invoke("datePart", source, "s"), 44);
|
||||
|
||||
// milliseconds
|
||||
Assert.assertEquals(invoke("datePart", source, "milliseconds"), 789);
|
||||
Assert.assertEquals(invoke("datePart", source, "ms"), 789);
|
||||
Assert.assertEquals(invoke("datePart", source, "S"), 789);
|
||||
|
||||
// years
|
||||
Assert.assertEquals(invoke("datePart", source, "years"), 2018);
|
||||
Assert.assertEquals(invoke("datePart", source, "year"), 2018);
|
||||
|
||||
// months
|
||||
Assert.assertEquals(invoke("datePart", source, "months"), 4);
|
||||
Assert.assertEquals(invoke("datePart", source, "month"), 4);
|
||||
|
||||
// weeks
|
||||
Assert.assertEquals(invoke("datePart", source, "weeks"), 5);
|
||||
Assert.assertEquals(invoke("datePart", source, "week"), 5);
|
||||
Assert.assertEquals(invoke("datePart", source, "w"), 5);
|
||||
|
||||
// days, day, d
|
||||
Assert.assertEquals(invoke("datePart", source, "days"), 30);
|
||||
Assert.assertEquals(invoke("datePart", source, "day"), 30);
|
||||
Assert.assertEquals(invoke("datePart", source, "d"), 30);
|
||||
|
||||
// weekday
|
||||
Assert.assertEquals(invoke("datePart", source, "weekday"), "Monday");
|
||||
|
||||
// time
|
||||
Assert.assertEquals(invoke("datePart", source, "time"), 1525132544000l + 789);
|
||||
}
|
||||
|
||||
private DateTimeFormatter formatter = new DateTimeFormatterBuilder()
|
||||
.append(DateTimeFormatter.BASIC_ISO_DATE).appendLiteral('-')
|
||||
.appendPattern("HH:mm:ss")
|
||||
|
Loading…
Reference in New Issue
Block a user