|
1 | 1 | package org.hamcrest.io;
|
2 | 2 |
|
3 | 3 | import org.hamcrest.Description;
|
4 |
| -import org.hamcrest.FeatureMatcher; |
| 4 | +import org.hamcrest.FunctionMatcher; |
| 5 | +import org.hamcrest.FunctionMatcher.Feature; |
5 | 6 | import org.hamcrest.Matcher;
|
6 | 7 | import org.hamcrest.TypeSafeDiagnosingMatcher;
|
7 | 8 |
|
@@ -37,33 +38,20 @@ public static Matcher<File> aFileWithSize(long size) {
|
37 | 38 | }
|
38 | 39 |
|
39 | 40 | public static Matcher<File> aFileWithSize(final Matcher<Long> expected) {
|
40 |
| - return new FeatureMatcher<File, Long>(expected, "A file with size", "size") { |
41 |
| - @Override protected Long featureValueOf(File actual) { return actual.length(); } |
42 |
| - }; |
| 41 | + return new FunctionMatcher<>("A file with size", "size", expected, LENGTH); |
43 | 42 | }
|
44 | 43 |
|
45 | 44 | public static Matcher<File> aFileNamed(final Matcher<String> expected) {
|
46 |
| - return new FeatureMatcher<File, String>(expected, "A file with name", "name") { |
47 |
| - @Override protected String featureValueOf(File actual) { return actual.getName(); } |
48 |
| - }; |
| 45 | + return new FunctionMatcher<>("A file with name", "name", expected, NAME); |
49 | 46 | }
|
50 | 47 |
|
51 | 48 | public static Matcher<File> aFileWithCanonicalPath(final Matcher<String> expected) {
|
52 |
| - return new FeatureMatcher<File, String>(expected, "A file with canonical path", "path") { |
53 |
| - @Override protected String featureValueOf(File actual) { |
54 |
| - try { |
55 |
| - return actual.getCanonicalPath(); |
56 |
| - } catch (IOException e) { |
57 |
| - return "Exception: " + e.getMessage(); |
58 |
| - } |
59 |
| - } |
60 |
| - }; |
| 49 | + return new FunctionMatcher<>("A file with canonical path", "path", expected, CANONICAL_PATH); |
61 | 50 | }
|
62 | 51 |
|
| 52 | + |
63 | 53 | public static Matcher<File> aFileWithAbsolutePath(final Matcher<String> expected) {
|
64 |
| - return new FeatureMatcher<File, String>(expected, "A file with absolute path", "path") { |
65 |
| - @Override protected String featureValueOf(File actual) { return actual.getAbsolutePath(); } |
66 |
| - }; |
| 54 | + return new FunctionMatcher<>("A file with absolute path", "path", expected, ABSOLUTE_PATH); |
67 | 55 | }
|
68 | 56 |
|
69 | 57 | public static interface FileStatus {
|
@@ -104,4 +92,25 @@ public void describeTo(Description description) {
|
104 | 92 | }
|
105 | 93 | };
|
106 | 94 | }
|
| 95 | + |
| 96 | + private static final Feature<File, String> ABSOLUTE_PATH = new Feature<File, String>() { |
| 97 | + @Override public String from(File actual) { return actual.getAbsolutePath(); } |
| 98 | + }; |
| 99 | + public static final Feature<File, Long> LENGTH = new Feature<File, Long>() { |
| 100 | + @Override public Long from(File actual) { return actual.length(); } |
| 101 | + }; |
| 102 | + |
| 103 | + public static final Feature<File, String> NAME = new Feature<File, String>() { |
| 104 | + @Override public String from(File actual) { return actual.getName(); } |
| 105 | + }; |
| 106 | + |
| 107 | + public static final Feature<File, String> CANONICAL_PATH = new Feature<File, String>() { |
| 108 | + @Override public String from(File actual) { |
| 109 | + try { |
| 110 | + return actual.getCanonicalPath(); |
| 111 | + } catch (IOException e) { |
| 112 | + return "Exception: " + e.getMessage(); |
| 113 | + } |
| 114 | + } |
| 115 | + }; |
107 | 116 | }
|
0 commit comments