java.io.file

Here are the examples of the java api class java.io.file taken from open source projects.

1. UtilityTest#testDelete()

Project: oodt
Source File: UtilityTest.java
View license
public void testDelete() throws IOException {
    File top = File.createTempFile("topdir", ".dir");
    top.delete();
    top.mkdir();
    File f1 = File.createTempFile("nesteddir", ".file", top);
    File f2 = File.createTempFile("nesteddir", ".file", top);
    File d1 = File.createTempFile("nesteddir", ".dir", top);
    d1.delete();
    d1.mkdir();
    File f3 = File.createTempFile("nesteddir", ".file", d1);
    File d2 = File.createTempFile("nesteddir", ".dir", d1);
    d2.delete();
    d2.mkdir();
    File f4 = File.createTempFile("nesteddir", ".file", d2);
    assertTrue(Utility.delete(top));
    assertTrue(!top.exists());
}

2. TestClusterProviderImpl#testCopyDirectory()

View license
@Test
public void testCopyDirectory() throws Exception {
    File copyTempDir = new File(tempDir, "copy");
    File srcDir = new File(copyTempDir, "somedir");
    File dstDir = new File(copyTempDir, "dst");
    Assert.assertTrue(srcDir.mkdirs());
    Assert.assertTrue(dstDir.mkdirs());
    File link1 = new File(copyTempDir, "link1");
    File link2 = new File(copyTempDir, "link2");
    File dir1 = new File(copyTempDir, "dir1");
    File file1 = new File(dir1, "f1");
    File file2 = new File(dir1, "f2");
    Assert.assertTrue(dir1.mkdirs());
    Assert.assertTrue(file1.createNewFile());
    Assert.assertTrue(file2.createNewFile());
    file2.setReadable(false);
    file2.setWritable(false);
    file2.setExecutable(false);
    Files.createSymbolicLink(link1.toPath(), dir1.toPath());
    Files.createSymbolicLink(link2.toPath(), link1.toPath());
    Files.createSymbolicLink(new File(srcDir, "dir1").toPath(), link2.toPath());
    File clone = ClusterProviderImpl.createDirectoryClone(srcDir, srcDir.getName(), dstDir);
    File cloneF1 = new File(new File(clone, "dir1"), "f1");
    Assert.assertTrue(cloneF1.isFile());
}

3. JobTask#initializeFileVariables()

Project: hydra
Source File: JobTask.java
View license
void initializeFileVariables() {
    jobDir = getLiveDir();
    File configDir = getConfigDir();
    logDir = new File(jobDir, "log");
    logOut = new File(logDir, "log.out");
    logErr = new File(logDir, "log.err");
    jobPid = new File(configDir, "job.pid");
    replicatePid = new File(configDir, "replicate.pid");
    backupPid = new File(configDir, "backup.pid");
    jobPort = new File(jobDir, "job.port");
    jobDone = new File(configDir, "job.done");
    replicateDone = new File(configDir, "replicate.done");
    backupDone = new File(configDir, "backup.done");
}

4. CompositeImageProcessorTest#testProcess()

View license
/**
     * Test method for
     * [email protected] com.alibaba.simpleimage.CompositeImageProcessor#process(java.io.InputStream, com.alibaba.simpleimage.render.DrawTextParameter, com.alibaba.simpleimage.render.ScaleParameter, com.alibaba.simpleimage.render.WriteParameter)}
     * .
     */
public void testProcess() throws Exception {
    CompositeImageProcessor processor = new CompositeImageProcessor();
    List<File> images = new ArrayList<File>();
    File imgDir = new File(sourceDir, "bmp");
    for (File img : imgDir.listFiles()) {
        images.add(img);
    }
    imgDir = new File(sourceDir, "cmyk");
    for (File img : imgDir.listFiles()) {
        images.add(img);
    }
    imgDir = new File(sourceDir, "gif");
    for (File img : imgDir.listFiles()) {
        images.add(img);
    }
    imgDir = new File(sourceDir, "gray");
    for (File img : imgDir.listFiles()) {
        images.add(img);
    }
    imgDir = new File(sourceDir, "rgb");
    for (File img : imgDir.listFiles()) {
        images.add(img);
    }
    imgDir = new File(sourceDir, "malformed");
    for (File img : imgDir.listFiles()) {
        images.add(img);
    }
    imgDir = new File(sourceDir, "quality");
    for (File img : imgDir.listFiles()) {
        images.add(img);
    }
    imgDir = new File(sourceDir, "scale");
    for (File img : imgDir.listFiles()) {
        images.add(img);
    }
    imgDir = new File(sourceDir, "png");
    for (File img : imgDir.listFiles()) {
        images.add(img);
    }
    imgDir = new File(sourceDir, "tiff");
    for (File img : imgDir.listFiles()) {
        images.add(img);
    }
    assertTrue(DEFAULT_SCALE_PARAM.getAlgorithm() == ScaleParameter.Algorithm.AUTO);
    assertTrue(DEFAULT_SCALE_PARAM.getMaxHeight() == 1024);
    assertTrue(DEFAULT_SCALE_PARAM.getMaxWidth() == 1024);
    for (File img : images) {
        if (img.isDirectory()) {
            continue;
        }
        if (img.getName().indexOf("result") > 0) {
            continue;
        }
        // ignore this image 
        if ("input_256_matte.tiff".equalsIgnoreCase(img.getName())) {
            continue;
        }
        FileInputStream inputStream = null;
        FileOutputStream outputStream = null;
        InputStream inputToStore = null;
        File outputFile = null;
        boolean check = true;
        InputStream memoryStream = null;
        String suffix = ".jpg";
        try {
            check = true;
            inputStream = new FileInputStream(img);
            memoryStream = ImageUtils.createMemoryStream(inputStream);
            if (ImageUtils.isGIF(memoryStream)) {
                suffix = ".gif";
            }
            DrawTextParameter dtp = createDrawTextParameter("??????", true, true);
            inputToStore = ((ByteArrayOutputStream) processor.process(memoryStream, dtp, DEFAULT_SCALE_PARAM.getMaxWidth(), DEFAULT_SCALE_PARAM.getMaxHeight())).toInputStream();
            String outputName = img.getName().substring(0, img.getName().indexOf("."));
            outputFile = new File(rpath, "COMPOSITETEST_" + outputName + suffix);
            outputStream = new FileOutputStream(outputFile);
            IOUtils.copy(inputToStore, outputStream);
            outputStream.flush();
        } catch (Exception e) {
            check = false;
        } finally {
            IOUtils.closeQuietly(inputStream);
            IOUtils.closeQuietly(inputToStore);
            IOUtils.closeQuietly(outputStream);
            IOUtils.closeQuietly(memoryStream);
        }
        if (check) {
            check(img, outputFile);
        }
    }
}

5. AndroidMavenPluginTest#validateRepo()

View license
private void validateRepo(File projectFolder) {
    File repo = new File(projectFolder, "build/repo/org/test/simple");
    assertTrue(repo.getPath() + " does not exists", repo.exists());
    File metadata = new File(repo, "maven-metadata.xml");
    File metadataMd5 = new File(repo, "maven-metadata.xml.md5");
    File metadataSha1 = new File(repo, "maven-metadata.xml.sha1");
    assertTrue(metadata.getPath() + " does not exists", metadata.exists());
    assertTrue(metadataMd5.getPath() + " does not exists", metadataMd5.exists());
    assertTrue(metadataSha1.getPath() + " does not exists", metadataSha1.exists());
    File aar = new File(repo, "1.0/simple-1.0.aar");
    File aarMd5 = new File(repo, "1.0/simple-1.0.aar.md5");
    File aarSha1 = new File(repo, "1.0/simple-1.0.aar.sha1");
    assertTrue(aar.getPath() + " does not exists", aar.exists());
    assertTrue(aarMd5.getPath() + " does not exists", aarMd5.exists());
    assertTrue(aarSha1.getPath() + " does not exists", aarSha1.exists());
    File pom = new File(repo, "1.0/simple-1.0.pom");
    File pomMd5 = new File(repo, "1.0/simple-1.0.pom.md5");
    File pomSha1 = new File(repo, "1.0/simple-1.0.pom.sha1");
    assertTrue(pom.getPath() + " does not exists", pom.exists());
    assertTrue(pomMd5.getPath() + " does not exists", pomMd5.exists());
    assertTrue(pomSha1.getPath() + " does not exists", pomSha1.exists());
}

6. FileAppenderBenchmark#deleteLogFiles()

View license
private void deleteLogFiles() {
    final File logbackFile = new File("target/testlogback.log");
    logbackFile.delete();
    final File log4jFile = new File("target/testlog4j.log");
    log4jFile.delete();
    final File log4jRandomFile = new File("target/testRandomlog4j2.log");
    log4jRandomFile.delete();
    final File log4j2File = new File("target/testlog4j2.log");
    log4j2File.delete();
    final File julFile = new File("target/testJulLog.log");
    julFile.delete();
}

7. FileAppenderParamsBenchmark#deleteLogFiles()

View license
private void deleteLogFiles() {
    final File logbackFile = new File("target/testlogback.log");
    logbackFile.delete();
    final File log4jFile = new File("target/testlog4j.log");
    log4jFile.delete();
    final File log4jRandomFile = new File("target/testRandomlog4j2.log");
    log4jRandomFile.delete();
    final File log4j2File = new File("target/testlog4j2.log");
    log4j2File.delete();
    final File julFile = new File("target/testJulLog.log");
    julFile.delete();
}

8. LocalizationUtilsTest#testJar()

Project: cdap
Source File: LocalizationUtilsTest.java
View license
@Test
public void testJar() throws IOException {
    String jarFileName = "target";
    File directory = TEMP_FOLDER.newFolder("jar");
    File libDir = new File(directory, "lib");
    Assert.assertTrue(libDir.mkdirs());
    File someClassFile = File.createTempFile("SomeClass", ".class", directory);
    File someOtherClassFile = File.createTempFile("SomeOtherClass", ".class", directory);
    File jarFile = createZipFile(jarFileName, directory, true);
    File localizationDir = TEMP_FOLDER.newFolder("localJar");
    File localizedResource = LocalizationUtils.localizeResource(jarFileName, new LocalizeResource(jarFile, true), localizationDir);
    Assert.assertTrue(localizedResource.isDirectory());
    File[] files = localizedResource.listFiles();
    Assert.assertNotNull(files);
    Assert.assertEquals(3, files.length);
    for (File file : files) {
        String name = file.getName();
        if (libDir.getName().equals(name)) {
            Assert.assertTrue(file.isDirectory());
        } else {
            Assert.assertTrue(someClassFile.getName().equals(name) || someOtherClassFile.getName().equals(name));
        }
    }
}

9. CoveragePerTestMediumTest#createTestFiles()

View license
private File createTestFiles() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File testDir = new File(baseDir, "test");
    testDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "foo");
    File xooFile2 = new File(srcDir, "sample2.xoo");
    FileUtils.write(xooFile2, "foo");
    File xooTestFile = new File(testDir, "sampleTest.xoo");
    FileUtils.write(xooTestFile, "failure\nerror\nok\nskipped");
    File xooTestFile2 = new File(testDir, "sample2Test.xoo");
    FileUtils.write(xooTestFile2, "test file tests");
    return baseDir;
}

10. FilePathTest#moveAllChildrenTo()

Project: Jenkins2
Source File: FilePathTest.java
View license
@Issue("JENKINS-16846")
@Test
public void moveAllChildrenTo() throws IOException, InterruptedException {
    File tmp = temp.getRoot();
    final String dirname = "sub";
    final File top = new File(tmp, "test");
    final File sub = new File(top, dirname);
    final File subsub = new File(sub, dirname);
    subsub.mkdirs();
    final File subFile1 = new File(sub.getAbsolutePath() + "/file1.txt");
    subFile1.createNewFile();
    final File subFile2 = new File(subsub.getAbsolutePath() + "/file2.txt");
    subFile2.createNewFile();
    final FilePath src = new FilePath(sub);
    final FilePath dst = new FilePath(top);
    // test conflict subdir
    src.moveAllChildrenTo(dst);
}

11. FileUtilTest#shouldReturnTrueWhenTwoFolderHasSameStructure()

Project: gocd
Source File: FileUtilTest.java
View license
@Test
public void shouldReturnTrueWhenTwoFolderHasSameStructure() throws Exception {
    File root = createTempDirectory();
    File folder1 = new File(root, "folder1");
    folder1.mkdirs();
    File file1 = new File(folder1, "readme.txt");
    file1.createNewFile();
    File folder2 = new File(root, "folder2");
    folder2.mkdirs();
    File file2 = new File(folder2, "readme.txt");
    file2.createNewFile();
    assertThat(FileUtil.isStructureSame(folder1, folder2), is(true));
}

12. FileUtilTest#shouldReturnFalseWhenTwoFolderHasDifferentStructure()

