View Javadoc
1   package ch.qos.logback.core.rolling.helper;
2   
3   import static org.junit.Assert.assertArrayEquals;
4   
5   import java.io.File;
6   import java.util.Date;
7   
8   import org.junit.Test;
9   
10  import ch.qos.logback.core.Context;
11  import ch.qos.logback.core.ContextBase;
12  
13  public class SizeAndTimeBasedArchiveRemoverTest {
14  
15      Context context = new ContextBase();
16  
17      @Test
18      public void smoke() {
19          FileNamePattern fileNamePattern = new FileNamePattern("smoke-%d-%i.gz", context);
20          SizeAndTimeBasedArchiveRemover remover = new SizeAndTimeBasedArchiveRemover(fileNamePattern, null);
21          File[] fileArray = new File[2];
22          File[] expected = new File[2];
23  
24          fileArray[0] = expected[1] = new File("/tmp/smoke-1970-01-01-0.gz");
25          fileArray[1] = expected[0] = new File("/tmp/smoke-1970-01-01-1.gz");
26  
27          remover.descendingSort(fileArray, new Date(0));
28  
29          assertArrayEquals(expected, fileArray);
30      }
31      
32      @Test
33      public void badFilenames() {
34          FileNamePattern fileNamePattern = new FileNamePattern("smoke-%d-%i.gz", context);
35          SizeAndTimeBasedArchiveRemover remover = new SizeAndTimeBasedArchiveRemover(fileNamePattern, null);
36          File[] fileArray = new File[2];
37          File[] expected = new File[2];
38  
39          fileArray[0] = expected[0] = new File("/tmp/smoke-1970-01-01-b.gz");
40          fileArray[1] = expected[1] = new File("/tmp/smoke-1970-01-01-c.gz");
41  
42          remover.descendingSort(fileArray, new Date(0));
43  
44          assertArrayEquals(expected, fileArray);
45      }
46  }