Skip to content

Commit c664af7

Browse files
Refactored Tests For Day_Of_Year Function
Signed-off-by: GabeFernandez310 <[email protected]>
1 parent 3c843ba commit c664af7

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

core/src/test/java/org/opensearch/sql/expression/datetime/DateTimeFunctionTest.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -492,23 +492,21 @@ public void dayOfYear() {
492492
public void testDayOfYearWithTimeType() {
493493
lenient().when(nullRef.valueOf(env)).thenReturn(nullValue());
494494
lenient().when(missingRef.valueOf(env)).thenReturn(missingValue());
495-
FunctionExpression expression = DSL.day_of_year(
496-
functionProperties,
497-
DSL.literal(new ExprTimeValue("12:23:34")));
498495

499-
assertEquals(INTEGER, eval(expression).type());
500-
assertEquals(LocalDate.now(
501-
functionProperties.getQueryStartClock()).getDayOfYear(),
502-
eval(expression).integerValue());
503-
assertEquals("day_of_year(TIME '12:23:34')", expression.toString());
496+
validateStringFormat(
497+
DSL.day_of_year(functionProperties, DSL.literal(new ExprTimeValue("12:23:34"))),
498+
"day_of_year(TIME '12:23:34')",
499+
LocalDate.now(functionProperties.getQueryStartClock()).getDayOfYear());
504500
}
505501

506502
public void dayOfYearWithUnderscoresQuery(String date, int dayOfYear) {
507503
FunctionExpression expression = DSL.day_of_year(
508504
functionProperties,
509505
DSL.literal(new ExprDateValue(date)));
510-
assertEquals(INTEGER, expression.type());
511-
assertEquals(integerValue(dayOfYear), eval(expression));
506+
assertAll(
507+
() -> assertEquals(INTEGER, expression.type()),
508+
() -> assertEquals(integerValue(dayOfYear), eval(expression))
509+
);
512510
}
513511

514512
@Test
@@ -589,19 +587,26 @@ public void invalidDayOfYearQuery(String date) {
589587
public void invalidDayOfYearArgument() {
590588
when(nullRef.type()).thenReturn(DATE);
591589
when(missingRef.type()).thenReturn(DATE);
592-
assertEquals(nullValue(), eval(DSL.day_of_year(
593-
functionProperties,
594-
nullRef)));
595-
assertEquals(missingValue(), eval(DSL.day_of_year(
596-
functionProperties,
597-
missingRef)));
598590

599-
//29th of Feb non-leapyear
600-
assertThrows(SemanticCheckException.class, () -> invalidDayOfYearQuery("2019-02-29"));
601-
//13th month
602-
assertThrows(SemanticCheckException.class, () -> invalidDayOfYearQuery("2019-13-15"));
603-
//incorrect format for type
604-
assertThrows(SemanticCheckException.class, () -> invalidDayOfYearQuery("asdfasdfasdf"));
591+
assertAll(
592+
() -> assertEquals(nullValue(), eval(DSL.day_of_year(functionProperties, nullRef))),
593+
() -> assertEquals(missingValue(), eval(DSL.day_of_year(functionProperties, missingRef))),
594+
595+
//29th of Feb non-leapyear
596+
() -> assertThrows(
597+
SemanticCheckException.class,
598+
() -> invalidDayOfYearQuery("2019-02-29")),
599+
600+
//13th month
601+
() -> assertThrows(
602+
SemanticCheckException.class,
603+
() -> invalidDayOfYearQuery("2019-13-15")),
604+
605+
//incorrect format for type
606+
() -> assertThrows(
607+
SemanticCheckException.class,
608+
() -> invalidDayOfYearQuery("asdfasdfasdf"))
609+
);
605610
}
606611

607612
@Test

0 commit comments

Comments
 (0)