Project: gocd
Source File: FileUtilTest.java
View license
@Test
public void shouldReturnFalseWhenTwoFolderHasDifferentStructure() throws Exception {
    File root = createTempDirectory();
    File folder1 = new File(root, "folder1");
    folder1.mkdirs();
    File file1 = new File(folder1, "readme.txt");
    file1.createNewFile();
    File folder2 = new File(root, "folder2");
    folder2.mkdirs();
    File file2 = new File(folder2, "readx.txt");
    file2.createNewFile();
    assertThat(FileUtil.isStructureSame(folder1, folder2), is(false));
}

13. FilePathTest#moveAllChildrenTo()

Project: hudson
Source File: FilePathTest.java
View license
@Issue("JENKINS-16846")
@Test
public void moveAllChildrenTo() throws IOException, InterruptedException {
    File tmp = temp.getRoot();
    final String dirname = "sub";
    final File top = new File(tmp, "test");
    final File sub = new File(top, dirname);
    final File subsub = new File(sub, dirname);
    subsub.mkdirs();
    final File subFile1 = new File(sub.getAbsolutePath() + "/file1.txt");
    subFile1.createNewFile();
    final File subFile2 = new File(subsub.getAbsolutePath() + "/file2.txt");
    subFile2.createNewFile();
    final FilePath src = new FilePath(sub);
    final FilePath dst = new FilePath(top);
    // test conflict subdir
    src.moveAllChildrenTo(dst);
}

14. TestBackupNode#setUp()

Project: hadoop-hdfs
Source File: TestBackupNode.java
View license
protected void setUp() throws Exception {
    super.setUp();
    File baseDir = new File(BASE_DIR);
    if (baseDir.exists())
        if (!(FileUtil.fullyDelete(baseDir)))
            throw new IOException("Cannot remove directory: " + baseDir);
    File dirC = new File(getBackupNodeDir(StartupOption.CHECKPOINT, 1));
    dirC.mkdirs();
    File dirB = new File(getBackupNodeDir(StartupOption.BACKUP, 1));
    dirB.mkdirs();
    dirB = new File(getBackupNodeDir(StartupOption.BACKUP, 2));
    dirB.mkdirs();
}

15. FileUtilsDirectoryContainsTestCase#setUp()

View license
@SuppressWarnings("ResultOfMethodCallIgnored")
@Before
public void setUp() throws Exception {
    top.mkdirs();
    directory1 = new File(top, "directory1");
    directory2 = new File(top, "directory2");
    directory3 = new File(directory2, "directory3");
    directory1.mkdir();
    directory2.mkdir();
    directory3.mkdir();
    file1 = new File(directory1, "file1");
    file2 = new File(directory2, "file2");
    file3 = new File(top, "file3");
    // Tests case with relative path
    file1ByRelativeDirectory2 = new File(getTestDirectory(), "directory2/../directory1/file1");
    file2ByRelativeDirectory1 = new File(getTestDirectory(), "directory1/../directory2/file2");
    FileUtils.touch(file1);
    FileUtils.touch(file2);
    FileUtils.touch(file3);
}

16. TestProdTypePatternMetExtractor#setup()

View license
@Before
public void setup() throws Exception {
    URL url = getClass().getResource("/product-type-patterns.xml");
    configFile = new File(url.toURI());
    extractor = new ProdTypePatternMetExtractor();
    extractor.setConfigFile(configFile);
    tmpDir = Files.createTempDir();
    book1 = new File(tmpDir, "book-1234567890.txt");
    book2 = new File(tmpDir, "book-0987654321.txt");
    page1 = new File(tmpDir, "page-1234567890-111.txt");
    page2 = new File(tmpDir, "page-0987654321-222.txt");
    Files.touch(book1);
    Files.touch(book2);
    Files.touch(page1);
    Files.touch(page2);
    url = getClass().getResource("/product-type-patterns-2.xml");
    configFile2 = new File(url.toURI());
    page1a = new File(tmpDir, "page-111-1234567890.txt");
    page2a = new File(tmpDir, "page-222-0987654321.txt");
    Files.touch(page1a);
    Files.touch(page2a);
}

17. IgnoredFilesTest#testDirIsIgnored()

View license
@Test
public void testDirIsIgnored() throws Exception {
    //final String dirPath1 = myClientRoot.getPath() + "/a";
    final File dir = new File(myClientRoot, "a");
    dir.mkdir();
    final File innerDir = new File(dir, "innerDir");
    innerDir.mkdir();
    final File file1 = new File(innerDir, "file1");
    final File file2 = new File(innerDir, "file2");
    file1.createNewFile();
    file2.createNewFile();
    final VirtualFile innerVf = myLocalFileSystem.refreshAndFindFileByIoFile(innerDir);
    final VirtualFile vf1 = myLocalFileSystem.refreshAndFindFileByIoFile(file1);
    final VirtualFile vf2 = myLocalFileSystem.refreshAndFindFileByIoFile(file2);
    final IgnoredFileBean ignoredFileBean = IgnoredBeanFactory.ignoreUnderDirectory(FileUtil.toSystemIndependentName(dir.getPath()), myProject);
    myChangeListManager.addFilesToIgnore(ignoredFileBean);
    dirty();
    assertFoundAndIgnored(innerVf);
    assertFoundAndIgnored(vf1);
    assertFoundAndIgnored(vf2);
}

18. IgnoredFilesTest#testDirIsIgnored()

View license
@Test
public void testDirIsIgnored() throws Exception {
    //final String dirPath1 = myClientRoot.getPath() + "/a";
    final File dir = new File(myClientRoot, "a");
    dir.mkdir();
    final File innerDir = new File(dir, "innerDir");
    innerDir.mkdir();
    final File file1 = new File(innerDir, "file1");
    final File file2 = new File(innerDir, "file2");
    file1.createNewFile();
    file2.createNewFile();
    final VirtualFile innerVf = myLocalFileSystem.refreshAndFindFileByIoFile(innerDir);
    final VirtualFile vf1 = myLocalFileSystem.refreshAndFindFileByIoFile(file1);
    final VirtualFile vf2 = myLocalFileSystem.refreshAndFindFileByIoFile(file2);
    final IgnoredFileBean ignoredFileBean = IgnoredBeanFactory.ignoreUnderDirectory(FileUtil.toSystemIndependentName(dir.getPath()), myProject);
    myChangeListManager.addFilesToIgnore(ignoredFileBean);
    dirty();
    assertFoundAndIgnored(innerVf);
    assertFoundAndIgnored(vf1);
    assertFoundAndIgnored(vf2);
}

19. KaaClientPropertiesStateTest#getProperties()

View license
public static KaaClientProperties getProperties() throws IOException {
    KaaClientProperties props = new KaaClientProperties();
    props.setProperty(KaaClientProperties.WORKING_DIR_PROPERTY, WORK_DIR);
    props.setProperty(KaaClientProperties.STATE_FILE_NAME_PROPERTY, STATE_PROPERTIES);
    props.setProperty(KaaClientProperties.CLIENT_PUBLIC_KEY_FILE_NAME_PROPERTY, KEY_PUBLIC);
    File dir = new File(WORK_DIR);
    dir.deleteOnExit();
    File pub = new File(WORK_DIR + KEY_PUBLIC);
    pub.deleteOnExit();
    props.setProperty(KaaClientProperties.CLIENT_PRIVATE_KEY_FILE_NAME_PROPERTY, KEY_PRIVATE);
    File priv = new File(WORK_DIR + KEY_PRIVATE);
    priv.deleteOnExit();
    File state = new File(WORK_DIR + STATE_PROPERTIES);
    state.deleteOnExit();
    props.setProperty(KaaClientProperties.TRANSPORT_POLL_DELAY, "0");
    props.setProperty(KaaClientProperties.TRANSPORT_POLL_PERIOD, "1");
    props.setProperty(KaaClientProperties.TRANSPORT_POLL_UNIT, "SECONDS");
    props.setProperty(KaaClientProperties.SDK_TOKEN, "123456");
    return props;
}

20. FileUtilTest#testIsFileUTF8()

Project: ps3mediaserver
Source File: FileUtilTest.java
View license
@Test
public void testIsFileUTF8() throws Exception {
    File file_utf8 = FileUtils.toFile(CLASS.getResource("russian-utf8-without-bom.srt"));
    assertThat(FileUtil.isFileUTF8(file_utf8)).isTrue();
    File file_utf8_2 = FileUtils.toFile(CLASS.getResource("russian-utf8-with-bom.srt"));
    assertThat(FileUtil.isFileUTF8(file_utf8_2)).isTrue();
    File file_utf8_3 = FileUtils.toFile(CLASS.getResource("english-utf8-with-bom.srt"));
    assertThat(FileUtil.isFileUTF8(file_utf8_3)).isTrue();
    File file_utf_16 = FileUtils.toFile(CLASS.getResource("russian-utf16-le.srt"));
    assertThat(FileUtil.isFileUTF8(file_utf_16)).isFalse();
    File file_utf_16_2 = FileUtils.toFile(CLASS.getResource("russian-utf16-be.srt"));
    assertThat(FileUtil.isFileUTF8(file_utf_16_2)).isFalse();
    File file_cp1251 = FileUtils.toFile(CLASS.getResource("russian-cp1251.srt"));
    assertThat(FileUtil.isFileUTF8(file_cp1251)).isFalse();
    File file_ch = FileUtils.toFile(CLASS.getResource("chinese-gb18030.srt"));
    assertThat(FileUtil.isFileUTF8(file_ch)).isFalse();
    File file_ch_2 = FileUtils.toFile(CLASS.getResource("chinese-big5.srt"));
    assertThat(FileUtil.isFileUTF8(file_ch_2)).isFalse();
}

21. FileUtilTest#testIsFileUTF16()

Project: ps3mediaserver
Source File: FileUtilTest.java
View license
@Test
public void testIsFileUTF16() throws Exception {
    File file_utf8 = FileUtils.toFile(CLASS.getResource("russian-utf8-without-bom.srt"));
    assertThat(FileUtil.isFileUTF16(file_utf8)).isFalse();
    File file_utf8_2 = FileUtils.toFile(CLASS.getResource("russian-utf8-with-bom.srt"));
    assertThat(FileUtil.isFileUTF16(file_utf8_2)).isFalse();
    File file_utf8_3 = FileUtils.toFile(CLASS.getResource("english-utf8-with-bom.srt"));
    assertThat(FileUtil.isFileUTF16(file_utf8_3)).isFalse();
    File file_utf_16 = FileUtils.toFile(CLASS.getResource("russian-utf16-le.srt"));
    assertThat(FileUtil.isFileUTF16(file_utf_16)).isTrue();
    File file_utf_16_2 = FileUtils.toFile(CLASS.getResource("russian-utf16-be.srt"));
    assertThat(FileUtil.isFileUTF16(file_utf_16_2)).isTrue();
    File file_cp1251 = FileUtils.toFile(CLASS.getResource("russian-cp1251.srt"));
    assertThat(FileUtil.isFileUTF16(file_cp1251)).isFalse();
    File file_ch = FileUtils.toFile(CLASS.getResource("chinese-gb18030.srt"));
    assertThat(FileUtil.isFileUTF16(file_ch)).isFalse();
    File file_ch_2 = FileUtils.toFile(CLASS.getResource("chinese-big5.srt"));
    assertThat(FileUtil.isFileUTF16(file_ch_2)).isFalse();
}

22. FileUtilTest#testIsFileUTF8()

View license
@Test
public void testIsFileUTF8() throws Exception {
    File file_utf8 = FileUtils.toFile(CLASS.getResource("russian-utf8-without-bom.srt"));
    assertThat(FileUtil.isFileUTF8(file_utf8)).isTrue();
    File file_utf8_2 = FileUtils.toFile(CLASS.getResource("russian-utf8-with-bom.srt"));
    assertThat(FileUtil.isFileUTF8(file_utf8_2)).isTrue();
    File file_utf8_3 = FileUtils.toFile(CLASS.getResource("english-utf8-with-bom.srt"));
    assertThat(FileUtil.isFileUTF8(file_utf8_3)).isTrue();
    File file_utf_16 = FileUtils.toFile(CLASS.getResource("russian-utf16-le.srt"));
    assertThat(FileUtil.isFileUTF8(file_utf_16)).isFalse();
    File file_utf_16_2 = FileUtils.toFile(CLASS.getResource("russian-utf16-be.srt"));
    assertThat(FileUtil.isFileUTF8(file_utf_16_2)).isFalse();
    File file_cp1251 = FileUtils.toFile(CLASS.getResource("russian-cp1251.srt"));
    assertThat(FileUtil.isFileUTF8(file_cp1251)).isFalse();
    File file_ch = FileUtils.toFile(CLASS.getResource("chinese-gb18030.srt"));
    assertThat(FileUtil.isFileUTF8(file_ch)).isFalse();
    File file_ch_2 = FileUtils.toFile(CLASS.getResource("chinese-big5.srt"));
    assertThat(FileUtil.isFileUTF8(file_ch_2)).isFalse();
}

