001package ch.qos.logback.core.rolling.helper; 002 003import static org.junit.Assert.assertArrayEquals; 004 005import java.io.File; 006import java.util.Date; 007 008import org.junit.Test; 009 010import ch.qos.logback.core.Context; 011import ch.qos.logback.core.ContextBase; 012 013public class SizeAndTimeBasedArchiveRemoverTest { 014 015 Context context = new ContextBase(); 016 017 @Test 018 public void smoke() { 019 FileNamePattern fileNamePattern = new FileNamePattern("smoke-%d-%i.gz", context); 020 SizeAndTimeBasedArchiveRemover remover = new SizeAndTimeBasedArchiveRemover(fileNamePattern, null); 021 File[] fileArray = new File[2]; 022 File[] expected = new File[2]; 023 024 fileArray[0] = expected[1] = new File("/tmp/smoke-1970-01-01-0.gz"); 025 fileArray[1] = expected[0] = new File("/tmp/smoke-1970-01-01-1.gz"); 026 027 remover.descendingSort(fileArray, new Date(0)); 028 029 assertArrayEquals(expected, fileArray); 030 } 031 032 @Test 033 public void badFilenames() { 034 FileNamePattern fileNamePattern = new FileNamePattern("smoke-%d-%i.gz", context); 035 SizeAndTimeBasedArchiveRemover remover = new SizeAndTimeBasedArchiveRemover(fileNamePattern, null); 036 File[] fileArray = new File[2]; 037 File[] expected = new File[2]; 038 039 fileArray[0] = expected[0] = new File("/tmp/smoke-1970-01-01-b.gz"); 040 fileArray[1] = expected[1] = new File("/tmp/smoke-1970-01-01-c.gz"); 041 042 remover.descendingSort(fileArray, new Date(0)); 043 044 assertArrayEquals(expected, fileArray); 045 } 046}