@@ -430,43 +430,45 @@ public void dayOfMonth() {
430430 assertEquals (integerValue (8 ), eval (expression ));
431431 }
432432
433+ private void dayOfWeekQuery (
434+ FunctionExpression dateExpression ,
435+ int dayOfWeek ,
436+ String testExpr ) {
437+ assertEquals (INTEGER , dateExpression .type ());
438+ assertEquals (integerValue (dayOfWeek ), eval (dateExpression ));
439+ assertEquals (testExpr , dateExpression .toString ());
440+ }
441+
433442 @ Test
434443 public void dayOfWeek () {
435- when (nullRef .type ()).thenReturn (DATE );
436- when (missingRef .type ()).thenReturn (DATE );
437- assertEquals (nullValue (), eval (DSL .dayofweek (functionProperties , nullRef )));
438- assertEquals (missingValue (), eval (DSL .dayofweek (functionProperties , missingRef )));
444+ lenient ().when (nullRef .valueOf (env )).thenReturn (nullValue ());
445+ lenient ().when (missingRef .valueOf (env )).thenReturn (missingValue ());
439446
440- FunctionExpression expression = DSL .dayofweek (
447+ FunctionExpression expression1 = DSL .dayofweek (
441448 functionProperties ,
442449 DSL .literal (new ExprDateValue ("2020-08-07" )));
443- assertEquals (INTEGER , expression .type ());
444- assertEquals ("dayofweek(DATE '2020-08-07')" , expression .toString ());
445- assertEquals (integerValue (6 ), eval (expression ));
446-
447- expression = DSL .dayofweek (
450+ FunctionExpression expression2 = DSL .dayofweek (
448451 functionProperties ,
449452 DSL .literal (new ExprDateValue ("2020-08-09" )));
450- assertEquals (INTEGER , expression .type ());
451- assertEquals ("dayofweek(DATE '2020-08-09')" , expression .toString ());
452- assertEquals (integerValue (1 ), eval (expression ));
453-
454- expression = DSL .dayofweek (
453+ FunctionExpression expression3 = DSL .dayofweek (
455454 functionProperties ,
456455 DSL .literal ("2020-08-09" ));
457- assertEquals (INTEGER , expression .type ());
458- assertEquals ("dayofweek(\" 2020-08-09\" )" , expression .toString ());
459- assertEquals (integerValue (1 ), eval (expression ));
460-
461- expression = DSL .dayofweek (
456+ FunctionExpression expression4 = DSL .dayofweek (
462457 functionProperties ,
463458 DSL .literal ("2020-08-09 01:02:03" ));
464- assertEquals (INTEGER , expression .type ());
465- assertEquals ("dayofweek(\" 2020-08-09 01:02:03\" )" , expression .toString ());
466- assertEquals (integerValue (1 ), eval (expression ));
459+
460+ assertAll (
461+ () -> dayOfWeekQuery (expression1 , 6 , "dayofweek(DATE '2020-08-07')" ),
462+
463+ () -> dayOfWeekQuery (expression2 , 1 , "dayofweek(DATE '2020-08-09')" ),
464+
465+ () -> dayOfWeekQuery (expression3 , 1 , "dayofweek(\" 2020-08-09\" )" ),
466+
467+ () -> dayOfWeekQuery (expression4 , 1 , "dayofweek(\" 2020-08-09 01:02:03\" )" )
468+ );
467469 }
468470
469- private void testDayOfWeekWithUnderscores (
471+ private void dayOfWeekWithUnderscoresQuery (
470472 FunctionExpression dateExpression ,
471473 int dayOfWeek ,
472474 String testExpr ) {
@@ -494,13 +496,14 @@ public void dayOfWeekWithUnderscores() {
494496 DSL .literal ("2020-08-09 01:02:03" ));
495497
496498 assertAll (
497- () -> testDayOfWeekWithUnderscores (expression1 , 6 , "day_of_week(DATE '2020-08-07')" ),
499+ () -> dayOfWeekWithUnderscoresQuery (expression1 , 6 , "day_of_week(DATE '2020-08-07')" ),
498500
499- () -> testDayOfWeekWithUnderscores (expression2 , 1 , "day_of_week(DATE '2020-08-09')" ),
501+ () -> dayOfWeekWithUnderscoresQuery (expression2 , 1 , "day_of_week(DATE '2020-08-09')" ),
500502
501- () -> testDayOfWeekWithUnderscores (expression3 , 1 , "day_of_week(\" 2020-08-09\" )" ),
503+ () -> dayOfWeekWithUnderscoresQuery (expression3 , 1 , "day_of_week(\" 2020-08-09\" )" ),
502504
503- () -> testDayOfWeekWithUnderscores (expression4 , 1 , "day_of_week(\" 2020-08-09 01:02:03\" )" )
505+ () -> dayOfWeekWithUnderscoresQuery (
506+ expression4 , 1 , "day_of_week(\" 2020-08-09 01:02:03\" )" )
504507 );
505508 }
506509
@@ -511,11 +514,14 @@ public void testDayOfWeekWithTimeType() {
511514 FunctionExpression expression = DSL .day_of_week (
512515 functionProperties , DSL .literal (new ExprTimeValue ("12:23:34" )));
513516
514- assertEquals (INTEGER , eval (expression ).type ());
515- assertEquals ((LocalDate .now (
516- functionProperties .getQueryStartClock ()).getDayOfWeek ().getValue () % 7 ) + 1 ,
517- eval (expression ).integerValue ());
518- assertEquals ("day_of_week(TIME '12:23:34')" , expression .toString ());
517+ assertAll (
518+ () -> assertEquals (INTEGER , eval (expression ).type ()),
519+ () -> assertEquals ((
520+ LocalDate .now (
521+ functionProperties .getQueryStartClock ()).getDayOfWeek ().getValue () % 7 ) + 1 ,
522+ eval (expression ).integerValue ()),
523+ () -> assertEquals ("day_of_week(TIME '12:23:34')" , expression .toString ())
524+ );
519525 }
520526
521527 private void testInvalidDayOfWeek (String date ) {
@@ -529,24 +535,23 @@ public void dayOfWeekWithUnderscoresLeapYear() {
529535 lenient ().when (nullRef .valueOf (env )).thenReturn (nullValue ());
530536 lenient ().when (missingRef .valueOf (env )).thenReturn (missingValue ());
531537
532- //Feb. 29 of a leap year
533- testDayOfWeekWithUnderscores (DSL .day_of_week (
534- functionProperties ,
535- DSL .literal ("2020-02-29" )), 7 , "day_of_week(\" 2020-02-29\" )" );
536-
537- //day after Feb. 29 of a leap year
538- testDayOfWeekWithUnderscores (DSL .day_of_week (
539- functionProperties ,
540- DSL .literal ("2020-03-01" )), 1 , "day_of_week(\" 2020-03-01\" )" );
541-
542- //Feb. 28 of a non-leap year
543- testDayOfWeekWithUnderscores (DSL .day_of_week (
544- functionProperties ,
545- DSL .literal ("2021-02-28" )), 1 , "day_of_week(\" 2021-02-28\" )" );
546-
547- //Feb. 29 of a non-leap year
548- assertThrows (SemanticCheckException .class , () -> testInvalidDayOfWeek ("2021-02-29" ));
549-
538+ assertAll (
539+ //Feb. 29 of a leap year
540+ () -> dayOfWeekWithUnderscoresQuery (DSL .day_of_week (
541+ functionProperties ,
542+ DSL .literal ("2020-02-29" )), 7 , "day_of_week(\" 2020-02-29\" )" ),
543+ //day after Feb. 29 of a leap year
544+ () -> dayOfWeekWithUnderscoresQuery (DSL .day_of_week (
545+ functionProperties ,
546+ DSL .literal ("2020-03-01" )), 1 , "day_of_week(\" 2020-03-01\" )" ),
547+ //Feb. 28 of a non-leap year
548+ () -> dayOfWeekWithUnderscoresQuery (DSL .day_of_week (
549+ functionProperties ,
550+ DSL .literal ("2021-02-28" )), 1 , "day_of_week(\" 2021-02-28\" )" ),
551+ //Feb. 29 of a non-leap year
552+ () -> assertThrows (
553+ SemanticCheckException .class , () -> testInvalidDayOfWeek ("2021-02-29" ))
554+ );
550555 }
551556
552557 @ Test
@@ -556,14 +561,19 @@ public void dayOfWeekWithUnderscoresInvalidArgument() {
556561 assertEquals (nullValue (), eval (DSL .day_of_week (functionProperties , nullRef )));
557562 assertEquals (missingValue (), eval (DSL .day_of_week (functionProperties , missingRef )));
558563
559- //40th day of the month
560- assertThrows (SemanticCheckException .class , () -> testInvalidDayOfWeek ("2021-02-40" ));
564+ assertAll (
565+ //40th day of the month
566+ () -> assertThrows (SemanticCheckException .class ,
567+ () -> testInvalidDayOfWeek ("2021-02-40" )),
561568
562- //13th month of the year
563- assertThrows (SemanticCheckException .class , () -> testInvalidDayOfWeek ("2021-13-29" ));
569+ //13th month of the year
570+ () -> assertThrows (SemanticCheckException .class ,
571+ () -> testInvalidDayOfWeek ("2021-13-29" )),
564572
565- //incorrect format
566- assertThrows (SemanticCheckException .class , () -> testInvalidDayOfWeek ("asdfasdf" ));
573+ //incorrect format
574+ () -> assertThrows (SemanticCheckException .class ,
575+ () -> testInvalidDayOfWeek ("asdfasdf" ))
576+ );
567577 }
568578
569579 @ Test
0 commit comments