23. FileUtilTest#testIsFileUTF16()

View license
@Test
public void testIsFileUTF16() throws Exception {
    File file_utf8 = FileUtils.toFile(CLASS.getResource("russian-utf8-without-bom.srt"));
    assertThat(FileUtil.isFileUTF16(file_utf8)).isFalse();
    File file_utf8_2 = FileUtils.toFile(CLASS.getResource("russian-utf8-with-bom.srt"));
    assertThat(FileUtil.isFileUTF16(file_utf8_2)).isFalse();
    File file_utf8_3 = FileUtils.toFile(CLASS.getResource("english-utf8-with-bom.srt"));
    assertThat(FileUtil.isFileUTF16(file_utf8_3)).isFalse();
    File file_utf_16 = FileUtils.toFile(CLASS.getResource("russian-utf16-le.srt"));
    assertThat(FileUtil.isFileUTF16(file_utf_16)).isTrue();
    File file_utf_16_2 = FileUtils.toFile(CLASS.getResource("russian-utf16-be.srt"));
    assertThat(FileUtil.isFileUTF16(file_utf_16_2)).isTrue();
    File file_cp1251 = FileUtils.toFile(CLASS.getResource("russian-cp1251.srt"));
    assertThat(FileUtil.isFileUTF16(file_cp1251)).isFalse();
    File file_ch = FileUtils.toFile(CLASS.getResource("chinese-gb18030.srt"));
    assertThat(FileUtil.isFileUTF16(file_ch)).isFalse();
    File file_ch_2 = FileUtils.toFile(CLASS.getResource("chinese-big5.srt"));
    assertThat(FileUtil.isFileUTF16(file_ch_2)).isFalse();
}

24. SSTableUtils#tempSSTableFile()

Project: cassandra
Source File: SSTableUtils.java
View license
/*
    public static ColumnFamily createCF(long mfda, int ldt, Cell... cols)
    {
        return createCF(KEYSPACENAME, CFNAME, mfda, ldt, cols);
    }

    public static ColumnFamily createCF(String ksname, String cfname, long mfda, int ldt, Cell... cols)
    {
        ColumnFamily cf = ArrayBackedSortedColumns.factory.create(ksname, cfname);
        cf.delete(new DeletionInfo(mfda, ldt));
        for (Cell col : cols)
            cf.addColumn(col);
        return cf;
    }

    public static File tempSSTableFile(String keyspaceName, String cfname) throws IOException
    {
        return tempSSTableFile(keyspaceName, cfname, 0);
    }
    */
public static File tempSSTableFile(String keyspaceName, String cfname, int generation) throws IOException {
    File tempdir = File.createTempFile(keyspaceName, cfname);
    if (!tempdir.delete() || !tempdir.mkdir())
        throw new IOException("Temporary directory creation failed.");
    tempdir.deleteOnExit();
    File cfDir = new File(tempdir, keyspaceName + File.separator + cfname);
    cfDir.mkdirs();
    cfDir.deleteOnExit();
    File datafile = new File(new Descriptor(cfDir, keyspaceName, cfname, generation).filenameFor(Component.DATA));
    if (!datafile.createNewFile())
        throw new IOException("unable to create file " + datafile);
    datafile.deleteOnExit();
    return datafile;
}

25. LocalizationUtilsTest#testZip()

Project: cdap
Source File: LocalizationUtilsTest.java
View license
@Test
public void testZip() throws IOException {
    String zipFileName = "target";
    File directory = TEMP_FOLDER.newFolder("zip");
    File file1 = File.createTempFile("file1", ".txt", directory);
    File file2 = File.createTempFile("file2", ".txt", directory);
    File zipFile = createZipFile(zipFileName, directory, false);
    File localizationDir = TEMP_FOLDER.newFolder("localZip");
    File localizedResource = LocalizationUtils.localizeResource(zipFileName, new LocalizeResource(zipFile, true), localizationDir);
    Assert.assertTrue(localizedResource.isDirectory());
    File[] files = localizedResource.listFiles();
    Assert.assertNotNull(files);
    Assert.assertEquals(2, files.length);
    if (file1.getName().equals(files[0].getName())) {
        Assert.assertEquals(file2.getName(), files[1].getName());
    } else {
        Assert.assertEquals(file1.getName(), files[1].getName());
        Assert.assertEquals(file2.getName(), files[0].getName());
    }
}

26. ContentCacheImplTest#canVisitOldestDirsFirst()

View license
@Test
public void canVisitOldestDirsFirst() {
    File cacheRoot = new File(TempFileProvider.getTempDir(), GUID.generate());
    cacheRoot.deleteOnExit();
    contentCache.setCacheRoot(cacheRoot);
    File f1 = tempfile(createDirs("2000/3/30/17/45/31"), "files-are-unsorted.bin");
    File f2 = tempfile(createDirs("2000/3/4/17/45/31"), "another-file.bin");
    File f3 = tempfile(createDirs("2010/12/24/23/59/58"), "a-second-before.bin");
    File f4 = tempfile(createDirs("2010/12/24/23/59/59"), "last-one.bin");
    File f5 = tempfile(createDirs("2000/1/7/2/7/12"), "first-one.bin");
    // Check that directories and files are visited in correct order
    FileHandler handler = Mockito.mock(FileHandler.class);
    contentCache.processFiles(handler);
    InOrder inOrder = Mockito.inOrder(handler);
    inOrder.verify(handler).handle(f5);
    inOrder.verify(handler).handle(f2);
    inOrder.verify(handler).handle(f1);
    inOrder.verify(handler).handle(f3);
    inOrder.verify(handler).handle(f4);
}

27. FileWatcherTest#testDirectoryMixed()

Project: consulo
Source File: FileWatcherTest.java
View license
public void testDirectoryMixed() throws Exception {
    File topDir = createTestDir("top");
    File watchedFile1 = createTestFile(topDir, "test.txt");
    File sub1Dir = createTestDir(topDir, "sub1");
    File unwatchedFile = createTestFile(sub1Dir, "test.txt");
    File sub2Dir = createTestDir(topDir, "sub2");
    File sub2subDir = createTestDir(sub2Dir, "sub");
    File watchedFile2 = createTestFile(sub2subDir, "test.txt");
    refresh(topDir);
    LocalFileSystem.WatchRequest topRequest = watch(topDir, false);
    LocalFileSystem.WatchRequest subRequest = watch(sub2Dir);
    try {
        myAccept = true;
        FileUtil.writeToFile(watchedFile1, "new content");
        FileUtil.writeToFile(watchedFile2, "new content");
        FileUtil.writeToFile(unwatchedFile, "new content");
        assertEvent(VFileContentChangeEvent.class, watchedFile1.getPath(), watchedFile2.getPath());
    } finally {
        unwatch(subRequest, topRequest);
        delete(topDir);
    }
}

28. TestGlobDirectoryStream#testNoOpenDirectoryStreams()

View license
@Test
public void testNoOpenDirectoryStreams() throws IOException {
    File baseDir = new File("target", UUID.randomUUID().toString()).getAbsoluteFile();
    File nestedDir1 = new File(baseDir, "x");
    Assert.assertTrue(nestedDir1.mkdirs());
    File nestedDir2 = new File(baseDir, "y");
    Assert.assertTrue(nestedDir2.mkdirs());
    File file1 = new File(nestedDir1, "x.txt");
    File file2 = new File(nestedDir2, "y.txt");
    File file3 = new File(nestedDir2, "x.txt");
    File file4 = new File(nestedDir2, "x.x");
    Files.createFile(file1.toPath());
    Files.createFile(file2.toPath());
    Files.createFile(file3.toPath());
    Files.createFile(file4.toPath());
    GlobDirectoryStream dsRef;
    try (GlobDirectoryStream ds = new GlobDirectoryStream(baseDir.toPath(), Paths.get("*/*.txt"))) {
        dsRef = ds;
        Iterator<Path> it = ds.iterator();
        it.hasNext();
        it.next();
    }
    Assert.assertEquals(0, dsRef.getOpenCounter());
}

29. InitializationTest#test06GetClassLoaderForExtension()

Project: druid
Source File: InitializationTest.java
View license
@Test
public void test06GetClassLoaderForExtension() throws IOException {
    final File some_extension_dir = temporaryFolder.newFolder();
    final File a_jar = new File(some_extension_dir, "a.jar");
    final File b_jar = new File(some_extension_dir, "b.jar");
    final File c_jar = new File(some_extension_dir, "c.jar");
    a_jar.createNewFile();
    b_jar.createNewFile();
    c_jar.createNewFile();
    final URLClassLoader loader = Initialization.getClassLoaderForExtension(some_extension_dir);
    final URL[] expectedURLs = new URL[] { a_jar.toURI().toURL(), b_jar.toURI().toURL(), c_jar.toURI().toURL() };
    final URL[] actualURLs = loader.getURLs();
    Arrays.sort(actualURLs, new Comparator<URL>() {

        @Override
        public int compare(URL o1, URL o2) {
            return o1.getPath().compareTo(o2.getPath());
        }
    });
    Assert.assertArrayEquals(expectedURLs, actualURLs);
}

30. InitializationTest#testGetExtensionFilesToLoad_null_load_list()

Project: druid
Source File: InitializationTest.java
View license
/**
   * If druid.extension.load is not specified, Initialization.getExtensionFilesToLoad is supposed to return all the
   * extension folders under root extensions directory.
   */
@Test
public void testGetExtensionFilesToLoad_null_load_list() throws IOException {
    final File extensionsDir = temporaryFolder.newFolder();
    final ExtensionsConfig config = new ExtensionsConfig() {

        @Override
        public String getDirectory() {
            return extensionsDir.getAbsolutePath();
        }
    };
    final File mysql_metadata_storage = new File(extensionsDir, "mysql-metadata-storage");
    final File druid_kafka_eight = new File(extensionsDir, "druid-kafka-eight");
    mysql_metadata_storage.mkdir();
    druid_kafka_eight.mkdir();
    final File[] expectedFileList = new File[] { druid_kafka_eight, mysql_metadata_storage };
    final File[] actualFileList = Initialization.getExtensionFilesToLoad(config);
    Arrays.sort(actualFileList);
    Assert.assertArrayEquals(expectedFileList, actualFileList);
}

31. InitializationTest#testGetHadoopDependencyFilesToLoad_with_hadoop_coordinates()

Project: druid
Source File: InitializationTest.java
View license
@Test
public void testGetHadoopDependencyFilesToLoad_with_hadoop_coordinates() throws IOException {
    final File rootHadoopDependenciesDir = temporaryFolder.newFolder();
    final ExtensionsConfig config = new ExtensionsConfig() {

        @Override
        public String getHadoopDependenciesDir() {
            return rootHadoopDependenciesDir.getAbsolutePath();
        }
    };
    final File hadoopClient = new File(rootHadoopDependenciesDir, "hadoop-client");
    final File versionDir = new File(hadoopClient, "2.3.0");
    hadoopClient.mkdir();
    versionDir.mkdir();
    final File[] expectedFileList = new File[] { versionDir };
    final File[] actualFileList = Initialization.getHadoopDependencyFilesToLoad(ImmutableList.of("org.apache.hadoop:hadoop-client:2.3.0"), config);
    Assert.assertArrayEquals(expectedFileList, actualFileList);
}

32. Settings#clearAllLogs()

Project: ATLauncher
Source File: Settings.java
View license
public void clearAllLogs() {
    File logFile1 = new File(getBaseDir(), Constants.LAUNCHER_NAME + "-Log-1.txt");
    File logFile2 = new File(getBaseDir(), Constants.LAUNCHER_NAME + "-Log-2.txt");
    File logFile3 = new File(getBaseDir(), Constants.LAUNCHER_NAME + "-Log-3.txt");
    if (logFile3.exists()) {
        Utils.delete(logFile3);
    }
    if (logFile2.exists()) {
        Utils.delete(logFile2);
    }
    if (logFile1.exists()) {
        Utils.delete(logFile1);
    }
    for (File file : this.logsDir.listFiles(Utils.getLogsFileFilter())) {
        if (file.getName().equals(LoggingThread.filename)) {
            // Skip current log
            continue;
        }
        Utils.delete(file);
    }
}

33. FileUtil#upgradeTickerFile()

