|
Commons IO example source code file (FileDeleteStrategyTestCase.java)
The Commons IO FileDeleteStrategyTestCase.java source code/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.io; import java.io.File; import java.io.IOException; import org.apache.commons.io.testtools.FileBasedTestCase; /** * Test for FileDeleteStrategy. * * @version $Id: FileDeleteStrategyTestCase.java 919474 2010-03-05 16:31:43Z sebb $ * @see FileDeleteStrategy */ public class FileDeleteStrategyTestCase extends FileBasedTestCase { public FileDeleteStrategyTestCase(String name) { super(name); } @Override protected void setUp() throws Exception { super.setUp(); } @Override protected void tearDown() throws Exception { super.tearDown(); } //----------------------------------------------------------------------- public void testDeleteNormal() throws Exception { File baseDir = getTestDirectory(); File subDir = new File(baseDir, "test"); assertEquals(true, subDir.mkdir()); File subFile = new File(subDir, "a.txt"); createFile(subFile, 16); assertEquals(true, subDir.exists()); assertEquals(true, subFile.exists()); // delete dir try { FileDeleteStrategy.NORMAL.delete(subDir); fail(); } catch (IOException ex) { // expected } assertEquals(true, subDir.exists()); assertEquals(true, subFile.exists()); // delete file FileDeleteStrategy.NORMAL.delete(subFile); assertEquals(true, subDir.exists()); assertEquals(false, subFile.exists()); // delete dir FileDeleteStrategy.NORMAL.delete(subDir); assertEquals(false, subDir.exists()); // delete dir FileDeleteStrategy.NORMAL.delete(subDir); // no error assertEquals(false, subDir.exists()); } public void testDeleteQuietlyNormal() throws Exception { File baseDir = getTestDirectory(); File subDir = new File(baseDir, "test"); assertEquals(true, subDir.mkdir()); File subFile = new File(subDir, "a.txt"); createFile(subFile, 16); assertEquals(true, subDir.exists()); assertEquals(true, subFile.exists()); // delete dir assertEquals(false, FileDeleteStrategy.NORMAL.deleteQuietly(subDir)); assertEquals(true, subDir.exists()); assertEquals(true, subFile.exists()); // delete file assertEquals(true, FileDeleteStrategy.NORMAL.deleteQuietly(subFile)); assertEquals(true, subDir.exists()); assertEquals(false, subFile.exists()); // delete dir assertEquals(true, FileDeleteStrategy.NORMAL.deleteQuietly(subDir)); assertEquals(false, subDir.exists()); // delete dir assertEquals(true, FileDeleteStrategy.NORMAL.deleteQuietly(subDir)); // no error assertEquals(false, subDir.exists()); } public void testDeleteForce() throws Exception { File baseDir = getTestDirectory(); File subDir = new File(baseDir, "test"); assertEquals(true, subDir.mkdir()); File subFile = new File(subDir, "a.txt"); createFile(subFile, 16); assertEquals(true, subDir.exists()); assertEquals(true, subFile.exists()); // delete dir FileDeleteStrategy.FORCE.delete(subDir); assertEquals(false, subDir.exists()); assertEquals(false, subFile.exists()); // delete dir FileDeleteStrategy.FORCE.delete(subDir); // no error assertEquals(false, subDir.exists()); } public void testDeleteNull() throws Exception { try { FileDeleteStrategy.NORMAL.delete((File) null); fail(); } catch (NullPointerException ex) { // expected } assertEquals(true, FileDeleteStrategy.NORMAL.deleteQuietly((File) null)); } public void testToString() { assertEquals("FileDeleteStrategy[Normal]", FileDeleteStrategy.NORMAL.toString()); assertEquals("FileDeleteStrategy[Force]", FileDeleteStrategy.FORCE.toString()); } } Other Commons IO examples (source code examples)Here is a short list of links related to this Commons IO FileDeleteStrategyTestCase.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.