KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > deployer > FolderContentPollerTestCase


1 package org.nanocontainer.deployer;
2
3 import org.apache.commons.vfs.FileObject;
4 import org.jmock.Mock;
5 import org.jmock.MockObjectTestCase;
6 import org.nanocontainer.deployer.FolderContentHandler;
7 import org.nanocontainer.deployer.FolderContentPoller;
8
9 /**
10  * @author Aslak Hellesøy
11  * @version $Revision: 2343 $
12  */

13 public class FolderContentPollerTestCase extends MockObjectTestCase {
14
15     public void testShouldPollForNewFoldersAtRegularIntervals() throws InterruptedException JavaDoc {
16         Mock rootFolderMock = mock(FileObject.class, "rootFolder");
17         FileObject[] noChildren = new FileObject[0];
18
19         // Adding a child that will be returned at the second invocation of getChildren
20
Mock newChildFolderMock = mock(FileObject.class, "childFolder");
21         FileObject[] newChildren = new FileObject[] {(FileObject) newChildFolderMock.proxy()};
22
23         Mock folderContentHandlerMock = mock(FolderContentHandler.class, "folderContentHandlerMock");
24
25         folderContentHandlerMock.expects(once())
26                                 .method("getFolder")
27                                 .withNoArguments()
28                                 .will(returnValue(rootFolderMock.proxy()));
29
30         rootFolderMock.expects(once())
31                       .method("close")
32                       .withNoArguments();
33         rootFolderMock.expects(once())
34                       .method("getChildren")
35                       .withNoArguments()
36                       .will(returnValue(noChildren));
37         folderContentHandlerMock.expects(once())
38                                 .method("setCurrentChildren")
39                                 .with(same(noChildren));
40         FolderContentPoller fileMonitor = new FolderContentPoller((FolderContentHandler) folderContentHandlerMock.proxy());
41
42         fileMonitor.start();
43         synchronized(fileMonitor) {
44             fileMonitor.wait(200);
45         }
46
47         rootFolderMock.expects(once())
48                       .method("close")
49                       .withNoArguments();
50         rootFolderMock.expects(once())
51                       .method("getChildren")
52                       .withNoArguments()
53                       .will(returnValue(newChildren));
54         folderContentHandlerMock.expects(once())
55                                 .method("setCurrentChildren")
56                                 .with(same(newChildren));
57
58
59         synchronized(fileMonitor) {
60             fileMonitor.notify();
61             fileMonitor.wait(200);
62         }
63         fileMonitor.stop();
64     }
65 }
Popular Tags