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. CompositeImageProcessorTest#testProcess()

View license
/**
     * Test method for
     * {@link 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);
        }
    }
}

4. 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");
}

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. 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;
}

9. 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);
}

10. 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));
}

11. 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));
}

12. 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);
}

13. 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));
        }
    }
}

14. 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();
}

15. 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();
}

16. 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);
}

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. 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();
}

20. 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;
}

21. 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();
}

22. 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();
}

23. 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);
}

24. 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");
}

25. 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);
}

26. 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();
    }
}

27. 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;
}

28. 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() + "!/"));
}

29. 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);
    }
}

30. 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);
}

31. 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());
    }
}

32. 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;
}

33. 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);
    }
}

34. 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());
}

35. 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);
}

36. 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);
}

37. 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);
}

38. 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);
}

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. 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);
}

42. 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));
}

43. 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());
}

44. 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();
}

45. 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);
}

46. 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);
}

47. 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()])));
}

48. 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();
}

49. 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();
            }
    }
}

50. 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());
}

51. 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());
}

52. 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());
}

53. 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);
}

54. 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);
}

55. 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();
}

56. 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);
    }
}

57. 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");
}

58. 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);
}

59. 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());
}

60. 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());
}

61. 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;
}

62. 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) {
    }
}

63. 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());
    }
}

64. 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;
}

65. 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;
}

66. 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;
}

67. 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());
}

68. 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();
}

69. 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();
}

70. 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());
}

71. 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());
}

72. 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);
}

73. 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());
}

74. 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"));
    }
}

75. 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());
}

76. 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);
    }
}

77. 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();
}

78. 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);
    }
}

79. 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);
    }
}

80. 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();
}

81. 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;
}

82. 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;
}

83. 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);
}

84. 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();
}

85. 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);
}

86. 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();
}

87. 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();
}

88. 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;
}

89. 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;
}

90. 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;
}

91. 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()])));
}

92. LocalStorageProvider#renameDocument()

View license
@Override
public String renameDocument(final String documentId, final String displayName) throws FileNotFoundException {
    if (LocalStorageProvider.isMissingPermission(getContext())) {
        return null;
    }
    File existingFile = new File(documentId);
    if (!existingFile.exists()) {
        throw new FileNotFoundException(documentId + " does not exist");
    }
    if (existingFile.getName().equals(displayName)) {
        return null;
    }
    File parentDirectory = existingFile.getParentFile();
    File newFile = new File(parentDirectory, displayName);
    int conflictIndex = 1;
    while (newFile.exists()) {
        newFile = new File(parentDirectory, displayName + "_" + conflictIndex++);
    }
    boolean success = existingFile.renameTo(newFile);
    if (!success) {
        throw new FileNotFoundException("Unable to rename " + documentId + " to " + existingFile.getAbsolutePath());
    }
    return existingFile.getAbsolutePath();
}

93. ResolveGeogigURITest#test()

Project: geogig
Source File: ResolveGeogigURITest.java
View license
@Test
public void test() throws Exception {
    File workingDir = tmpFolder.newFolder("fakeWorkingDir");
    File fakeRepo = new File(workingDir, ".geogig");
    fakeRepo.mkdirs();
    Platform platform = mock(Platform.class);
    when(platform.pwd()).thenReturn(workingDir);
    URI resolvedRepoDir = new ResolveGeogigURI(platform, null).call().get();
    assertEquals(fakeRepo.toURI(), resolvedRepoDir);
    workingDir = new File(new File(workingDir, "subdir1"), "subdir2");
    workingDir.mkdirs();
    when(platform.pwd()).thenReturn(workingDir);
    resolvedRepoDir = new ResolveGeogigURI(platform, null).call().get();
    assertEquals(fakeRepo.toURI(), resolvedRepoDir);
    when(platform.pwd()).thenReturn(tmpFolder.getRoot());
    assertFalse(new ResolveGeogigURI(platform, null).call().isPresent());
}

94. JobInstanceLogTest#shouldFindIndexPageFromTestOutputRecursivelyWithMultipleFolders()

Project: gocd
Source File: JobInstanceLogTest.java
View license
@Test
public void shouldFindIndexPageFromTestOutputRecursivelyWithMultipleFolders() throws Exception {
    final File logFolder = new File(rootFolder, "logs");
    final File testOutput = new File(rootFolder, TestArtifactPlan.TEST_OUTPUT_FOLDER);
    final File junitReportFolder = new File(testOutput, "junitreport");
    junitReportFolder.mkdirs();
    logFolder.mkdirs();
    FileOutputStream fileOutputStream = new FileOutputStream(new File(junitReportFolder, "index.html"));
    IOUtils.write("Test", fileOutputStream);
    IOUtils.closeQuietly(fileOutputStream);
    HashMap map = new HashMap();
    map.put("artifactfolder", rootFolder);
    jobInstanceLog = new JobInstanceLog(null, map);
    assertThat(jobInstanceLog.getTestIndexPage().getName(), is("index.html"));
}

95. DefaultCredentialProviderTest#testDefaultCredentialWellKnownFileNonWindows()

View license
public void testDefaultCredentialWellKnownFileNonWindows() throws IOException {
    // Simulate where the SDK puts the well-known file on non-Windows platforms
    File homeDir = getTempDirectory();
    File configDir = new File(homeDir, ".config");
    if (!configDir.exists()) {
        configDir.mkdir();
    }
    File cloudConfigDir = new File(configDir, DefaultCredentialProvider.CLOUDSDK_CONFIG_DIRECTORY);
    if (!cloudConfigDir.exists()) {
        cloudConfigDir.mkdir();
    }
    File wellKnownFile = new File(cloudConfigDir, DefaultCredentialProvider.WELL_KNOWN_CREDENTIALS_FILE);
    if (wellKnownFile.exists()) {
        wellKnownFile.delete();
    }
    TestDefaultCredentialProvider testProvider = new TestDefaultCredentialProvider();
    testProvider.addFile(wellKnownFile.getAbsolutePath());
    testProvider.setProperty("os.name", "linux");
    testProvider.setProperty("user.home", homeDir.getAbsolutePath());
    testDefaultCredentialUser(wellKnownFile, testProvider);
}

96. FetchArtifactBuilderTest#setUp()

Project: gocd
Source File: FetchArtifactBuilderTest.java
View license
@Before
public void setUp() throws Exception {
    File folder = TestFileUtil.createTempFolder("log");
    File consolelog = new File(folder, "console.log");
    folder.mkdirs();
    consolelog.createNewFile();
    zip = new ZipUtil().zip(folder, TestFileUtil.createUniqueTempFile(folder.getName()), Deflater.NO_COMPRESSION);
    toClean.add(folder);
    toClean.add(zip);
    dest = new File("dest");
    dest.mkdirs();
    toClean.add(dest);
    clock = new TestingClock();
    publisher = new StubGoPublisher();
    checksumFileHandler = mock(ChecksumFileHandler.class);
    urlService = mock(URLService.class);
    downloadAction = mock(DownloadAction.class);
}

97. DirectoryCleanerTest#shouldNotCleanSvnDestIfExternalIsEnabled()

Project: gocd
Source File: DirectoryCleanerTest.java
View license
@Test
public void shouldNotCleanSvnDestIfExternalIsEnabled() {
    File svnDest = new File(baseFolder, "test1");
    File shouldExist = new File(svnDest, "shouldExist");
    shouldExist.mkdirs();
    File svnExternal = new File(baseFolder, "test1/external");
    svnExternal.mkdirs();
    cleaner.allowed("test1", "test1/subdir");
    cleaner.clean();
    assertThat(svnDest.exists(), is(true));
    assertThat(shouldExist.exists(), is(true));
}

98. P4TestRepo#checkInOneFile()

Project: gocd
Source File: P4TestRepo.java
View license
private List<Modification> checkInOneFile(P4Material p4Material1, String fileName, String comment) throws Exception {
    File workingDir = TestFileUtil.createTempFolder("p4-working-dir-" + UUID.randomUUID());
    P4Client client = createClient();
    client.client(clientConfig(clientName, workingDir), inMemoryConsumer(), true);
    File dir = new File(workingDir, p4Material1.getFolder());
    dir.mkdirs();
    checkout(dir);
    File newFile = new File(new File(workingDir, p4Material1.getFolder()), fileName);
    newFile.createNewFile();
    add(workingDir, newFile.getAbsolutePath());
    commit(comment, workingDir);
    client.removeClient();
    List<Modification> modifications = p4Material1.latestModification(workingDir, new TestSubprocessExecutionContext());
    return modifications;
}

99. CommandRepositoryInitializerIntegrationTest#shouldNotDeleteCustomCommandRepositoryWhenUpdatingDefaultCommandRepository()

View license
@Test
public void shouldNotDeleteCustomCommandRepositoryWhenUpdatingDefaultCommandRepository() throws Exception {
    File versionFile = TestFileUtil.writeStringToTempFileInFolder("default", "version.txt", "10.1=10");
    File randomFile = TestFileUtil.createTestFile(versionFile.getParentFile(), "random");
    File defaultCommandRepoDir = versionFile.getParentFile();
    File customCommandRepoDir = TestFileUtil.createTestFolder(new File(defaultCommandRepoDir.getParent()), "customDir");
    File userFile = TestFileUtil.createTestFile(customCommandRepoDir, "userFile");
    initializer.usePackagedCommandRepository(new ZipInputStream(new FileInputStream(getZippedCommandRepo("12.4=12"))), defaultCommandRepoDir);
    assertThat(defaultCommandRepoDir.exists(), is(true));
    assertThat(FileUtils.readFileToString(new File(defaultCommandRepoDir, "version.txt")), is("12.4=12"));
    assertThat(new File(defaultCommandRepoDir, "snippet.xml").exists(), is(true));
    assertThat(new File(defaultCommandRepoDir, randomFile.getName()).exists(), is(false));
    assertThat(customCommandRepoDir.exists(), is(true));
    assertThat(new File(customCommandRepoDir, userFile.getName()).exists(), is(true));
}

100. StoreTest#testSizeRecursive()

Project: oryx
Source File: StoreTest.java
View license
@Test
public void testSizeRecursive() throws Exception {
    File dir = Files.createTempDir();
    dir.deleteOnExit();
    File subDir = new File(dir, "subdir");
    assertTrue(subDir.mkdir());
    File file1 = new File(dir, "testDU1.txt");
    File file2 = new File(subDir, "testDU2.txt");
    Files.write("Hello.", file1, StandardCharsets.UTF_8);
    Files.write("Shalom.", file2, StandardCharsets.UTF_8);
    Store store = Store.get();
    assertEquals(6, store.getSizeRecursive(file1.toString()));
    assertEquals(7, store.getSizeRecursive(file2.toString()));
    assertEquals(7, store.getSizeRecursive(subDir.toString()));
    assertEquals(13, store.getSizeRecursive(dir.toString()));
    IOUtils.deleteRecursively(dir);
}