1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2008, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package ch.qos.logback.core.util;
11  
12  
13  import static org.junit.Assert.assertFalse;
14  import static org.junit.Assert.assertTrue;
15  
16  import java.io.File;
17  import java.util.ArrayList;
18  import java.util.List;
19  import java.util.Random;
20  
21  import org.junit.After;
22  import org.junit.Before;
23  import org.junit.Test;
24  
25  public class FileUtilTest {
26  
27    List<File> cleanupList = new ArrayList<File>();
28    
29    @Before
30    public void setUp() throws Exception {
31      
32    }
33  
34    @After
35    public void tearDown() throws Exception {
36      for(File f: cleanupList) {
37        f.delete();
38      }
39    }
40  
41    
42    @Test
43    public void smoke() {
44      int diff =  new Random().nextInt(100);
45      File file = new File(Constants.OUTPUT_DIR_PREFIX+"/fu"+diff+"/testing.txt");
46      // these will be deleted later
47      cleanupList.add(file);
48      cleanupList.add(file.getParentFile());
49  
50      assertTrue(FileUtil.mustCreateParentDirectories(file));
51      assertTrue(FileUtil.createMissingParentDirectories(file));
52      assertFalse(FileUtil.mustCreateParentDirectories(file));
53    }
54    
55    @Test
56    public void smokeII() {
57      int diff =  new Random().nextInt(100);
58      File file = new File(Constants.OUTPUT_DIR_PREFIX+"/fu"+diff+"/bla/testing.txt");
59      // these will be deleted later
60      cleanupList.add(file);
61      cleanupList.add(file.getParentFile());
62      cleanupList.add(file.getParentFile().getParentFile());
63      
64      assertTrue(FileUtil.mustCreateParentDirectories(file));
65      assertTrue(FileUtil.createMissingParentDirectories(file));
66      assertFalse(FileUtil.mustCreateParentDirectories(file));
67    }
68  }