Project: bither-android
Source File: FileUtil.java
View license
public static void upgradeTickerFile() {
    File marketDir = getMarketCache();
    File file = new File(marketDir, BITSTAMP_TICKER_NAME);
    fileExistAndDelete(file);
    file = new File(marketDir, BTCE_TICKER_NAME);
    fileExistAndDelete(file);
    file = new File(marketDir, HUOBI_TICKER_NAME);
    fileExistAndDelete(file);
    file = new File(marketDir, OKCOIN_TICKER_NAME);
    fileExistAndDelete(file);
    file = new File(marketDir, CHBTC_TICKER_NAME);
    fileExistAndDelete(file);
    file = new File(marketDir, BTCCHINA_TICKER_NAME);
    fileExistAndDelete(file);
}

34. SaveProfileJob#createDirAndFile()

Project: scouter
Source File: SaveProfileJob.java
View license
private void createDirAndFile() {
    File xlogDir = new File(workingDir);
    if (xlogDir.exists() == false) {
        xlogDir.mkdirs();
    }
    File xlogFile = new File(xlogDir, xLogFileName);
    if (xlogFile.exists()) {
        xlogFile.delete();
    }
    File profFile = new File(xlogDir, profileFileName);
    if (profFile.exists()) {
        profFile.delete();
    }
    File profsumFile = new File(xlogDir, profileSummaryFileName);
    if (profsumFile.exists()) {
        profsumFile.delete();
    }
}

35. CanonicalSessionMigrator#migrateSession()

View license
private static void migrateSession(File sessionFile, File sessionsDirectory, long canonicalAddress) {
    File canonicalSessionFile = new File(sessionsDirectory.getAbsolutePath() + File.separatorChar + canonicalAddress);
    sessionFile.renameTo(canonicalSessionFile);
    Log.w("CanonicalSessionMigrator", "Moving: " + sessionFile.toString() + " to " + canonicalSessionFile.toString());
    File canonicalSessionFileLocal = new File(sessionsDirectory.getAbsolutePath() + File.separatorChar + canonicalAddress + "-local");
    File localFile = new File(sessionFile.getAbsolutePath() + "-local");
    if (localFile.exists())
        localFile.renameTo(canonicalSessionFileLocal);
    Log.w("CanonicalSessionMigrator", "Moving " + localFile + " to " + canonicalSessionFileLocal);
    File canonicalSessionFileRemote = new File(sessionsDirectory.getAbsolutePath() + File.separatorChar + canonicalAddress + "-remote");
    File remoteFile = new File(sessionFile.getAbsolutePath() + "-remote");
    if (remoteFile.exists())
        remoteFile.renameTo(canonicalSessionFileRemote);
    Log.w("CanonicalSessionMigrator", "Moving " + remoteFile + " to " + canonicalSessionFileRemote);
}

36. WarLauncherTests#explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath()

Project: spring-boot
Source File: WarLauncherTests.java
View license
@Test
public void explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath() throws Exception {
    File warRoot = new File("target/exploded-war");
    FileSystemUtils.deleteRecursively(warRoot);
    warRoot.mkdirs();
    File webInfClasses = new File(warRoot, "WEB-INF/classes");
    webInfClasses.mkdirs();
    File webInfLib = new File(warRoot, "WEB-INF/lib");
    webInfLib.mkdirs();
    File webInfLibFoo = new File(webInfLib, "foo.jar");
    new JarOutputStream(new FileOutputStream(webInfLibFoo)).close();
    WarLauncher launcher = new WarLauncher(new ExplodedArchive(warRoot, true));
    List<Archive> archives = launcher.getClassPathArchives();
    assertThat(archives).hasSize(2);
    assertThat(getUrls(archives)).containsOnly(webInfClasses.toURI().toURL(), new URL("jar:" + webInfLibFoo.toURI().toURL() + "!/"));
}

37. SSTableUtils#tempSSTableFile()

Project: stratio-cassandra
Source File: SSTableUtils.java
View license
public static File tempSSTableFile(String keyspaceName, String cfname, int generation) throws IOException {
    File tempdir = File.createTempFile(keyspaceName, cfname);
    if (!tempdir.delete() || !tempdir.mkdir())
        throw new IOException("Temporary directory creation failed.");
    tempdir.deleteOnExit();
    File keyspaceDir = new File(tempdir, keyspaceName);
    keyspaceDir.mkdir();
    keyspaceDir.deleteOnExit();
    File datafile = new File(new Descriptor(keyspaceDir, keyspaceName, cfname, generation, Descriptor.Type.FINAL).filenameFor("Data.db"));
    if (!datafile.createNewFile())
        throw new IOException("unable to create file " + datafile);
    datafile.deleteOnExit();
    return datafile;
}

38. TestLocalDataTransferer#setUp()

Project: oodt
Source File: TestLocalDataTransferer.java
View license
public void setUp() throws Exception {
    transfer = (LocalDataTransferer) new LocalDataTransferFactory().createDataTransfer();
    URL url = this.getClass().getResource("/test.txt");
    origFile = new File(url.getFile());
    File testFile = File.createTempFile("test", ".txt");
    testDir = new File(testFile.getParentFile(), UUID.randomUUID().toString());
    repoDir = new File(testDir, "repo");
    if (!repoDir.mkdirs()) {
        throw new Exception("Failed to create repo directory!");
    }
    repoFile = new File(repoDir, "test.txt");
    destDir = new File(testDir, "dest");
    if (!destDir.mkdirs()) {
        throw new Exception("Failed to create destination directory!");
    }
    destFile = new File(destDir, "test.txt");
}

39. IgvToolsGuiTest#testSortName_FolderPeriods()

Project: igv
Source File: IgvToolsGuiTest.java
View license
/**
     * Copy a file into a folder with periods in the name,
     * check that the default naming functions properly (rather than
     * splitting on the first period we want to split on the last)
     * @throws Exception
     */
@Test
public void testSortName_FolderPeriods() throws Exception {
    String fname = "Unigene.sample.bed";
    File baseInputFile = new File(TestUtils.DATA_DIR + "bed", fname);
    File inputFile = new File(TestUtils.DATA_DIR + "folder.with.periods", fname);
    inputFile.delete();
    inputFile.deleteOnExit();
    FileUtils.copyFile(baseInputFile, inputFile);
    String output = IgvToolsGui.getDefaultOutputText(inputFile.getAbsolutePath(), IgvToolsGui.Tool.SORT);
    File outputFile = new File(output);
    outputFile.delete();
    outputFile.deleteOnExit();
    //The file doesn't actually exist, but we should
    //be able to write to the path
    assertFalse(outputFile.exists());
    FileWriter writer = new FileWriter(outputFile);
    assertNotNull(writer);
}

40. SymlinkHandlingTest#testSidewaysRecursiveLink()

View license
@Test
public void testSidewaysRecursiveLink() throws Exception {
    File target = myTempDir.newFolder("dir_a");
    File link1Home = createTestDir(target, "dir_b");
    File link1 = createSymLink(SystemInfo.isWindows ? target.getPath() : "../../" + target.getName(), link1Home.getPath() + "/link1");
    File mainDir = myTempDir.newFolder("project");
    File subDir = createTestDir(mainDir, "dir_c");
    File link2Home = createTestDir(subDir, "dir_d");
    File link2 = createSymLink(SystemInfo.isWindows ? target.getPath() : "../../../" + target.getName(), link2Home.getPath() + "/link2");
    assertVisitedPaths(mainDir, subDir.getPath(), link2Home.getPath(), link2.getPath(), link2.getPath() + "/" + link1Home.getName(), link2.getPath() + "/" + link1Home.getName() + "/" + link1.getName());
}

41. FileIOChannelFactoryTest#testMatchMultipleWithSubdirectoryExpansion()

View license
@Test
public void testMatchMultipleWithSubdirectoryExpansion() throws Exception {
    File matchedSubDir = temporaryFolder.newFolder("a");
    File matchedSubDirFile = File.createTempFile("sub-dir-file", "", matchedSubDir);
    matchedSubDirFile.deleteOnExit();
    File unmatchedSubDir = temporaryFolder.newFolder("b");
    File unmatchedSubDirFile = File.createTempFile("sub-dir-file", "", unmatchedSubDir);
    unmatchedSubDirFile.deleteOnExit();
    List<String> expected = ImmutableList.of(matchedSubDirFile.toString(), temporaryFolder.newFile("aa").toString(), temporaryFolder.newFile("ab").toString());
    temporaryFolder.newFile("ba");
    temporaryFolder.newFile("bb");
    // Windows doesn't like resolving paths with * in them, so the ** is appended after resolve.
    assertThat(factory.match(factory.resolve(temporaryFolder.getRoot().getPath(), "a") + "**"), Matchers.hasItems(expected.toArray(new String[expected.size()])));
}

42. FileWritingTest#fileNestedClasses()

Project: javapoet
Source File: FileWritingTest.java
View license
@Test
public void fileNestedClasses() throws IOException {
    TypeSpec type = TypeSpec.classBuilder("Test").build();
    JavaFile.builder("foo", type).build().writeTo(tmp.getRoot());
    JavaFile.builder("foo.bar", type).build().writeTo(tmp.getRoot());
    JavaFile.builder("foo.bar.baz", type).build().writeTo(tmp.getRoot());
    File fooDir = new File(tmp.getRoot(), "foo");
    File fooFile = new File(fooDir, "Test.java");
    File barDir = new File(fooDir, "bar");
    File barFile = new File(barDir, "Test.java");
    File bazDir = new File(barDir, "baz");
    File bazFile = new File(bazDir, "Test.java");
    assertThat(fooFile.exists()).isTrue();
    assertThat(barFile.exists()).isTrue();
    assertThat(bazFile.exists()).isTrue();
}

43. LayeredModulePathTest#createOverlays()

