001/**
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 *
006 */
007package org.fcrepo.migration.foxml;
008
009/**
010 * @author mdurbin
011 */
012import java.io.File;
013import java.util.regex.Pattern;
014
015import org.apache.commons.io.filefilter.RegexFileFilter;
016import org.junit.Assert;
017import org.junit.Before;
018import org.junit.Test;
019import org.junit.runner.RunWith;
020import org.mockito.Mock;
021import org.mockito.Mockito;
022import org.mockito.junit.MockitoJUnitRunner;
023
024@RunWith(MockitoJUnitRunner.class)
025public class FoxmlDirectoryDFSIteratorTest {
026
027    @Mock private File root;
028
029    @Mock private File f1;
030
031    @Before
032    public void setup() {
033        Mockito.when(root.listFiles()).thenReturn(new File[] { f1 });
034
035        Mockito.when(f1.isFile()).thenReturn(true);
036        Mockito.when(f1.getName()).thenReturn(".hidden");
037
038    }
039
040    @Test
041    public void testNonHiddenInclusionPattern() {
042        final FoxmlDirectoryDFSIterator i
043               = new FoxmlDirectoryDFSIterator(root, null, null, new RegexFileFilter(Pattern.compile("^[^\\.].*$")));
044        Assert.assertFalse("There must not be a matching file.", i.hasNext());
045    }
046
047    @Test
048    public void testIncludeAllPattern() {
049        final FoxmlDirectoryDFSIterator i
050               = new FoxmlDirectoryDFSIterator(root, null, null, new RegexFileFilter(Pattern.compile(".*")));
051        Assert.assertTrue("There should be a matching file.", i.hasNext());
052    }
053
054}