001/* 002 * Copyright 2015 DuraSpace, Inc. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.fcrepo.migration.foxml; 017 018/** 019 * @author mdurbin 020 */ 021import java.io.File; 022import java.util.regex.Pattern; 023 024import org.apache.commons.io.filefilter.RegexFileFilter; 025import org.junit.Assert; 026import org.junit.Before; 027import org.junit.Test; 028import org.junit.runner.RunWith; 029import org.mockito.Mock; 030import org.mockito.Mockito; 031import org.mockito.junit.MockitoJUnitRunner; 032 033@RunWith(MockitoJUnitRunner.class) 034public class FoxmlDirectoryDFSIteratorTest { 035 036 @Mock private File root; 037 038 @Mock private File f1; 039 040 @Before 041 public void setup() { 042 Mockito.when(root.listFiles()).thenReturn(new File[] { f1 }); 043 044 Mockito.when(f1.isFile()).thenReturn(true); 045 Mockito.when(f1.getName()).thenReturn(".hidden"); 046 047 } 048 049 @Test 050 public void testNonHiddenInclusionPattern() { 051 final FoxmlDirectoryDFSIterator i 052 = new FoxmlDirectoryDFSIterator(root, null, null, new RegexFileFilter(Pattern.compile("^[^\\.].*$"))); 053 Assert.assertFalse("There must not be a matching file.", i.hasNext()); 054 } 055 056 @Test 057 public void testIncludeAllPattern() { 058 final FoxmlDirectoryDFSIterator i 059 = new FoxmlDirectoryDFSIterator(root, null, null, new RegexFileFilter(Pattern.compile(".*"))); 060 Assert.assertTrue("There should be a matching file.", i.hasNext()); 061 } 062 063}