2121import  static  org .junit .jupiter .api .Assertions .assertTrue ;
2222
2323import  java .nio .file .attribute .FileTime ;
24+ import  java .time .Duration ;
2425import  org .apache .logging .log4j .core .test .appender .rolling .action .DummyFileAttributes ;
26+ import  org .apache .logging .log4j .core .time .Clock ;
27+ import  org .apache .logging .log4j .core .time .ClockFactory ;
2528import  org .junit .jupiter .api .Test ;
2629
2730/** 
2831 * Tests the IfLastModified class. 
2932 */ 
3033public  class  IfLastModifiedTest  {
3134
35+     private  static  final  Clock  CLOCK  = ClockFactory .getClock ();
36+ 
3237    @ Test 
3338    public  void  testGetDurationReturnsConstructorValue () {
34-         final  IfLastModified  filter  =
35-                 IfLastModified .newBuilder ().setAge (Duration .parse ("P7D" )).get ();
39+         final  IfLastModified  filter  = IfLastModified .newBuilder ()
40+                 .setAge (Duration .parse ("P7D" ))
41+                 .setClock (CLOCK )
42+                 .get ();
3643        assertEquals (0 , filter .getAge ().compareTo (Duration .parse ("P7D" )));
3744    }
3845
3946    @ Test 
4047    public  void  testAcceptsIfFileAgeEqualToDuration () {
41-         final  IfLastModified  filter  =
42-                 IfLastModified .newBuilder ().setAge (Duration .parse ("PT33S" )).get ();
48+         final  IfLastModified  filter  = IfLastModified .newBuilder ()
49+                 .setAge (Duration .parse ("PT33S" ))
50+                 .setClock (CLOCK )
51+                 .get ();
4352        final  DummyFileAttributes  attrs  = new  DummyFileAttributes ();
4453        final  long  age  = 33  * 1000 ;
4554        attrs .lastModified  = FileTime .fromMillis (System .currentTimeMillis () - age );
@@ -48,8 +57,10 @@ public void testAcceptsIfFileAgeEqualToDuration() {
4857
4958    @ Test 
5059    public  void  testAcceptsIfFileAgeExceedsDuration () {
51-         final  IfLastModified  filter  =
52-                 IfLastModified .newBuilder ().setAge (Duration .parse ("PT33S" )).get ();
60+         final  IfLastModified  filter  = IfLastModified .newBuilder ()
61+                 .setAge (Duration .parse ("PT33S" ))
62+                 .setClock (CLOCK )
63+                 .get ();
5364        final  DummyFileAttributes  attrs  = new  DummyFileAttributes ();
5465        final  long  age  = 33  * 1000  + 5 ;
5566        attrs .lastModified  = FileTime .fromMillis (System .currentTimeMillis () - age );
@@ -58,8 +69,10 @@ public void testAcceptsIfFileAgeExceedsDuration() {
5869
5970    @ Test 
6071    public  void  testDoesNotAcceptIfFileAgeLessThanDuration () {
61-         final  IfLastModified  filter  =
62-                 IfLastModified .newBuilder ().setAge (Duration .parse ("PT33S" )).get ();
72+         final  IfLastModified  filter  = IfLastModified .newBuilder ()
73+                 .setAge (Duration .parse ("PT33S" ))
74+                 .setClock (CLOCK )
75+                 .get ();
6376        final  DummyFileAttributes  attrs  = new  DummyFileAttributes ();
6477        final  long  age  = 33  * 1000  - 5 ;
6578        attrs .lastModified  = FileTime .fromMillis (System .currentTimeMillis () - age );
@@ -72,6 +85,7 @@ public void testAcceptCallsNestedConditionsOnlyIfPathAccepted() {
7285        final  IfLastModified  filter  = IfLastModified .newBuilder ()
7386                .setAge (Duration .parse ("PT33S" ))
7487                .setNestedConditions (counter )
88+                 .setClock (CLOCK )
7589                .get ();
7690        final  DummyFileAttributes  attrs  = new  DummyFileAttributes ();
7791        final  long  oldEnough  = 33  * 1000  + 5 ;
@@ -100,6 +114,7 @@ public void testBeforeTreeWalk() {
100114        final  IfLastModified  filter  = IfLastModified .newBuilder ()
101115                .setAge (Duration .parse ("PT33S" ))
102116                .setNestedConditions (counter , counter , counter )
117+                 .setClock (CLOCK )
103118                .get ();
104119        filter .beforeFileTreeWalk ();
105120        assertEquals (3 , counter .getBeforeFileTreeWalkCount ());
0 commit comments