001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.rolling;
015
016import ch.qos.logback.core.testUtil.CoreTestConstants;
017import ch.qos.logback.core.util.Compare;
018
019import java.io.IOException;
020import java.util.List;
021
022import static org.junit.Assert.assertTrue;
023
024public class DefaultRolloverChecker implements RolloverChecker {
025
026    final String testId;
027    final boolean withCompression;
028    final String compressionSuffix;
029
030    public DefaultRolloverChecker(String testId, boolean withCompression, String compressionSuffix) {
031        this.testId = testId;
032        this.withCompression = withCompression;
033        this.compressionSuffix = compressionSuffix;
034    }
035
036    public void check(List<String> expectedFilenameList) throws IOException {
037
038        int i = 0;
039        for (String fn : expectedFilenameList) {
040            String suffix = withCompression ? addGZIfNotLast(expectedFilenameList, i, compressionSuffix) : "";
041
042            String witnessFileName = CoreTestConstants.TEST_SRC_PREFIX + "witness/rolling/tbr-" + testId + "." + i + suffix;
043            assertTrue(Compare.compare(fn, witnessFileName));
044            i++;
045        }
046    }
047
048    String addGZIfNotLast(List<String> expectedFilenameList, int i, String suff) {
049        int lastIndex = expectedFilenameList.size() - 1;
050        return (i != lastIndex) ? suff : "";
051    }
052}