View license
private void createOverlays(final File root, final String name, boolean addOn, String... overlays) throws IOException {
    final File system = new File(root, "system");
    final File layers = addOn ? new File(system, "add-ons") : new File(system, "layers");
    final File repo = new File(layers, name);
    final File overlaysRoot = new File(repo, ".overlays");
    overlaysRoot.mkdir();
    final File overlaysConfig = new File(overlaysRoot, ".overlays");
    final OutputStream os = new FileOutputStream(overlaysConfig);
    try {
        for (final String overlay : overlays) {
            os.write(overlay.getBytes());
            os.write('\n');
        }
    } finally {
        if (os != null)
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
}

44. UtilTest#testDeleteContentsRecursive()

Project: Jenkins2
Source File: UtilTest.java
View license
@Test
public void testDeleteContentsRecursive() throws Exception {
    final File dir = tmp.newFolder();
    final File d1 = new File(dir, "d1");
    final File d2 = new File(dir, "d2");
    final File f1 = new File(dir, "f1");
    final File d1f1 = new File(d1, "d1f1");
    final File d2f2 = new File(d2, "d1f2");
    // Test: Files and directories are deleted
    mkdirs(dir, d1, d2);
    mkfiles(f1, d1f1, d2f2);
    Util.deleteContentsRecursive(dir);
    assertTrue("dir exists", dir.exists());
    assertFalse("d1 exists", d1.exists());
    assertFalse("d2 exists", d2.exists());
    assertFalse("f1 exists", f1.exists());
}

45. UtilTest#testDeleteRecursive()

Project: Jenkins2
Source File: UtilTest.java
View license
@Test
public void testDeleteRecursive() throws Exception {
    final File dir = tmp.newFolder();
    final File d1 = new File(dir, "d1");
    final File d2 = new File(dir, "d2");
    final File f1 = new File(dir, "f1");
    final File d1f1 = new File(d1, "d1f1");
    final File d2f2 = new File(d2, "d1f2");
    // Test: Files and directories are deleted
    mkdirs(dir, d1, d2);
    mkfiles(f1, d1f1, d2f2);
    Util.deleteRecursive(dir);
    assertFalse("dir exists", dir.exists());
}

46. KairosDatastoreTest#test_cleanCacheDir()

Project: kairosdb
Source File: KairosDatastoreTest.java
View license
@SuppressWarnings({ "ResultOfMethodCallIgnored", "ConstantConditions" })
@Test
public void test_cleanCacheDir() throws IOException, DatastoreException {
    TestDatastore testds = new TestDatastore();
    KairosDatastore datastore = new KairosDatastore(testds, new QueryQueuingManager(1, "hostname"), Collections.<DataPointListener>emptyList(), new TestDataPointFactory());
    // Create files in the cache directory
    File cacheDir = new File(datastore.getCacheDir());
    File file1 = new File(cacheDir, "testFile1");
    file1.createNewFile();
    File file2 = new File(cacheDir, "testFile2");
    file2.createNewFile();
    File[] files = cacheDir.listFiles();
    assertTrue(files.length > 0);
    datastore.cleanCacheDir(false);
    assertFalse(file1.exists());
    assertFalse(file2.exists());
}

47. SolrMorphlineTest#testLoadManagedSchema()

Project: kite
Source File: SolrMorphlineTest.java
View license
@Test
public void testLoadManagedSchema() throws Exception {
    // Copy the collection1 config files, so we don't have to keep multiple
    // copies of the auxiliary files in source
    File solrHomeDir = Files.createTempDir();
    solrHomeDir.deleteOnExit();
    File collection1Dir = new File(SOLR_INSTANCE_DIR, "collection1");
    FileUtils.copyDirectory(collection1Dir, solrHomeDir);
    // Copy in the managed collection files, remove the schema.xml since the
    // managed schema uses a generated one
    File managedCollectionDir = new File(SOLR_INSTANCE_DIR, "managedSchemaCollection");
    FileUtils.copyDirectory(managedCollectionDir, solrHomeDir);
    File oldSchemaXml = new File(solrHomeDir + File.separator + "conf" + File.separator + "schema.xml");
    oldSchemaXml.delete();
    assertFalse(oldSchemaXml.exists());
    SolrLocator locator = new SolrLocator(new MorphlineContext.Builder().build());
    locator.setCollectionName("managedSchemaCollection");
    locator.setSolrHomeDir(solrHomeDir.getAbsolutePath());
    IndexSchema schema = locator.getIndexSchema();
    assertNotNull(schema);
    schema.getField("test-managed-morphline-field");
}

48. TestQueryResultPurger#createTestFiles()

Project: lens
Source File: TestQueryResultPurger.java
View license
private void createTestFiles() throws IOException {
    //60 seconds
    long delta = 60 * 1000;
    long lastModified = System.currentTimeMillis() - (MILLISECONDS_IN_DAY + delta);
    File hdfsDir = new File(conf.get(LensConfConstants.RESULT_SET_PARENT_DIR) + "/" + conf.get(LensConfConstants.QUERY_HDFS_OUTPUT_PATH) + "/test-dir");
    hdfsDir.mkdirs();
    hdfsDir.setLastModified(lastModified);
    File resultFile = new File(conf.get(LensConfConstants.RESULT_SET_PARENT_DIR) + "/test-result.txt");
    resultFile.createNewFile();
    resultFile.setLastModified(lastModified);
}

49. IssuesTests_5500_5999#testBug5919()

Project: ceylon
Source File: IssuesTests_5500_5999.java
View license
@Test
public void testBug5919() throws IOException {
    File mrepo = new File(System.getProperty("user.home"), ".m2/repository");
    File annot = new File(mrepo, "com/android/support/support-annotations/23.0.1");
    File jar = new File(annot, "support-annotations-23.0.1.jar");
    File pom = new File(annot, "support-annotations-23.0.1.pom");
    downloadAndroidAnnotations(pom);
    downloadAndroidAnnotations(jar);
    File overridesFile = new File(getPackagePath(), "bug59xx/bug5919/overrides.xml");
    compile(Arrays.asList("-overrides", overridesFile.getAbsolutePath(), "-apt", "com.jakewharton:butterknife-compiler/8.1.0"), "bug59xx/bug5919/test.ceylon");
    File carFile = getModuleArchive("com.redhat.ceylon.compiler.java.test.issues.bug59xx.bug5919", "1");
    assertTrue(carFile.exists());
    try (JarFile car = new JarFile(carFile)) {
        Assert.assertNotNull(car.getEntry("com/redhat/ceylon/compiler/java/test/issues/bug59xx/bug5919/Foo$$ViewBinder.class"));
    }
}

50. CompilerToolTests#testCompileMultipleAutodetect()

Project: ceylon
Source File: CompilerToolTests.java
View license
@Test
public void testCompileMultipleAutodetect() throws Exception {
    File carFile1 = getModuleArchive("com.first", "1");
    carFile1.delete();
    File carFile2 = getModuleArchive("com.second", "1");
    carFile2.delete();
    File carFile3 = getModuleArchive("single", "1");
    carFile3.delete();
    ToolModel<CeylonCompileTool> model = pluginLoader.loadToolModel("compile");
    Assert.assertNotNull(model);
    CeylonCompileTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--src=test/src/com/redhat/ceylon/tools/test/bugCC59"));
    tool.run();
    assertTrue(carFile1.exists() && carFile2.exists() && carFile3.exists());
}

51. CompilerToolTests#testCompileMultipleAutodetect()

View license
@Test
public void testCompileMultipleAutodetect() throws Exception {
    File carFile1 = getModuleArchive("com.first", "1");
    carFile1.delete();
    File carFile2 = getModuleArchive("com.second", "1");
    carFile2.delete();
    File carFile3 = getModuleArchive("single", "1");
    carFile3.delete();
    ToolModel<CeylonCompileTool> model = pluginLoader.loadToolModel("compile");
    Assert.assertNotNull(model);
    CeylonCompileTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--src=test/src/com/redhat/ceylon/tools/test/bugCC59"));
    tool.run();
    assertTrue(carFile1.exists() && carFile2.exists() && carFile3.exists());
}

52. CompressionUtilMain#main()

View license
public static void main(String[] args) throws Exception {
    // copy "Dependency.txt" to build directory -- this will be our test file for all compress/uncompress
    File sourceFile = new File("Dependency.txt");
    File targetFile = new File("build", sourceFile.getName());
    FileUtil.copy(sourceFile, targetFile, true);
    // compress the targetFile, then uncompress and compare with original
    File compressedFile = CompressionUtil.compress(targetFile, "zip", false);
    // renamed this compressed file
    File newCompressedFile = new File("build/Dependency2.txt.zip");
    compressedFile.renameTo(newCompressedFile);
    // uncompress this file
    File newUncompressedFile = CompressionUtil.uncompress(newCompressedFile, new File("build"), true);
    // compare the two files
    boolean result = FileUtil.equals(sourceFile, newUncompressedFile);
    logger.debug("file compare = " + result);
}

53. TupleNClassCastBugTest#run()

Project: crunch
Source File: TupleNClassCastBugTest.java
View license
public void run(Pipeline pipeline, PTypeFamily typeFamily) throws IOException {
    File input = File.createTempFile("docs", "txt");
    input.deleteOnExit();
    Files.copy(newInputStreamSupplier(getResource("docs.txt")), input);
    File output = File.createTempFile("output", "");
    String outputPath = output.getAbsolutePath();
    output.delete();
    PCollection<String> docLines = pipeline.readTextFile(input.getAbsolutePath());
    pipeline.writeTextFile(mapGroupDo(docLines, typeFamily), outputPath);
    pipeline.done();
    // *** We are not directly testing the output, we are looking for a ClassCastException
    // *** which is thrown in a different thread during the reduce phase. If all is well
    // *** the file will exist and have six lines. Otherwise the bug is present.
    File outputFile = new File(output, "part-r-00000");
    List<String> lines = Files.readLines(outputFile, Charset.defaultCharset());
    int lineCount = 0;
    for (String line : lines) {
        lineCount++;
    }
    assertEquals(6, lineCount);
    output.deleteOnExit();
}

54. SipSharedPreferencesHelper#getPreferenceFile()

View license
@SuppressLint("SdCardPath")
private File getPreferenceFile(Context context, String prefName) {
    String finalPath = "shared_prefs/" + prefName + ".xml";
    File f = new File(context.getFilesDir(), "../" + finalPath);
    if (f.exists()) {
        return f;
    }
    f = new File("/data/data/" + context.getPackageName() + "/" + finalPath);
    if (f.exists()) {
        return f;
    }
    f = new File("/dbdata/databases/" + context.getPackageName() + "/" + finalPath);
    if (f.exists()) {
        return f;
    }
    return null;
}

55. TestGlobDirectoryStream#testWildcardNestedDirWithMatchingFile()

View license
@Test
public void testWildcardNestedDirWithMatchingFile() throws IOException {
    File baseDir = new File("target", UUID.randomUUID().toString()).getAbsoluteFile();
    File nestedDir1 = new File(baseDir, "x");
    Assert.assertTrue(nestedDir1.mkdirs());
    File nestedDir2 = new File(baseDir, "y");
    Assert.assertTrue(nestedDir2.mkdirs());
    File file1 = new File(nestedDir1, "x.txt");
    File file2 = new File(nestedDir2, "y.txt");
    File file3 = new File(nestedDir2, "x.txt");
    Files.createFile(file1.toPath());
    Files.createFile(file2.toPath());
    Files.createFile(file3.toPath());
    try (DirectoryStream<Path> ds = new GlobDirectoryStream(baseDir.toPath(), Paths.get("*/x.txt"))) {
        Iterator<Path> it = ds.iterator();
        Assert.assertTrue(it.hasNext());
        Set<Path> found = new HashSet<>();
        found.add(it.next());
        Assert.assertTrue(it.hasNext());
        found.add(it.next());
        Assert.assertFalse(it.hasNext());
        Assert.assertEquals(ImmutableSet.of(file1.toPath(), file3.toPath()), found);
    }
}

56. FileIOChannelFactoryTest#testMatchMultipleWithSubdirectoryExpansion()

View license
@Test
public void testMatchMultipleWithSubdirectoryExpansion() throws Exception {
    File matchedSubDir = temporaryFolder.newFolder("a");
    File matchedSubDirFile = File.createTempFile("sub-dir-file", "", matchedSubDir);
    matchedSubDirFile.deleteOnExit();
    File unmatchedSubDir = temporaryFolder.newFolder("b");
    File unmatchedSubDirFile = File.createTempFile("sub-dir-file", "", unmatchedSubDir);
    unmatchedSubDirFile.deleteOnExit();
    List<String> expected = ImmutableList.of(matchedSubDirFile.toString(), temporaryFolder.newFile("aa").toString(), temporaryFolder.newFile("ab").toString());
    temporaryFolder.newFile("ba");
    temporaryFolder.newFile("bb");
    // Windows doesn't like resolving paths with * in them, so the ** is appended after resolve.
    assertThat(factory.match(factory.resolve(temporaryFolder.getRoot().getPath(), "a") + "**"), Matchers.hasItems(expected.toArray(new String[expected.size()])));
}

57. IndexMergeBenchmark#merge()

Project: druid
Source File: IndexMergeBenchmark.java
View license
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void merge(Blackhole blackhole) throws Exception {
    File tmpFile = File.createTempFile("IndexMergeBenchmark-MERGEDFILE-" + System.currentTimeMillis(), ".TEMPFILE");
    tmpFile.delete();
    tmpFile.mkdirs();
    log.info(tmpFile.getAbsolutePath() + " isFile: " + tmpFile.isFile() + " isDir:" + tmpFile.isDirectory());
    tmpFile.deleteOnExit();
    File mergedFile = INDEX_MERGER.mergeQueryableIndex(indexesToMerge, schemaInfo.getAggsArray(), tmpFile, new IndexSpec());
    blackhole.consume(mergedFile);
    tmpFile.delete();
}

58. IndexMergeBenchmark#mergeV9()

Project: druid
Source File: IndexMergeBenchmark.java
View license
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void mergeV9(Blackhole blackhole) throws Exception {
    File tmpFile = File.createTempFile("IndexMergeBenchmark-MERGEDFILE-V9-" + System.currentTimeMillis(), ".TEMPFILE");
    tmpFile.delete();
    tmpFile.mkdirs();
    log.info(tmpFile.getAbsolutePath() + " isFile: " + tmpFile.isFile() + " isDir:" + tmpFile.isDirectory());
    tmpFile.deleteOnExit();
    File mergedFile = INDEX_MERGER_V9.mergeQueryableIndex(indexesToMerge, schemaInfo.getAggsArray(), tmpFile, new IndexSpec());
    blackhole.consume(mergedFile);
    tmpFile.delete();
}

59. InitializationTest#testExtensionsWithSameDirName()

Project: druid
Source File: InitializationTest.java
View license
@Test
public void testExtensionsWithSameDirName() throws Exception {
    final String extensionName = "some_extension";
    final File tmpDir1 = temporaryFolder.newFolder();
    final File tmpDir2 = temporaryFolder.newFolder();
    final File extension1 = new File(tmpDir1, extensionName);
    final File extension2 = new File(tmpDir2, extensionName);
    Assert.assertTrue(extension1.mkdir());
    Assert.assertTrue(extension2.mkdir());
    final File jar1 = new File(extension1, "jar1.jar");
    final File jar2 = new File(extension2, "jar2.jar");
    Assert.assertTrue(jar1.createNewFile());
    Assert.assertTrue(jar2.createNewFile());
    final ClassLoader classLoader1 = Initialization.getClassLoaderForExtension(extension1);
    final ClassLoader classLoader2 = Initialization.getClassLoaderForExtension(extension2);
    Assert.assertArrayEquals(new URL[] { jar1.toURL() }, ((URLClassLoader) classLoader1).getURLs());
    Assert.assertArrayEquals(new URL[] { jar2.toURL() }, ((URLClassLoader) classLoader2).getURLs());
}

60. FilePermissionsTest#testPreserveExecuteFlag()

Project: zt-zip
Source File: FilePermissionsTest.java
View license
public void testPreserveExecuteFlag() throws Exception {
    File tmpDir = File.createTempFile("FilePermissionsTest-", null);
    tmpDir.delete();
    tmpDir.mkdir();
    File fileA = new File(tmpDir, "fileA.txt");
    File fileB = new File(tmpDir, "fileB.txt");
    FileUtils.copyFile(testFile, fileA);
    FileUtils.copyFile(testFile, fileB);
    assertTrue(fileA.exists());
    setExecutable(fileA, true);
    File tmpZip = File.createTempFile("FilePermissionsTest-", ".zip");
    ZipUtil.pack(tmpDir, tmpZip);
    FileUtils.deleteDirectory(tmpDir);
    ZipUtil.unpack(tmpZip, tmpDir);
    assertTrue(fileA.exists());
    assertTrue(canExecute(fileA));
    assertTrue(fileB.exists());
    assertFalse(canExecute(fileB));
}

61. InsightPluginModelTest#testLoadMultiple()

View license
public void testLoadMultiple() throws Exception {
    File fileA = new File(temp, "insight-plugin-a.jar.disabled");
    fileA.createNewFile();
    File fileB = new File(temp, "insight-plugin-b.jar");
    fileB.createNewFile();
    File fileC = new File(temp, "insight-plugin-c.jar");
    fileC.createNewFile();
    model.load(path);
    // ensure predictable order
    Collections.sort(model.getPlugins());
    assertEquals(3, model.getPlugins().size());
    InsightPlugin plugin = model.getPlugins().get(0);
    assertEquals(fileA, plugin.getFile());
    assertFalse(plugin.isEnabled());
    plugin = model.getPlugins().get(1);
    assertEquals(fileB, plugin.getFile());
    assertTrue(plugin.isEnabled());
    plugin = model.getPlugins().get(2);
    assertEquals(fileC, plugin.getFile());
    assertTrue(plugin.isEnabled());
}

62. InsightPluginModelTest#testCommit()

View license
public void testCommit() throws Exception {
    File fileA = new File(temp, "insight-plugin-a.jar.disabled");
    fileA.createNewFile();
    File fileB = new File(temp, "insight-plugin-b.jar");
    fileB.createNewFile();
    model.load(path);
    // ensure predictable order
    Collections.sort(model.getPlugins());
    model.getPlugins().get(0).setEnabled(true);
    model.getPlugins().get(1).setEnabled(false);
    assertTrue(fileA.exists());
    assertTrue(fileB.exists());
    model.commit();
    assertFalse(fileA.exists());
    assertFalse(fileB.exists());
    File fileAEnabled = new File(temp, "insight-plugin-a.jar");
    assertTrue(fileAEnabled.exists());
    File fileBDisabled = new File(temp, "insight-plugin-b.jar.disabled");
    assertTrue(fileBDisabled.exists());
}

63. FileUtilTest#testOrganizeFilesFiveFiles()

Project: fitnesse
Source File: FileUtilTest.java
View license
@Test
public void testOrganizeFilesFiveFiles() throws Exception {
    File dir = FileUtil.createDir("temp4");
    File file3 = createFileInDir(dir, "dFile.txt");
    File file1 = createFileInDir(dir, "bFile.txt");
    File file4 = createFileInDir(dir, "eFile.txt");
    File file0 = createFileInDir(dir, "aFile.txt");
    File file2 = createFileInDir(dir, "cFile.txt");
    assertEquals(5, FileUtil.getDirectoryListing(dir).length);
    assertEquals(file0, FileUtil.getDirectoryListing(dir)[0]);
    assertEquals(file1, FileUtil.getDirectoryListing(dir)[1]);
    assertEquals(file2, FileUtil.getDirectoryListing(dir)[2]);
    assertEquals(file3, FileUtil.getDirectoryListing(dir)[3]);
    assertEquals(file4, FileUtil.getDirectoryListing(dir)[4]);
    FileUtil.deleteFileSystemDirectory(dir);
}

64. FileUtilTest#testOrganizeFilesFiveSubDirs()

Project: fitnesse
Source File: FileUtilTest.java
View license
@Test
public void testOrganizeFilesFiveSubDirs() throws Exception {
    File dir = FileUtil.createDir("temp6");
    File dir3 = createSubDir(dir, "dDir");
    File dir1 = createSubDir(dir, "bDir");
    File dir4 = createSubDir(dir, "eDir");
    File dir0 = createSubDir(dir, "aDir");
    File dir2 = createSubDir(dir, "cDir");
    assertEquals(5, FileUtil.getDirectoryListing(dir).length);
    assertEquals(dir0, FileUtil.getDirectoryListing(dir)[0]);
    assertEquals(dir1, FileUtil.getDirectoryListing(dir)[1]);
    assertEquals(dir2, FileUtil.getDirectoryListing(dir)[2]);
    assertEquals(dir3, FileUtil.getDirectoryListing(dir)[3]);
    assertEquals(dir4, FileUtil.getDirectoryListing(dir)[4]);
    FileUtil.deleteFileSystemDirectory(dir);
}

65. TestFileNIO#testRenameSemantics()

Project: flume
Source File: TestFileNIO.java
View license
@Test
public void testRenameSemantics() throws IOException {
    File f1 = FileUtil.createTempFile("moved", "");
    f1.delete();
    f1.deleteOnExit();
    File f2 = FileUtil.createTempFile("orig", "");
    f2.deleteOnExit();
    f2.renameTo(f1);
    LOG.info("f1 = " + f1.getAbsolutePath() + " exists " + f1.exists());
    LOG.info("f2 = " + f2.getAbsolutePath() + " exists " + f2.exists());
}

66. TestTailSourceCursor#testFileDescriptor()

Project: flume
Source File: TestTailSourceCursor.java
View license
// /////////////////////////////////////////////////////////////////////////
/**
   * This an experiment playing with FileDescriptors.
   * 
   * This doesn't test flume per se but is a jvm operating system consistency
   * check.
   */
@Test
public void testFileDescriptor() throws IOException {
    File f = FileUtil.createTempFile("fdes", ".tmp");
    f.deleteOnExit();
    File f2 = FileUtil.createTempFile("fdes", ".tmp");
    f2.delete();
    f2.deleteOnExit();
    FileInputStream fis = new FileInputStream(f);
    FileDescriptor fd = fis.getFD();
    f.renameTo(f2);
    FileDescriptor fd2 = fis.getFD();
    assertEquals(fd, fd2);
    new File(f.getAbsolutePath()).createNewFile();
    FileInputStream fis2 = new FileInputStream(f);
    FileDescriptor fd3 = fis2.getFD();
    assertTrue(fd3 != fd);
}

67. HyphenationTestCase#testHyphenatorBinary()

Project: fop
Source File: HyphenationTestCase.java
View license
@Test
public void testHyphenatorBinary() throws HyphenationException, IOException {
    File f = File.createTempFile("hyp", "fop");
    f.delete();
    f.mkdir();
    InternalResourceResolver resourceResolver = ResourceResolverFactory.createDefaultInternalResourceResolver(f.toURI());
    HyphenationTree hTree = new HyphenationTree();
    hTree.loadPatterns(new File("test/resources/fop/fr.xml").getAbsolutePath());
    File hyp = new File(f, "fr.hyp");
    ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(hyp));
    out.writeObject(hTree);
    out.close();
    Hyphenation hyph = Hyphenator.hyphenate("fr.hyp" + Hyphenator.HYPTYPE, null, resourceResolver, null, "oello", 0, 0);
    assertEquals(hyph.toString(), "oel-lo");
    hyp.delete();
    f.delete();
}

