Java tutorial
/** * Copyright (c) 2015 by the original author or authors. This code is free * software; you can redistribute it and/or modify it under the terms of the GNU * Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. The * above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package ch.bender.evacuate; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import mockit.Tested; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; /** * TODO Hey Heri, comment this type please ! * * @author Heri */ public class RunnerCheckDirectoriesTest { /** logger for this class */ private static Logger myLog = LogManager.getLogger(RunnerCheckDirectoriesTest.class); @Tested Runner myClassUnderTest; /** * Executed at loading of this class (static inizalizer). * <p> * @throws Throwable * On any problem */ @BeforeClass public static final void doBeforeClass() throws Throwable { System.out.println("doBeforeClass() entering..."); try { if (Files.exists(Testconstants.ROOT_DIR)) { Helper.deleteDirRecursive(Testconstants.ROOT_DIR); } Files.createDirectory(Testconstants.ROOT_DIR); Path orig = Testconstants.createNewFolder(Testconstants.ROOT_DIR, "orig"); Path origSub1 = Testconstants.createNewFolder(orig, "sub1"); Path origSub2 = Testconstants.createNewFolder(orig, "sub2"); Path file1 = Testconstants.createNewFile(orig, "file1.txt"); Path fileSub1 = Testconstants.createNewFile(origSub1, "fileSub1.txt"); Path fileSub2 = Testconstants.createNewFile(origSub2, "fileSub2.txt"); Path backup = Testconstants.createNewFolder(Testconstants.ROOT_DIR, "backup"); FileUtils.copyDirectoryToDirectory(origSub1.toFile(), backup.toFile()); FileUtils.copyDirectoryToDirectory(origSub2.toFile(), backup.toFile()); } catch (Throwable e) { System.err.println("Throwable caught in doBeforeClass()"); e.printStackTrace(); throw e; } System.out.println("doBeforeClass() leaving..."); } /** * Executed at the end of all tests. * <p> * * @throws Throwable * On any problem */ @AfterClass public static final void doAfterClass() throws Throwable { System.out.println("doAfterClass() entering..."); try { if (Files.exists(Testconstants.ROOT_DIR)) { Helper.deleteDirRecursive(Testconstants.ROOT_DIR); } System.out.println("doAfterClass() leaving..."); } catch (Throwable e) { System.err.println("Throwable caught in doAfterClass()"); e.printStackTrace(); } } /** * This method is executed just before each test method * * @throws Throwable * On any problem (test method will not be executed) */ @Before public void setUp() throws Throwable { myLog.debug("entering"); try { // TODO (autogenerated method stub) } catch (Throwable t) { myLog.error("Throwable caught in setup", t); throw t; } } /** * Test method for {@link ch.bender.evacuate.Runner#checkDirectories()}. */ @Test public void testCheckDirectories() { myClassUnderTest.setOrigDir(Paths.get(Testconstants.ROOT_DIR.toString(), "orig").toString()); myClassUnderTest.setBackupDir(Paths.get(Testconstants.ROOT_DIR.toString(), "backup").toString()); myClassUnderTest.setEvacuateDir(Paths.get(Testconstants.ROOT_DIR.toString(), "evacuate").toString()); // // ROOT_DIR = Paths.get( TEST_SANDBOX_DIR_STR ); // Files.createDirectory( ROOT_DIR ); // // Path orig = createNewFolder( ROOT_DIR, "orig" ); // Path origSub1 = createNewFolder( orig, "sub1" ); // Path origSub2 = createNewFolder( orig, "sub2" ); // // Path file1 = createNewFile( orig, "file1.txt" ); // Path fileSub1 = createNewFile( origSub1, "fileSub1.txt" ); // Path fileSub2 = createNewFile( origSub2, "fileSub2.txt" ); // // Path backup = createNewFolder( ROOT_DIR, "backup" ); // // private String myOrigDirStr; // private String myBackupDirStr; // private String myEvacuateDirStr; } }