/* * DirectoryMonitorTest.java * * Created 26.05.2007. * * eaio: NativeCall - calling operating system methods from Java * Copyright (c) 2004-2007 Johann Burkard () * * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * 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 com.eaio.nativecall.monitor; import java.io.File; import java.io.IOException; import java.util.Arrays; import sun.misc.ServiceConfigurationError; import junit.framework.TestCase; /** * Test case for {@link DirectoryMonitor}. * * @author Johann Burkard * @version $Id: DirectoryMonitorTest.java 59 2008-01-24 20:17:19Z Johann $ */ public class DirectoryMonitorTest extends TestCase { /** * Constructor for DirectoryMonitorTest. * */ public DirectoryMonitorTest() { } /** * Constructor for DirectoryMonitorTest. * * @param arg0 */ public DirectoryMonitorTest(String arg0) { super(arg0); } public void testDirectoryMonitor() throws SecurityException, UnsatisfiedLinkError, UnsupportedOperationException, IOException, ServiceConfigurationError { final DirectoryMonitor mon = new DirectoryMonitor(new File(".")); final String[] contents = new File(".").list(); Arrays.sort(contents); new Thread(new Runnable() { public void run() { try { mon.monitor(); System.out.println("Contents have changed!"); System.out.println("Before"); for (int i = 0; i < contents.length; ++i) { System.out.println(contents[i]); } // Make sure changes are accessible to Java try { Thread.sleep(100); } catch (InterruptedException ex) {} System.out.println("After"); String[] current = new File(".").list(); Arrays.sort(current); for (int i = 0; i < current.length; ++i) { System.out.println(current[i]); } assertFalse(Arrays.equals(current, contents)); } catch (IOException ex) { fail(ex.toString()); } } }).start(); try { Thread.sleep(100); } catch (InterruptedException ex) {} File tempFile = new File(new File("."), "temp"); assertTrue(tempFile.createNewFile()); try { Thread.sleep(500); } catch (InterruptedException ex) {} assertTrue(tempFile.delete()); } }