1717package org .apache .logging .log4j .core .util .internal .instant ;
1818
1919import static java .util .Arrays .asList ;
20+ import static java .util .Collections .singletonList ;
2021import static org .apache .logging .log4j .core .util .internal .instant .InstantPatternDynamicFormatter .sequencePattern ;
2122import static org .assertj .core .api .Assertions .assertThat ;
2223
3132import java .util .stream .IntStream ;
3233import java .util .stream .Stream ;
3334import org .apache .logging .log4j .core .time .MutableInstant ;
34- import org .apache .logging .log4j .core .util .internal .instant .InstantPatternDynamicFormatter .DateTimeFormatterPatternFormatterFactory ;
35- import org .apache .logging .log4j .core .util .internal .instant .InstantPatternDynamicFormatter .PatternFormatterFactory ;
36- import org .apache .logging .log4j .core .util .internal .instant .InstantPatternDynamicFormatter .SecondPatternFormatterFactory ;
35+ import org .apache .logging .log4j .core .util .internal .instant .InstantPatternDynamicFormatter .DateTimeFormatterPatternSequence ;
36+ import org .apache .logging .log4j .core .util .internal .instant .InstantPatternDynamicFormatter .PatternSequence ;
37+ import org .apache .logging .log4j .core .util .internal .instant .InstantPatternDynamicFormatter .SecondPatternSequence ;
38+ import org .apache .logging .log4j .core .util .internal .instant .InstantPatternDynamicFormatter .StaticPatternSequence ;
3739import org .apache .logging .log4j .util .Constants ;
3840import org .junit .jupiter .params .ParameterizedTest ;
3941import org .junit .jupiter .params .provider .Arguments ;
@@ -45,75 +47,76 @@ class InstantPatternDynamicFormatterTest {
4547 @ ParameterizedTest
4648 @ MethodSource ("sequencingTestCases" )
4749 void sequencing_should_work (
48- final String pattern ,
49- final ChronoUnit thresholdPrecision ,
50- final List <PatternFormatterFactory > expectedSequences ) {
51- final List <PatternFormatterFactory > actualSequences = sequencePattern (pattern , thresholdPrecision );
50+ final String pattern , final ChronoUnit thresholdPrecision , final List <PatternSequence > expectedSequences ) {
51+ final List <PatternSequence > actualSequences = sequencePattern (pattern , thresholdPrecision );
5252 assertThat (actualSequences ).isEqualTo (expectedSequences );
5353 }
5454
5555 static List <Arguments > sequencingTestCases () {
5656 final List <Arguments > testCases = new ArrayList <>();
5757
58+ // Merged constants
59+ testCases .add (Arguments .of (":'foo'," , ChronoUnit .DAYS , singletonList (new StaticPatternSequence (":foo," ))));
60+
5861 // `SSSX` should be treated constant for daily updates
59- testCases .add (Arguments .of ("SSSX" , ChronoUnit .DAYS , asList (pMilliSec (), pDyn ("X" ))));
62+ testCases .add (Arguments .of ("SSSX" , ChronoUnit .DAYS , asList (pMilliSec (), pDtf ("X" ))));
6063
6164 // `yyyyMMddHHmmssSSSX` instant cache updated hourly
6265 testCases .add (Arguments .of (
6366 "yyyyMMddHHmmssSSSX" ,
6467 ChronoUnit .HOURS ,
65- asList (pDyn ("yyyyMMddHH" , ChronoUnit .HOURS ), pDyn ("mm" ), pSec ("" , 3 ), pDyn ("X" ))));
68+ asList (pDtf ("yyyyMMddHH" , ChronoUnit .HOURS ), pDtf ("mm" ), pSec ("" , 3 ), pDtf ("X" ))));
6669
6770 // `yyyyMMddHHmmssSSSX` instant cache updated per minute
6871 testCases .add (Arguments .of (
6972 "yyyyMMddHHmmssSSSX" ,
7073 ChronoUnit .MINUTES ,
71- asList (pDyn ("yyyyMMddHHmm" , ChronoUnit .MINUTES ), pSec ("" , 3 ), pDyn ("X" ))));
74+ asList (pDtf ("yyyyMMddHHmm" , ChronoUnit .MINUTES ), pSec ("" , 3 ), pDtf ("X" ))));
7275
7376 // ISO9601 instant cache updated daily
7477 final String iso8601InstantPattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX" ;
7578 testCases .add (Arguments .of (
7679 iso8601InstantPattern ,
7780 ChronoUnit .DAYS ,
7881 asList (
79- pDyn ("yyyy'-'MM'-'dd'T'" , ChronoUnit .DAYS ),
80- pDyn ("HH':'mm':'" , ChronoUnit .MINUTES ),
82+ pDtf ("yyyy'-'MM'-'dd'T'" , ChronoUnit .DAYS ),
83+ pDtf ("HH':'mm':'" , ChronoUnit .MINUTES ),
8184 pSec ("." , 3 ),
82- pDyn ("X" ))));
85+ pDtf ("X" ))));
8386
8487 // ISO9601 instant cache updated per minute
8588 testCases .add (Arguments .of (
8689 iso8601InstantPattern ,
8790 ChronoUnit .MINUTES ,
88- asList (pDyn ("yyyy'-'MM'-'dd'T'HH':'mm':'" , ChronoUnit .MINUTES ), pSec ("." , 3 ), pDyn ("X" ))));
91+ asList (pDtf ("yyyy'-'MM'-'dd'T'HH':'mm':'" , ChronoUnit .MINUTES ), pSec ("." , 3 ), pDtf ("X" ))));
8992
9093 // ISO9601 instant cache updated per second
9194 testCases .add (Arguments .of (
9295 iso8601InstantPattern ,
9396 ChronoUnit .SECONDS ,
94- asList (pDyn ("yyyy'-'MM'-'dd'T'HH':'mm':'" , ChronoUnit .MINUTES ), pSec ("." , 3 ), pDyn ("X" ))));
97+ asList (pDtf ("yyyy'-'MM'-'dd'T'HH':'mm':'" , ChronoUnit .MINUTES ), pSec ("." , 3 ), pDtf ("X" ))));
9598
9699 // Seconds and micros
97100 testCases .add (Arguments .of (
98- "HH:mm:ss.SSSSSS" , ChronoUnit .MINUTES , asList (pDyn ("HH':'mm':'" , ChronoUnit .MINUTES ), pSec ("." , 6 ))));
101+ "HH:mm:ss.SSSSSS" , ChronoUnit .MINUTES , asList (pDtf ("HH':'mm':'" , ChronoUnit .MINUTES ), pSec ("." , 6 ))));
99102
100103 return testCases ;
101104 }
102105
103- private static DateTimeFormatterPatternFormatterFactory pDyn (final String pattern ) {
104- return new DateTimeFormatterPatternFormatterFactory ( pattern );
106+ private static DateTimeFormatterPatternSequence pDtf (final String simplePattern ) {
107+ return new DateTimeFormatterPatternSequence ( simplePattern );
105108 }
106109
107- private static DateTimeFormatterPatternFormatterFactory pDyn (final String pattern , final ChronoUnit precision ) {
108- return new DateTimeFormatterPatternFormatterFactory (pattern , precision );
110+ private static DateTimeFormatterPatternSequence pDtf (final String pattern , final ChronoUnit precision ) {
111+ return new DateTimeFormatterPatternSequence (pattern , precision );
109112 }
110113
111- private static SecondPatternFormatterFactory pSec (String separator , int fractionalDigits ) {
112- return new SecondPatternFormatterFactory (true , separator , fractionalDigits );
114+ private static SecondPatternSequence pSec (String separator , int fractionalDigits ) {
115+ return new SecondPatternSequence (true , separator , fractionalDigits );
113116 }
114117
115- private static SecondPatternFormatterFactory pMilliSec () {
116- return new SecondPatternFormatterFactory (false , "" , 3 );
118+ private static SecondPatternSequence pMilliSec () {
119+ return new SecondPatternSequence (false , "" , 3 );
117120 }
118121
119122 @ ParameterizedTest
0 commit comments