File asserrtions with Hamcrest

0 views
Skip to first unread message

JamesRichardson

unread,
Nov 28, 2007, 4:37:33 PM11/28/07
to Hamcrest Java Users
Something of very little consequence:

http://www.time4tea.net/wiki/display/MAIN/Testing+Files+with+Hamcrest

Just wraps the assertions in the java.io.File class with hamcrest
matchers.

May be useful to somebody..

Cheers

James

Nat Pryce

unread,
Nov 28, 2007, 5:10:35 PM11/28/07
to hamcre...@googlegroups.com
Sweet. That gave me two ideas.

Firstly, an implementation of FileFilter that delegates to a matcher.

Secondly, a compiler that takes any class and translates all isXXX
boolean property accessors to matchers and all getXXX property
accessors to "has" matchers.

--Nat

JamesRichardson

unread,
Nov 28, 2007, 6:46:39 PM11/28/07
to Hamcrest Java Users
The first one shouldn't take long!

import org.hamcrest.Matcher;

import java.io.File;
import java.io.FileFilter;

public class FileFilterMatcher implements FileFilter {

private final Matcher<File> matcher;

public FileFilterMatcher(Matcher<File> matcher) {
this.matcher = matcher;
}

public boolean accept(File file) {
return matcher.matches(file);
Reply all
Reply to author
Forward
0 new messages