68. PluginStores#writePluginStore()

Project: fred
Source File: PluginStores.java
View license
public void writePluginStore(String storeIdentifier, PluginStore store) throws IOException {
    boolean isEncrypted = node.wantEncryptedDatabase();
    File backup = getPluginStoreFile(storeIdentifier, isEncrypted, true);
    File main = getPluginStoreFile(storeIdentifier, isEncrypted, false);
    if (backup.exists() && main.exists()) {
        FileUtil.secureDelete(backup);
    }
    if (main.exists()) {
        if (!main.renameTo(backup))
            System.err.println("Unable to rename " + main + " to " + backup + " when writing pluginstore for " + storeIdentifier);
    }
    writePluginStoreInner(storeIdentifier, store, isEncrypted, false);
    File f = getPluginStoreFile(storeIdentifier, !isEncrypted, true);
    if (f.exists()) {
        FileUtil.secureDelete(f);
    }
    f = getPluginStoreFile(storeIdentifier, !isEncrypted, false);
    if (f.exists()) {
        FileUtil.secureDelete(f);
    }
}

69. XmlPartialConfigProviderTest#shouldGetFilesToLoadMatchingPattern()

View license
@Test
public void shouldGetFilesToLoadMatchingPattern() throws Exception {
    GoConfigMother mother = new GoConfigMother();
    PipelineConfig pipe1 = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0);
    File file1 = helper.addFileWithPipeline("pipe1.gocd.xml", pipe1);
    File file2 = helper.addFileWithPipeline("pipe1.gcd.xml", pipe1);
    File file3 = helper.addFileWithPipeline("subdir/pipe1.gocd.xml", pipe1);
    File file4 = helper.addFileWithPipeline("subdir/sub/pipe1.gocd.xml", pipe1);
    File[] matchingFiles = xmlPartialProvider.getFiles(tmpFolder, mock(PartialConfigLoadContext.class));
    File[] expected = new File[] { file1, file3, file4 };
    assertArrayEquals("Matched files are: " + Arrays.asList(matchingFiles).toString(), expected, matchingFiles);
}

70. XmlPartialConfigProviderTest#shouldUseExplicitPatternWhenProvided()

View license
@Test
public void shouldUseExplicitPatternWhenProvided() throws Exception {
    GoConfigMother mother = new GoConfigMother();
    PipelineConfig pipe1 = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0);
    File file1 = helper.addFileWithPipeline("pipe1.myextension", pipe1);
    File file2 = helper.addFileWithPipeline("pipe1.gcd.xml", pipe1);
    File file3 = helper.addFileWithPipeline("subdir/pipe1.gocd.xml", pipe1);
    File file4 = helper.addFileWithPipeline("subdir/sub/pipe1.gocd.xml", pipe1);
    PartialConfigLoadContext context = mock(PartialConfigLoadContext.class);
    Configuration configs = new Configuration();
    configs.addNewConfigurationWithValue("pattern", "*.myextension", false);
    when(context.configuration()).thenReturn(configs);
    File[] matchingFiles = xmlPartialProvider.getFiles(tmpFolder, context);
    File[] expected = new File[1];
    expected[0] = file1;
    assertArrayEquals(expected, matchingFiles);
}

71. CGIARProviderTest#testFileNotFound()

Project: graphhopper
Source File: CGIARProviderTest.java
View license
@Test
public void testFileNotFound() {
    CGIARProvider instance = new CGIARProvider();
    File file = new File(instance.getCacheDir(), instance.getFileName(46, -20) + ".gh");
    File zipFile = new File(instance.getCacheDir(), instance.getFileName(46, -20) + ".zip");
    file.delete();
    zipFile.delete();
    assertEquals(0, instance.getEle(46, -20), 1);
    // file not found => small!
    assertTrue(file.exists());
    assertEquals(228, file.length());
    file.delete();
    zipFile.delete();
}

72. TestDynamicClassLoader#deleteClass()

Project: hindex
Source File: TestDynamicClassLoader.java
View license
private void deleteClass(String className) throws Exception {
    String jarFileName = className + ".jar";
    File file = new File(TEST_UTIL.getDataTestDir().toString(), jarFileName);
    file.delete();
    assertFalse("Should be deleted: " + file.getPath(), file.exists());
    file = new File(conf.get("hbase.dynamic.jars.dir"), jarFileName);
    file.delete();
    assertFalse("Should be deleted: " + file.getPath(), file.exists());
    file = new File(localDirPath(), jarFileName);
    file.delete();
    assertFalse("Should be deleted: " + file.getPath(), file.exists());
}

73. IdeFinder#loadWindowsDriveInfoLib()

Project: lombok
Source File: IdeFinder.java
View license
private static void loadWindowsDriveInfoLib() throws IOException {
    if (!windowsDriveInfoLibLoaded.compareAndSet(false, true))
        return;
    final String prefix = "lombok-" + Version.getVersion() + "-";
    File temp = File.createTempFile("lombok", ".mark");
    File dll1 = new File(temp.getParentFile(), prefix + "WindowsDriveInfo-i386.dll");
    File dll2 = new File(temp.getParentFile(), prefix + "WindowsDriveInfo-x86_64.dll");
    temp.delete();
    dll1.deleteOnExit();
    dll2.deleteOnExit();
    try {
        if (unpackDLL("WindowsDriveInfo-i386.dll", dll1)) {
            System.load(dll1.getAbsolutePath());
            return;
        }
    } catch (Throwable ignore) {
    }
    try {
        if (unpackDLL("WindowsDriveInfo-x86_64.dll", dll2)) {
            System.load(dll2.getAbsolutePath());
        }
    } catch (Throwable ignore) {
    }
}

