01: package org.nanocontainer.deployer;
02:
03: import org.apache.commons.vfs.FileObject;
04: import org.apache.commons.vfs.FileType;
05: import org.jmock.Mock;
06: import org.jmock.MockObjectTestCase;
07: import org.nanocontainer.deployer.DifferenceAnalysingFolderContentHandler;
08: import org.nanocontainer.deployer.FolderListener;
09:
10: /**
11: * @author Aslak Hellesøy
12: * @version $Revision: 2343 $
13: */
14: public class DifferenceAnalysingFolderContentHandlerTestCase extends
15: MockObjectTestCase {
16: public void testAddedFoldersShouldCauseFolderAddedEvent() {
17: Mock folderMock = mock(FileObject.class);
18: DifferenceAnalysingFolderContentHandler handler = new DifferenceAnalysingFolderContentHandler(
19: (FileObject) folderMock.proxy(), null);
20:
21: Mock addedFolderMock = mock(FileObject.class);
22: addedFolderMock.expects(once()).method("getType")
23: .withNoArguments().will(returnValue(FileType.FOLDER));
24: FileObject addedFolder = (FileObject) addedFolderMock.proxy();
25:
26: Mock folderListenerMock = mock(FolderListener.class);
27: folderListenerMock.expects(once()).method("folderAdded").with(
28: same(addedFolder));
29: handler.addFolderListener((FolderListener) folderListenerMock
30: .proxy());
31:
32: handler.setCurrentChildren(new FileObject[] { addedFolder });
33: }
34:
35: public void testRemovedFoldersShouldCauseFolderRemovedEvent() {
36: Mock folderMock = mock(FileObject.class);
37: DifferenceAnalysingFolderContentHandler handler = new DifferenceAnalysingFolderContentHandler(
38: (FileObject) folderMock.proxy(), null);
39:
40: Mock initialFolderOneMock = mock(FileObject.class);
41: initialFolderOneMock.expects(once()).method("getType")
42: .withNoArguments().will(returnValue(FileType.FOLDER));
43: FileObject initialFolderOne = (FileObject) initialFolderOneMock
44: .proxy();
45: Mock initialFolderTwoMock = mock(FileObject.class);
46: initialFolderTwoMock.expects(once()).method("getType")
47: .withNoArguments().will(returnValue(FileType.FOLDER));
48: initialFolderTwoMock.expects(once()).method("getType")
49: .withNoArguments().will(returnValue(FileType.FOLDER));
50: FileObject initialFolderTwo = (FileObject) initialFolderTwoMock
51: .proxy();
52: FileObject[] initialFolders = new FileObject[] {
53: initialFolderOne, initialFolderTwo };
54:
55: handler.setCurrentChildren(initialFolders);
56:
57: FileObject[] foldersAfterRemoval = new FileObject[] { initialFolderOne };
58: Mock folderListenerMock = mock(FolderListener.class);
59: folderListenerMock.expects(once()).method("folderRemoved")
60: .with(same(initialFolderTwo));
61: handler.addFolderListener((FolderListener) folderListenerMock
62: .proxy());
63:
64: handler.setCurrentChildren(foldersAfterRemoval);
65: }
66: }
|