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