74. FileSystemBinaryStoreTest#shouldCreateFileLock()

View license
@Test
public void shouldCreateFileLock() throws IOException {
    File tmpFile = File.createTempFile("foo", "bar");
    File tmpDir = tmpFile.getParentFile();
    tmpFile.delete();
    assertThat(tmpDir.exists(), is(true));
    assertThat(tmpDir.canRead(), is(true));
    assertThat(tmpDir.canWrite(), is(true));
    assertThat(tmpDir.isDirectory(), is(true));
    File lockFile = new File(tmpDir, "lock");
    lockFile.createNewFile();
    RandomAccessFile raf = new RandomAccessFile(lockFile, "rw");
    FileLock fileLock = raf.getChannel().lock();
    fileLock.release();
    assertThat(lockFile.exists(), is(true));
    lockFile.delete();
}

75. CreateAndDeleteWalletsTest#createMultiBitRuntime()

View license
/**
     * Create a working, portable runtime of MultiBit in a temporary directory.
     * 
     * @return the temporary directory the multibit runtime has been created in
     */
private File createMultiBitRuntime() throws IOException {
    File multiBitDirectory = FileHandler.createTempDirectory("CreateAndDeleteWalletsTest");
    String multiBitDirectoryPath = multiBitDirectory.getAbsolutePath();
    System.out.println("Building MultiBit runtime in : " + multiBitDirectory.getAbsolutePath());
    // Create an empty multibit.properties.
    File multibitProperties = new File(multiBitDirectoryPath + File.separator + "multibit.properties");
    multibitProperties.createNewFile();
    multibitProperties.deleteOnExit();
    // Copy in the checkpoints stored in git - this is in source/main/resources/.
    File multibitCheckpoints = new File(multiBitDirectoryPath + File.separator + "multibit.checkpoints");
    FileHandler.copyFile(new File("./src/main/resources/multibit.checkpoints"), multibitCheckpoints);
    multibitCheckpoints.deleteOnExit();
    return multiBitDirectory;
}

76. GenesisBlockReplayTest#createMultiBitRuntime()

View license
/**
     * Create a working, portable runtime of MultiBit in a temporary directory.
     * 
     * @return the temporary directory the multibit runtime has been created in
     */
private File createMultiBitRuntime() throws IOException {
    File multiBitDirectory = FileHandler.createTempDirectory("multibit");
    String multiBitDirectoryPath = multiBitDirectory.getAbsolutePath();
    System.out.println("Building MultiBit runtime in : " + multiBitDirectory.getAbsolutePath());
    // Create an empty multibit.properties.
    File multibitProperties = new File(multiBitDirectoryPath + File.separator + "multibit.properties");
    multibitProperties.createNewFile();
    multibitProperties.deleteOnExit();
    // Copy in the checkpoints stored in git - this is in source/main/resources/.
    File multibitCheckpoints = new File(multiBitDirectoryPath + File.separator + "multibit.checkpoints");
    FileHandler.copyFile(new File("./src/main/resources/multibit.checkpoints"), multibitCheckpoints);
    multibitCheckpoints.deleteOnExit();
    return multiBitDirectory;
}

77. MiningCoinBaseTransactionsSeenTest#createMultiBitRuntime()

View license
/**
     * Create a working, portable runtime of MultiBit in a temporary directory.
     * 
     * @return the temporary directory the multibit runtime has been created in
     */
private File createMultiBitRuntime() throws IOException {
    File multiBitDirectory = FileHandler.createTempDirectory("multibit");
    String multiBitDirectoryPath = multiBitDirectory.getAbsolutePath();
    System.out.println("Building MultiBit runtime in : " + multiBitDirectory.getAbsolutePath());
    // Create an empty multibit.properties.
    File multibitProperties = new File(multiBitDirectoryPath + File.separator + "multibit.properties");
    multibitProperties.createNewFile();
    multibitProperties.deleteOnExit();
    // Copy in the checkpoints stored in git - this is in source/main/resources/.
    File multibitCheckpoints = new File(multiBitDirectoryPath + File.separator + "multibit.checkpoints");
    FileHandler.copyFile(new File("./src/main/resources/multibit.checkpoints"), multibitCheckpoints);
    multibitCheckpoints.deleteOnExit();
    return multiBitDirectory;
}

78. ModelTest#createMultiBitRuntime()

Project: multibit
Source File: ModelTest.java
View license
/**
        * Create a working, portable runtime of MultiBit in a temporary directory.
        *
        * @return the temporary directory the multibit runtime has been created in
        */
private File createMultiBitRuntime() throws IOException {
    File multiBitDirectory = FileHandler.createTempDirectory("multibit");
    String multiBitDirectoryPath = multiBitDirectory.getAbsolutePath();
    System.out.println("Building MultiBit runtime in : " + multiBitDirectory.getAbsolutePath());
    // Create an empty multibit.properties.
    File multibitProperties = new File(multiBitDirectoryPath + File.separator + "multibit.properties");
    multibitProperties.createNewFile();
    multibitProperties.deleteOnExit();
    // Copy in the checkpoints stored in git - this is in source/main/resources/.
    File multibitCheckpoints = new File(multiBitDirectoryPath + File.separator + "multibit.checkpoints");
    FileHandler.copyFile(new File("./src/main/resources/multibit.checkpoints"), multibitCheckpoints);
    multibitCheckpoints.deleteOnExit();
    return multiBitDirectory;
}

79. ReplayManagerTest#createMultiBitRuntime()

Project: multibit
Source File: ReplayManagerTest.java
View license
/**
     * Create a working, portable runtime of MultiBit in a temporary directory.
     * 
     * @return the temporary directory the multibit runtime has been created in
     */
private File createMultiBitRuntime() throws IOException {
    File multiBitDirectory = FileHandler.createTempDirectory("multibit");
    String multiBitDirectoryPath = multiBitDirectory.getAbsolutePath();
    System.out.println("Building MultiBit runtime in : " + multiBitDirectory.getAbsolutePath());
    // Create an empty multibit.properties.
    File multibitProperties = new File(multiBitDirectoryPath + File.separator + "multibit.properties");
    multibitProperties.createNewFile();
    multibitProperties.deleteOnExit();
    // Copy in the checkpoints and blockchain stored in git - this is in
    // source/main/resources/.
    File multibitBlockcheckpoints = new File(multiBitDirectoryPath + File.separator + "multibit.checkpoints");
    FileHandler.copyFile(new File("./src/main/resources/multibit.checkpoints"), multibitBlockcheckpoints);
    multibitBlockcheckpoints.deleteOnExit();
    return multiBitDirectory;
}

80. ListAddresses#createMultiBitRuntime()

Project: multibit
Source File: ListAddresses.java
View license
/**
   * Create a working, portable runtime of MultiBit in a temporary directory.
   *
   * @return the temporary directory the multibit runtime has been created in
   */
private static File createMultiBitRuntime() throws IOException {
    File multiBitDirectory = FileHandler.createTempDirectory("multibit");
    String multiBitDirectoryPath = multiBitDirectory.getAbsolutePath();
    System.out.println("Building MultiBit runtime in : " + multiBitDirectory.getAbsolutePath());
    // Create an empty multibit.properties.
    File multibitProperties = new File(multiBitDirectoryPath + File.separator + "multibit.properties");
    multibitProperties.createNewFile();
    multibitProperties.deleteOnExit();
    // Copy in the checkpoints stored in git - this is in source/main/resources/.
    File multibitCheckpoints = new File(multiBitDirectoryPath + File.separator + "multibit.checkpoints");
    FileHandler.copyFile(new File("./src/main/resources/multibit.checkpoints"), multibitCheckpoints);
    multibitCheckpoints.deleteOnExit();
    return multiBitDirectory;
}

81. SendBitcoinNowActionTest#createMultiBitRuntime()

View license
/**
     * Create a working, portable runtime of MultiBit in a temporary directory.
     * 
     * @return the temporary directory the multibit runtime has been created in
     */
private File createMultiBitRuntime() throws IOException {
    File multiBitDirectory = FileHandler.createTempDirectory("multibit");
    String multiBitDirectoryPath = multiBitDirectory.getAbsolutePath();
    System.out.println("Building MultiBit runtime in : " + multiBitDirectory.getAbsolutePath());
    // Create an empty multibit.properties.
    File multibitProperties = new File(multiBitDirectoryPath + File.separator + "multibit.properties");
    multibitProperties.createNewFile();
    multibitProperties.deleteOnExit();
    // Copy in the checkpoints stored in git - this is in source/main/resources/.
    File multibitCheckpoints = new File(multiBitDirectoryPath + File.separator + "multibit.checkpoints");
    FileHandler.copyFile(new File("./src/main/resources/multibit.checkpoints"), multibitCheckpoints);
    multibitCheckpoints.deleteOnExit();
    return multiBitDirectory;
}

82. FileSystemUtilTest#updateFileHandleTest()

Project: onos
Source File: FileSystemUtilTest.java
View license
/**
     * This test case checks the contents to be written in the file.
     *
     * @throws IOException when fails to create a test file
     */
@Test
public void updateFileHandleTest() throws IOException {
    File dir = new File(BASE_PKG + SLASH + TEST_FILE);
    dir.mkdirs();
    File createFile = new File(dir + TEST_FILE);
    createFile.createNewFile();
    File createSourceFile = new File(dir + SOURCE_TEST_FILE);
    createSourceFile.createNewFile();
    updateFileHandle(createFile, TEST_DATA_1, false);
    updateFileHandle(createFile, TEST_DATA_2, false);
    updateFileHandle(createFile, TEST_DATA_3, false);
    appendFileContents(createFile, createSourceFile);
    updateFileHandle(createFile, null, true);
    deleteDirectory(dir);
}

83. TestImapsProtocol#testLSandGET()

Project: oodt
Source File: TestImapsProtocol.java
View license
public void testLSandGET() throws ProtocolException, IOException {
    GreenMailUtil.sendTextEmailSecureTest("[email protected]", "[email protected]", "Test Subject", "Test Body");
    imapsProtocol.cd(new ProtocolFile("INBOX", true));
    List<ProtocolFile> emails = imapsProtocol.ls();
    assertEquals(1, emails.size());
    File bogusFile = File.createTempFile("bogus", "bogus");
    File tmpDir = new File(bogusFile.getParentFile(), "TestImapsProtocol");
    bogusFile.delete();
    tmpDir.mkdirs();
    File email = new File(tmpDir, "test-email");
    imapsProtocol.get(emails.get(0), email);
    String[] splitEmail = FileUtils.readFileToString(email, "UTF-8").split("\n");
    assertEquals("From: [email protected]", splitEmail[0]);
    assertEquals("To: [email protected]", splitEmail[1]);
    assertEquals("Subject: Test Subject", splitEmail[2]);
    // 3 is divider text (i.e. ----- ~ Message ~ -----)
    assertEquals("Test Body", splitEmail[4]);
    tmpDir.delete();
}

84. IOUtilsTest#testDeleteRecursively()

Project: oryx
Source File: IOUtilsTest.java
View license
@Test
public void testDeleteRecursively() throws IOException {
    File tempDir = Files.createTempDir();
    tempDir.deleteOnExit();
    assertTrue(tempDir.exists());
    File subFile1 = new File(tempDir, "subFile1");
    Files.write(SOME_BYTES, subFile1);
    assertTrue(subFile1.exists());
    File subDir1 = new File(tempDir, "subDir1");
    IOUtils.mkdirs(subDir1);
    File subFile2 = new File(subDir1, "subFile2");
    Files.write(SOME_BYTES, subFile2);
    assertTrue(subFile2.exists());
    File subDir2 = new File(subDir1, "subDir2");
    IOUtils.mkdirs(subDir2);
    IOUtils.deleteRecursively(tempDir);
    assertFalse(tempDir.exists());
    assertFalse(subFile1.exists());
    assertFalse(subDir1.exists());
    assertFalse(subFile2.exists());
    assertFalse(subDir2.exists());
}

85. ManagedDefaultRepositoryContent#deleteArtifact()

View license
@Override
public void deleteArtifact(ArtifactReference artifactReference) {
    String path = toPath(artifactReference);
    File filePath = new File(getRepoRoot(), path);
    if (filePath.exists()) {
        FileUtils.deleteQuietly(filePath);
    }
    File filePathmd5 = new File(getRepoRoot(), path + ".md5");
    if (filePathmd5.exists()) {
        FileUtils.deleteQuietly(filePathmd5);
    }
    File filePathsha1 = new File(getRepoRoot(), path + ".sha1");
    if (filePathsha1.exists()) {
        FileUtils.deleteQuietly(filePathsha1);
    }
}

