public class RollingAppenderTimeAndSizeTest {

  private static final String CONFIG = "log4j-rolling3.xml";

  private static final String DIR = "target/rolling3/test";

  public static LoggerContextRule loggerContextRule =
      LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG);

  @Rule public RuleChain chain = loggerContextRule.withCleanFoldersRule(DIR);

  private Logger logger;

  @Before
  public void setUp() throws Exception {
    this.logger = loggerContextRule.getLogger(RollingAppenderTimeAndSizeTest.class.getName());
  }

  @Test
  public void testAppender() throws Exception {
    for (int i = 0; i < 100; ++i) {
      logger.debug("This is test message number " + i);
    }
    Thread.sleep(50);
    final File dir = new File(DIR);
    assertTrue("Directory not created", dir.exists() && dir.listFiles().length > 0);
    final File[] files = dir.listFiles();
    assertNotNull(files);
    assertThat(files, hasItemInArray(that(hasName(that(endsWith(".gz"))))));
  }
}
 @Before
 public void setUp() throws Exception {
   this.logger = loggerContextRule.getLogger(RollingAppenderTimeAndSizeTest.class.getName());
 }