1   /* $Id: DirectoryFileStateMonitorTest.java,v 1.2 2004/06/03 15:50:24 johndavidtaylor Exp $
2    * Created on Apr 26, 2004 by jdt@roe.ac.uk
3    * The alipes project
4    *
5    */
6   package org.abraracourcix.alipes.monitors.file;
7   
8   import java.io.File;
9   import java.io.IOException;
10  import java.util.ArrayList;
11  import java.util.Iterator;
12  import java.util.List;
13  
14  import junit.framework.TestCase;
15  
16  /***
17   * To change the template for this generated type comment go to
18   * Window - Preferences - Java - Code Generation - Code and Comments
19   * 
20   * @author jdt
21   */
22  public class DirectoryFileStateMonitorTest extends TestCase {
23      /***
24       * Commons logger
25       */
26      private static final org.apache.commons.logging.Log log =
27          org.apache.commons.logging.LogFactory.getLog(
28              DirectoryFileStateMonitorTest.class);
29      /***
30       * Fire up the text UI
31       * @param args ignored
32       */
33      public static void main(final String[] args) {
34          junit.textui.TestRunner.run(DirectoryFileStateMonitorTest.class);
35      }
36      /***
37       * The list of files to be created for testing
38       */
39      private static final String[] TEST_FILE_NAMES= {"foo","bar"};
40      /***
41       * Collection of test files
42       */
43      private List testFiles = new ArrayList();
44      /***
45       * The test directory
46       */
47      private File dir;
48      /***
49       * the monitor under test
50       */
51      private AbstractFileStateMonitor monitor;
52      
53      /***
54       * Usual setup method
55       * @see TestCase#setUp()
56       */
57      protected void setUp() throws Exception {
58          super.setUp();
59          for (int i = 0; i<TEST_FILE_NAMES.length;++i) {
60              final File file = File.createTempFile(TEST_FILE_NAMES[i],"txt");
61              testFiles.add(file);
62          }
63         final File firstFile = (File) testFiles.get(0);
64         dir = firstFile.getParentFile();
65         monitor = new DirectoryFileStateMonitor(null,0,dir);
66      }
67      /***
68       * Usual teardown method
69       * @see TestCase#tearDown()
70       */
71      protected final void tearDown() throws IOException {
72          final Iterator it = testFiles.iterator();
73          while (it.hasNext()) {
74              final File file = (File) it.next();
75              file.delete();
76          }
77      }
78     
79      /***
80       * Test that the setter and getter are working
81       * @throws IOException shouldn't
82       */
83      public final void testGetSetStaleInterval() throws IOException {
84          final int testVal = 100;
85          monitor.setStaleInterval(testVal);
86          assertEquals("Returned stale interval not correct", testVal, monitor.getStaleInterval());
87      }
88  }
89  
90  
91  /*
92   *  $Log: DirectoryFileStateMonitorTest.java,v $
93   *  Revision 1.2  2004/06/03 15:50:24  johndavidtaylor
94   *  Refactored DirChangeFileStateMonitor's behaviour when 
95   *  the directory it monitors disappears.  Wired up the DirChangeEmailAlerter.
96   *
97   *  Revision 1.1  2004/04/27 11:00:35  johndavidtaylor
98   *  new tests
99   *
100  */