1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.helpers;
15
16 import ch.qos.logback.core.Context;
17 import ch.qos.logback.core.ContextBase;
18 import ch.qos.logback.core.rolling.helper.FileFilterUtil;
19 import ch.qos.logback.core.rolling.helper.FileNamePattern;
20 import org.junit.jupiter.api.Assertions;
21 import org.junit.jupiter.api.Test;
22
23 import java.io.File;
24 import java.text.ParseException;
25 import java.text.SimpleDateFormat;
26
27 public class FileFilterUtilTest {
28
29 Context context = new ContextBase();
30
31
32 @Test
33 public void findHighestCounterTest() throws ParseException {
34 String[] sa = new String[] { "c:/log/debug-old-2010-08-10.0.log", "c:/log/debug-old-2010-08-10.1.log",
35 "c:/log/debug-old-2010-08-10.10.log", "c:/log/debug-old-2010-08-10.11.log",
36 "c:/log/debug-old-2010-08-10.12.log", "c:/log/debug-old-2010-08-10.2.log",
37 "c:/log/debug-old-2010-08-10.3.log", "c:/log/debug-old-2010-08-10.4.log",
38 "c:/log/debug-old-2010-08-10.5.log", "c:/log/debug-old-2010-08-10.6.log",
39 "c:/log/debug-old-2010-08-10.7.log", "c:/log/debug-old-2010-08-10.8.log",
40 "c:/log/debug-old-2010-08-10.9.log" };
41
42 File[] matchingFileArray = new File[sa.length];
43 for (int i = 0; i < sa.length; i++) {
44 matchingFileArray[i] = new File(sa[i]);
45 }
46 FileNamePattern fnp = new FileNamePattern("c:/log/debug-old-%d{yyyy-MM-dd}.%i.log", context);
47 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
48 String rexexp = null;
49 rexexp = fnp.toRegexForFixedDate(sdf.parse("2010-08-10"));
50 String stemRegex = FileFilterUtil.afterLastSlash(rexexp);
51 int result = FileFilterUtil.findHighestCounter(matchingFileArray, stemRegex);
52 Assertions.assertEquals(12, result);
53 }
54 }