1 package com.atlassian.webdriver.matchers;
2
3 import org.hamcrest.Description;
4 import org.hamcrest.Matcher;
5 import org.hamcrest.TypeSafeMatcher;
6
7 import java.io.File;
8
9 import static com.google.common.base.Preconditions.checkNotNull;
10
11
12
13
14
15
16 public final class FileMatchers
17 {
18
19 private FileMatchers()
20 {
21 throw new AssertionError("Don't instantiate me");
22 }
23
24 public static Matcher<File> hasAbsolutePath(final String absolutePath)
25 {
26 checkNotNull(absolutePath, "absolutePath");
27 return new TypeSafeMatcher<File>()
28 {
29 @Override
30 public boolean matchesSafely(File item)
31 {
32 return item != null && absolutePath.equals(item.getAbsolutePath());
33 }
34
35 @Override
36 public void describeTo(Description description)
37 {
38 description.appendText("A File with absolute path ").appendValue(absolutePath);
39 }
40 };
41 }
42
43 public static Matcher<File> exists()
44 {
45 return new TypeSafeMatcher<File>()
46 {
47 @Override
48 public boolean matchesSafely(File item)
49 {
50 return item.exists();
51 }
52
53 @Override
54 public void describeTo(Description description)
55 {
56 description.appendText("A file or directory that exists");
57 }
58 };
59 }
60
61 public static Matcher<File> isDirectory()
62 {
63 return new TypeSafeMatcher<File>()
64 {
65 @Override
66 public boolean matchesSafely(File item)
67 {
68 return item.isDirectory();
69 }
70
71 @Override
72 public void describeTo(Description description)
73 {
74 description.appendText("An existing directory");
75 }
76 };
77 }
78
79 public static Matcher<File> isFile()
80 {
81 return new TypeSafeMatcher<File>()
82 {
83 @Override
84 public boolean matchesSafely(File item)
85 {
86 return item.isFile();
87 }
88
89 @Override
90 public void describeTo(Description description)
91 {
92 description.appendText("An existing file");
93 }
94 };
95 }
96 }