86. WhenAsciidoctorIsCalledUsingCli#more_than_one_input_file_should_throw_an_exception()

View license
@Test
public void more_than_one_input_file_should_throw_an_exception() {
    File inputFile1 = classpath.getResource("rendersample.asciidoc");
    String inputPath1 = inputFile1.getPath().substring(pwd.length() + 1);
    File inputFile2 = classpath.getResource("tocsample.asciidoc");
    String inputPath2 = inputFile2.getPath().substring(pwd.length() + 1);
    new AsciidoctorInvoker().invoke(inputPath1, inputPath2);
    File expectedFile1 = new File(inputPath1.replaceFirst("\\.asciidoc$", ".html"));
    assertThat(expectedFile1.exists(), is(true));
    expectedFile1.delete();
    File expectedFile2 = new File(inputPath2.replaceFirst("\\.asciidoc$", ".html"));
    assertThat(expectedFile2.exists(), is(true));
    expectedFile2.delete();
}

87. JPMTest#testVM()

Project: bnd
Source File: JPMTest.java
View license
public void testVM() throws Exception {
    File tmp = new File("tmp");
    IO.delete(tmp);
    tmp.mkdirs();
    File home = new File(tmp, "home");
    File bin = new File(tmp, "bin");
    System.setProperty("jpm.intest", "true");
    JustAnotherPackageManager jpm = new JustAnotherPackageManager(new ReporterAdapter(), null, home, bin);
    SortedSet<JVM> vms = jpm.getVMs();
    assertNotNull(vms);
    assertTrue(vms.size() >= 1);
    System.out.println(vms);
    File f = IO.getFile("~/jdk1.8");
    if (f.isDirectory()) {
        JVM jvm = jpm.addVm(f);
        assertNotNull(jvm);
    }
}

88. FileSystemInstaller#uninstall()

View license
public void uninstall(InstallationConfig config) throws UtilityException {
    File endorsedDir = getEndorsedDir(config);
    File sharedDir = getSharedDir(config);
    File domainDir = getWebAppDir(config);
    endorsedDir.mkdirs();
    sharedDir.mkdirs();
    domainDir.mkdirs();
    try {
        removeFilesFromDirectory(config.getEndorsedDependencies(), endorsedDir);
        removeFilesFromDirectory(config.getSharedDependencies(), sharedDir);
        removeFilesFromDirectory(config.getPortletApplications().values(), domainDir);
        File delete = new File(domainDir, config.getPortalApplication().getName());
        delete.delete();
    } catch (IOException io) {
        throw new UtilityException("Unable to remove files. ", io, config.getInstallationDirectory());
    }
}

89. ProjectBuilderMediumTest#prepareProject()

View license
private File prepareProject() throws IOException {
    File baseDir = temp.getRoot();
    File module1Dir = new File(baseDir, "module1");
    module1Dir.mkdir();
    File srcDir = new File(module1Dir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
    return baseDir;
}

90. FolderSnapshotTests#getChangedFilesWhenAFileIsAddedAndDeletedAndChanged()

View license
@Test
public void getChangedFilesWhenAFileIsAddedAndDeletedAndChanged() throws Exception {
    File folder1 = new File(this.folder, "folder1");
    File file1 = new File(folder1, "file1");
    File file2 = new File(folder1, "file2");
    File newFile = new File(folder1, "newfile");
    FileCopyUtils.copy("updatedcontent".getBytes(), file1);
    file2.delete();
    newFile.createNewFile();
    FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
    ChangedFiles changedFiles = this.initialSnapshot.getChangedFiles(updatedSnapshot, null);
    assertThat(changedFiles.getSourceFolder()).isEqualTo(this.folder);
    assertThat(getChangedFile(changedFiles, file1).getType()).isEqualTo(Type.MODIFY);
    assertThat(getChangedFile(changedFiles, file2).getType()).isEqualTo(Type.DELETE);
    assertThat(getChangedFile(changedFiles, newFile).getType()).isEqualTo(Type.ADD);
}

91. FolderObserverTest#testMoveDirectoryOut()

View license
public void testMoveDirectoryOut() throws IOException, InterruptedException, FolderObserver.FolderNotExistingException {
    mCurrentTest = "testMoveDirectory";
    File subFolder = new File(mTestFolder, "subfolder");
    subFolder.mkdir();
    FolderObserver fo = new FolderObserver(this, createFolder(mCurrentTest));
    File movedSubFolder = new File(getContext().getFilesDir(), subFolder.getName());
    subFolder.renameTo(movedSubFolder);
    File testFile = new File(movedSubFolder, "should-not-notify");
    mLatch = new CountDownLatch(1);
    testFile.createNewFile();
    mLatch.await(1, TimeUnit.SECONDS);
    assertEquals(1, mLatch.getCount());
    fo.stopWatching();
}

92. ReportSourceLocatorTest#testMultipleSubdirectories()

Project: pitest
Source File: ReportSourceLocatorTest.java
View license
@Test
public void testMultipleSubdirectories() {
    File mockReportsDir = this.buildMockReportsDirectory();
    File mockSubDir0 = mock(File.class);
    File mockSubDir1 = mock(File.class);
    File mockSubDir2 = mock(File.class);
    File mockSubDir3 = mock(File.class);
    when(mockSubDir0.lastModified()).thenReturn(2L);
    when(mockSubDir1.lastModified()).thenReturn(3L);
    when(mockSubDir2.lastModified()).thenReturn(1L);
    when(mockSubDir3.lastModified()).thenReturn(3L);
    when(mockReportsDir.listFiles(isA(FileFilter.class))).thenReturn(new File[] { mockSubDir0, mockSubDir1, mockSubDir2, mockSubDir3 });
    assertThat(this.fixture.locate(mockReportsDir, this.mockLog), sameInstance(mockSubDir1));
}

93. JavaScriptValidatorTest#testErrorSuppressionErrorFromJavaScriptValidator()

Project: redpen
Source File: JavaScriptValidatorTest.java
View license
@Test
public void testErrorSuppressionErrorFromJavaScriptValidator() throws RedPenException, IOException {
    File javaScriptValidatorsDir = File.createTempFile("test", "js");
    javaScriptValidatorsDir.delete();
    javaScriptValidatorsDir.mkdirs();
    System.setProperty("REDPEN_HOME", javaScriptValidatorsDir.getAbsolutePath());
    File validatorJS = new File(javaScriptValidatorsDir.getAbsolutePath() + File.separator + "MyValidator.js");
    String content2 = "function validateSentence(sentence) {\n" + "addLocalizedError(sentence, 'validation error in JavaScript Validator');}";
    Files.write(Paths.get(validatorJS.getAbsolutePath()), content2.getBytes(UTF_8));
    validatorJS.deleteOnExit();
    Configuration config = Configuration.builder().addValidatorConfig(new ValidatorConfiguration("JavaScript").addProperty("script-path", javaScriptValidatorsDir.getAbsolutePath())).build();
    String sampleAsciiDocShortText = "[suppress]\n" + "the good item is a good example.\n";
    Document doc = createFileContent(sampleAsciiDocShortText, DocumentParser.ASCIIDOC);
    RedPen redPen = new RedPen(config);
    List<ValidationError> errors = redPen.validate(doc);
    assertEquals(0, errors.size());
}

94. DownloadServiceTests#testAttachmentNoNameGivenFileExists()

Project: RSSOwl
Source File: DownloadServiceTests.java
View license
/**
   * @throws Exception
   */
@Test
public void testAttachmentNoNameGivenFileExists() throws Exception {
    File tmpDir = getTmpDir();
    Date date = new Date(System.currentTimeMillis());
    DownloadRequest request = getAttachmentDownloadRequest("http://www.rssowl.org/rssowl2dg/tests/download/test.txt", null, 0, tmpDir, null, date);
    fService.download(request);
    File download = new File(tmpDir, "test.txt");
    assertTrue(download.exists());
    request = getAttachmentDownloadRequest("http://www.rssowl.org/rssowl2dg/tests/download/test.txt", null, 0, tmpDir, null, date);
    fService.download(request);
    File secondDownload = new File(tmpDir, "test_" + DOWNLOAD_FILE_DATE_FORMAT.format(date) + ".txt");
    assertTrue(secondDownload.exists());
    secondDownload.delete();
    download.delete();
}

95. JPEGDecoderFunctionTest#testIJGQuality()

View license
public void testIJGQuality() throws Exception {
    File profileDir = new File(jpegs, "quality");
    File img = new File(profileDir, "quality_80.jpg");
    assertTrue(getQuality(img) == 80);
    img = new File(profileDir, "quality_90.jpg");
    assertTrue(getQuality(img) == 90);
    img = new File(profileDir, "quality_95.jpg");
    assertTrue(getQuality(img) == 95);
    img = new File(profileDir, "quality_unknow.jpg");
    assertTrue(getQuality(img) == 99);
}

96. ReadRenderTest#testReadImageFormat()

Project: simpleimage
Source File: ReadRenderTest.java
View license
public void testReadImageFormat() throws Exception {
    File dir1 = new File("./src/test/resources/conf.test/simpleimage/rgb");
    ImageWrapper img = read(dir1, "adobe_RGB_1998.jpg");
    assertEquals(ImageFormat.JPEG, img.getImageFormat());
    File dir2 = new File("./src/test/resources/conf.test/simpleimage/gif");
    img = read(dir2, "1212.gif");
    assertEquals(ImageFormat.GIF, img.getImageFormat());
    File dir3 = new File("./src/test/resources/conf.test/simpleimage/png");
    img = read(dir3, "dst.png");
    assertEquals(ImageFormat.PNG, img.getImageFormat());
    File dir4 = new File("./src/test/resources/conf.test/simpleimage/bmp");
    img = read(dir4, "normal.bmp");
    assertEquals(ImageFormat.BMP, img.getImageFormat());
    File dir5 = new File("./src/test/resources/conf.test/simpleimage/tiff");
    img = read(dir5, "input_16.tiff");
    assertEquals(ImageFormat.TIFF, img.getImageFormat());
}

97. PathResolverTest#relative_path_from_multiple_dirs()

Project: sonarqube
Source File: PathResolverTest.java
View license
@Test
public void relative_path_from_multiple_dirs() throws IOException {
    PathResolver resolver = new PathResolver();
    File dir1 = temp.newFolder("D1");
    File dir2 = temp.newFolder("D2");
    File org = new File(dir2, "org");
    File hello = new File(org, "hello");
    File world = new File(hello, "World.java");
    PathResolver.RelativePath relativePath = resolver.relativePath(Arrays.asList(dir1, dir2), world);
    assertThat(relativePath.dir().getCanonicalPath()).isEqualTo(dir2.getCanonicalPath());
    assertThat(relativePath.path()).isEqualTo("org/hello/World.java");
}

98. PathResolverTest#cant_find_relative_path_from_multiple_dirs()

Project: sonarqube
Source File: PathResolverTest.java
View license
@Test
public void cant_find_relative_path_from_multiple_dirs() throws IOException {
    PathResolver resolver = new PathResolver();
    File dir1 = temp.newFolder("D1");
    File dir2 = temp.newFolder("D2");
    File org = new File(dir2, "org");
    File hello = new File(org, "hello");
    File world = new File(hello, "World.java");
    PathResolver.RelativePath relativePath = resolver.relativePath(Arrays.asList(dir1), world);
    assertThat(relativePath).isNull();
}

99. ScmMediumTest#prepareProject()

Project: sonarqube
Source File: ScmMediumTest.java
View license
private File prepareProject() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile1 = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile1, "Sample xoo\ncontent\n3\n4\n5");
    File xooScmFile1 = new File(srcDir, "sample.xoo.scm");
    FileUtils.write(xooScmFile1, // revision,author,dateTime
    "1,,2013-01-04\n" + "2,julien,2013-01-04\n" + "3,julien,2013-02-03\n" + "3,julien,2013-02-03\n" + "4,simon,2013-03-04\n");
    return baseDir;
}

100. WorkDirectoryCleanerTest#setUp()

View license
@Before
public void setUp() throws IOException {
    // create files to clean
    temp.newFile();
    File newFolder = temp.newFolder();
    File fileInFolder = new File(newFolder, "test");
    fileInFolder.createNewFile();
    File lock = new File(temp.getRoot(), DirectoryLock.LOCK_FILE_NAME);
    lock.createNewFile();
    // mock project
    ProjectReactor projectReactor = mock(ProjectReactor.class);
    ProjectDefinition projectDefinition = mock(ProjectDefinition.class);
    when(projectReactor.getRoot()).thenReturn(projectDefinition);
    when(projectDefinition.getWorkDir()).thenReturn(temp.getRoot());
    assertThat(temp.getRoot().list().length).isGreaterThan(1);
    cleaner = new WorkDirectoryCleaner(projectReactor);
}