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.helper;
015
016import ch.qos.logback.core.rolling.RolloverFailure;
017import ch.qos.logback.core.testUtil.CoreTestConstants;
018import ch.qos.logback.core.testUtil.RandomUtil;
019import ch.qos.logback.core.util.EnvUtil;
020import ch.qos.logback.core.util.FileUtil;
021import org.junit.Ignore;
022import org.junit.Test;
023
024import java.io.File;
025import java.io.IOException;
026
027import static org.junit.Assert.assertFalse;
028import static org.junit.Assert.assertTrue;
029
030public class FileStoreUtilTest {
031
032    int diff = RandomUtil.getPositiveInt();
033    String pathPrefix = CoreTestConstants.OUTPUT_DIR_PREFIX + "fs" + diff + "/";
034
035    @Test
036    public void filesOnSameFolderShouldBeOnTheSameFileStore() throws RolloverFailure, IOException {
037        if (!EnvUtil.isJDK7OrHigher())
038            return;
039
040        File parent = new File(pathPrefix);
041        File file = new File(pathPrefix + "filesOnSameFolderShouldBeOnTheSameFileStore");
042        FileUtil.createMissingParentDirectories(file);
043        file.createNewFile();
044        assertTrue(FileStoreUtil.areOnSameFileStore(parent, file));
045    }
046
047    // test should be run manually
048    @Ignore
049    @Test
050    public void manual_filesOnDifferentVolumesShouldBeDetectedAsSuch() throws RolloverFailure {
051        if (!EnvUtil.isJDK7OrHigher())
052            return;
053
054        // author's computer has two volumes
055        File c = new File("c:/tmp/");
056        File d = new File("d:/");
057        assertFalse(FileStoreUtil.areOnSameFileStore(c, d));
058    }
059}