コード例 #1
0
  @Test
  public void readAndSave_deleteAndRenameTempFileTest() throws MalformedURLException, IOException {
    final File cache = folder.newFile(); // cache file does not exist

    // Assert.assertTrue(temp.length() == 0); // does not work on any system
    Assert.assertTrue(FileUtil.isEmpty(cache, DataStore.DEFAULT_CHARSET));

    // file will be created
    CachingXmlDataStore.readAndSave(DATA_URL, cache, CHARSET);
    Assert.assertTrue(cache.length() >= 722015);

    // file will be overwritten (delete and rename)
    CachingXmlDataStore.readAndSave(DATA_URL, cache, CHARSET);
    Assert.assertTrue(cache.length() >= 722015);
  }
コード例 #2
0
  @Test
  public void readAndSave_renamingFailsTest() throws MalformedURLException, IOException {
    final File cache = folder.newFile(); // cache file does not exist
    final IMockBuilder<File> builder = EasyMock.createMockBuilder(File.class);
    builder.withConstructor(URI.class);
    builder.withArgs(cache.toURI());
    final File fileMock = builder.addMockedMethod("renameTo", File.class).createMock();
    EasyMock.expect(fileMock.renameTo(EasyMock.anyObject(File.class))).andReturn(false).anyTimes();
    EasyMock.replay(fileMock);

    // Assert.assertTrue(temp.length() == 0); // does not work on any system
    Assert.assertTrue(FileUtil.isEmpty(fileMock, DataStore.DEFAULT_CHARSET));

    // file will be created
    CachingXmlDataStore.readAndSave(DATA_URL, fileMock, CHARSET);
    Assert.assertTrue(fileMock.length() >= 722015);

    // file will be overwritten (delete and rename)
    CachingXmlDataStore.readAndSave(DATA_URL, fileMock, CHARSET);
    Assert.assertTrue(fileMock.length() >= 722015);
  }