Last active
December 21, 2015 00:08
-
-
Save tomoyamkung/6217432 to your computer and use it in GitHub Desktop.
[Java]SuffixFileFilter を使ったファイルフィルタのスニペット。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.tomoyamkung.org.apache.commons.io.filefilter; | |
import static org.hamcrest.CoreMatchers.*; | |
import static org.junit.Assert.*; | |
import java.io.File; | |
import org.apache.commons.io.filefilter.SuffixFileFilter; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class SuffixFileFilterTest { | |
private File dir; | |
@Before | |
public void setUp() throws Exception { | |
dir = new File("testdata/org_apache_commons_io_filefilter/suffix_file_filter_test"); | |
} | |
@Test | |
public void 拡張子がtxtのファイル名を取得する() throws Exception { | |
// Setup | |
String suffix = ".txt"; | |
// Exercise | |
String[] list = dir.list(new SuffixFileFilter(suffix)); | |
// Verify | |
assertThat(list.length, is(2)); | |
assertThat(list[0], is("hoge1.txt")); | |
assertThat(list[1], is("hoge2.txt")); | |
} | |
@Test | |
public void 拡張子がjpgとcsvのファイル名を取得する() throws Exception { | |
// Setup | |
String[] suffix = {".jpg", ".csv"}; | |
// Exercise | |
String[] list = dir.list(new SuffixFileFilter(suffix)); | |
// Verify | |
assertThat(list.length, is(2)); | |
assertThat(list[0], is("piyo.jpg")); | |
assertThat(list[1], is("var.csv")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
テストデータとして、"testdata/org_apache_commons_io_filefilter/suffix_file_filter_test" ディレクトリを作成し、そこに次のファイルを用意する。