INT-1520: add AntPatternFileListFilter

This commit is contained in:
Iwein Fuld
2010-10-14 19:21:36 +02:00
parent 695961c2ba
commit 037d2113f8
2 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package org.springframework.integration.file.filters;
import org.springframework.integration.file.entries.AbstractEntryListFilter;
import org.springframework.util.AntPathMatcher;
import java.io.File;
/**
* @author Iwein Fuld
*/
public class AntPatternFileListFilter extends AbstractEntryListFilter<File> {
private final AntPathMatcher matcher = new AntPathMatcher();
private final String path;
public AntPatternFileListFilter(String path) {
this.path = path;
}
@Override
public boolean accept(File file) {
return matcher.match( path, file.getPath());
}
}

View File

@@ -0,0 +1,32 @@
package org.springframework.integration.file.filters;
import org.junit.Test;
import java.io.File;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* @author Iwein Fuld
*
* Minimal test set to ensure AntPathMatcher is used correctly.
*/
public class AntPatternFileListFilterTest {
@Test
public void shouldMatchExactly() {
assertThat(new AntPatternFileListFilter("foo/bar").accept(new File("foo/bar")), is(true));
}
@Test
public void shouldMatchQuestionMark() {
assertThat(new AntPatternFileListFilter("*/bar").accept(new File("foo/bar")), is(true));
}
@Test
public void shouldMatchWildcard() {
assertThat(new AntPatternFileListFilter("foo/ba?").accept(new File("foo/bar")), is(true));
}
}