testsupport: prefer TemporaryFolder over DelTree junit rule See 86b89c63309f5fa985da92e3eabf33af5079be22
Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/3562f7f8 Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/3562f7f8 Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/3562f7f8 Branch: refs/heads/develop Commit: 3562f7f8c930d24a2aba9548f85f13f0a7392168 Parents: c3b6247 Author: Paul Merlin <[email protected]> Authored: Sat Nov 19 16:49:21 2016 +0100 Committer: Paul Merlin <[email protected]> Committed: Sat Nov 19 16:49:21 2016 +0100 ---------------------------------------------------------------------- .../org/apache/zest/test/util/DelTreeAfter.java | 105 ------------------- 1 file changed, 105 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-java/blob/3562f7f8/core/testsupport/src/main/java/org/apache/zest/test/util/DelTreeAfter.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/util/DelTreeAfter.java b/core/testsupport/src/main/java/org/apache/zest/test/util/DelTreeAfter.java deleted file mode 100644 index 24abb1a..0000000 --- a/core/testsupport/src/main/java/org/apache/zest/test/util/DelTreeAfter.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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.zest.test.util; - -import java.io.File; -import java.io.IOException; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - -/** - * JUnit Test Rule that delete directories after the test. - */ -public class DelTreeAfter - implements TestRule -{ - - private final boolean createDirsBefore; - private final File[] directories; - - public DelTreeAfter( File... directories ) - { - this( false, directories ); - } - - public DelTreeAfter( boolean createDirsBefore, File[] directories ) - { - this.createDirsBefore = createDirsBefore; - this.directories = directories; - } - - @Override - public Statement apply( final Statement base, Description description ) - { - return new Statement() - { - @Override - public void evaluate() - throws Throwable - { - if( createDirsBefore ) - { - for( File dir : directories ) - { - if( !dir.mkdirs() ) - { - throw new IOException( "Unable to create directory: " + dir ); - } - } - } - try - { - base.evaluate(); - } - finally - { - if( directories != null ) - { - for( File dir : directories ) - { - if( dir.exists() ) - { - delTree( dir ); - } - } - } - } - } - }; - } - - private static void delTree( File dir ) - { - if( dir.isDirectory() ) - { - for( File file : dir.listFiles() ) - { - delTree( file ); - } - dir.delete(); - } - else - { - dir.delete(); - } - } - -}
