### Question:
FileSystemFilter { String getTopLevel(String path) { return getTopLevel(this.currentDirectory, path); }  String getSearchString(); Mode getMode(); boolean isAutoChangeDirectoryToLeafItem(); String getCurrentDirectory(); int getMaxResultSize(); Integer getFileNumber(); boolean isFinished(); FileSystemFilter setAutoChangeDirectoryToLeafItem(boolean autoChangeDirectoryToLeafItem); FileSystemFilter setMaxResultSize(int maxResultSize); FileSystemFilter setFileNumber(Integer fileNumber); boolean matches(BorgFilesystemItem item); List<BorgFilesystemItem> reduce(List<BorgFilesystemItem> origList); FileSystemFilter setSearchString(String searchString); FileSystemFilter setMode(String mode); FileSystemFilter setMode(Mode mode); FileSystemFilter setCurrentDirectory(String currentDirectory);  }### Answer:
@Test void getTopLevelTest() { FileSystemFilter filter = new FileSystemFilter(); assertEquals("home", filter.getTopLevel("home")); assertEquals("home", filter.getTopLevel("home/test")); assertEquals("home", filter.getTopLevel("home/")); filter.setCurrentDirectory("home"); assertNull(filter.getTopLevel("home")); assertEquals("kai", filter.getTopLevel("home/kai")); assertEquals("kai", filter.getTopLevel("home/kai/test.java")); assertNull(filter.getTopLevel("etc/test")); List<BorgFilesystemItem> list = createList(); filter.setCurrentDirectory("").setMode(FileSystemFilter.Mode.TREE); for (BorgFilesystemItem item : list) { if (filter.matches(item)) { } } list = filter.reduce(list); assertEquals(3, list.size()); assertEquals("home", list.get(0).getDisplayPath()); assertEquals("etc", list.get(1).getDisplayPath()); assertEquals("opt", list.get(2).getDisplayPath()); assertEquals("opt", list.get(2).getPath()); assertEquals(-1, list.get(2).getFileNumber()); assertEquals("d", list.get(2).getType()); assertNull(list.get(2).getMode()); list = createList(); filter.setCurrentDirectory("home"); for (BorgFilesystemItem item : list) { if (filter.matches(item)) { } } list = filter.reduce(list); assertEquals(4, list.size()); assertEquals("admin", list.get(0).getDisplayPath()); assertEquals("drwxr-xr-x", list.get(0).getMode()); assertEquals("kai", list.get(1).getDisplayPath()); assertEquals("drwxr-xr-x", list.get(1).getMode()); assertEquals(".bashrc", list.get(2).getDisplayPath()); assertEquals("-rw-r--r--", list.get(2).getMode()); assertEquals(".borgbutler", list.get(3).getDisplayPath()); list = createList(); filter.setCurrentDirectory("opt"); for (BorgFilesystemItem item : list) { if (filter.matches(item)) { } } list = filter.reduce(list); assertEquals(2, list.size()); assertEquals("openhab", list.get(0).getDisplayPath()); assertEquals("vbox-backups", list.get(1).getDisplayPath()); list = createList(); filter.setCurrentDirectory("home/admin"); for (BorgFilesystemItem item : list) { if (filter.matches(item)) { } } list = filter.reduce(list); assertEquals(1, list.size()); assertEquals("test.txt", list.get(0).getDisplayPath()); }