1 package org.apidesign.unionfs;
3 import java.util.Arrays;
4 import java.util.HashSet;
6 import org.junit.After;
7 import org.junit.AfterClass;
8 import org.junit.Before;
9 import org.junit.BeforeClass;
10 import org.junit.Test;
11 import org.openide.filesystems.FileObject;
12 import static org.junit.Assert.*;
13 import org.openide.filesystems.FileSystem;
14 import org.xml.sax.SAXException;
16 public class UnionFSTest {
18 public UnionFSTest() {
22 public static void setUpClass() throws Exception {
26 public static void tearDownClass() throws Exception {
34 public void tearDown() {
38 public void union() throws SAXException {
39 FileSystem one = UnionFS.fromResource(UnionFSTest.class.getResource("fs-one.xml"));
40 assertChildren("There is just one file in the folder", one, "Menu", "Open.instance");
42 FileSystem two = UnionFS.fromResource(UnionFSTest.class.getResource("fs-two.xml"));
43 assertChildren("There is just one file in the other folder", two, "Menu", "Close.instance");
45 FileSystem union = UnionFS.union(one, two);
46 assertChildren("There both in the union", union, "Menu", "Open.instance", "Close.instance");
49 private static void assertChildren(String msg, FileSystem fs, String folder, String... expect) {
50 Set<String> names = new HashSet<String>();
51 names.addAll(Arrays.asList(expect));
53 FileObject fo = fs.getRoot().getFileObject(folder);
54 assertNotNull(msg + " folder " + folder + " has to exist", fo);
56 for (FileObject ch : fo.getChildren()) {
57 names.remove(ch.getNameExt());
60 if (!names.isEmpty()) {
61 fail(msg + " - expected files not found " + names);