View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.rolling;
15  
16  import ch.qos.logback.core.testUtil.CoreTestConstants;
17  import ch.qos.logback.core.util.Compare;
18  
19  import java.io.IOException;
20  import java.util.List;
21  
22  import static org.junit.Assert.assertTrue;
23  
24  public class DefaultRolloverChecker implements RolloverChecker {
25  
26      final String testId;
27      final boolean withCompression;
28      final String compressionSuffix;
29  
30      public DefaultRolloverChecker(String testId, boolean withCompression, String compressionSuffix) {
31          this.testId = testId;
32          this.withCompression = withCompression;
33          this.compressionSuffix = compressionSuffix;
34      }
35  
36      public void check(List<String> expectedFilenameList) throws IOException {
37  
38          int i = 0;
39          for (String fn : expectedFilenameList) {
40              String suffix = withCompression ? addGZIfNotLast(expectedFilenameList, i, compressionSuffix) : "";
41  
42              String witnessFileName = CoreTestConstants.TEST_SRC_PREFIX + "witness/rolling/tbr-" + testId + "." + i + suffix;
43              assertTrue(Compare.compare(fn, witnessFileName));
44              i++;
45          }
46      }
47  
48      String addGZIfNotLast(List<String> expectedFilenameList, int i, String suff) {
49          int lastIndex = expectedFilenameList.size() - 1;
50          return (i != lastIndex) ? suff : "";
51      }
52  }