1
2
3
4
5
6
7 package com.varmateo.testutils;
8
9 import java.nio.file.Files;
10 import java.nio.file.Path;
11 import java.io.IOException;
12 import java.util.List;
13 import java.util.stream.Collectors;
14
15 import org.assertj.core.api.ListAssert;
16 import org.assertj.core.api.PathAssert;
17
18
19
20
21
22 public final class DirPathAssert
23 extends PathAssert {
24
25
26
27
28
29 public static DirPathAssert assertThatDir(final Path actual) {
30
31 return new DirPathAssert(actual);
32 }
33
34
35
36
37
38 public DirPathAssert(final Path actual) {
39
40 super(actual);
41 }
42
43
44
45
46
47 public ListAssert<String> entryNames()
48 throws IOException {
49
50 isNotNull();
51
52 List<String> entries =
53 Files.list(actual)
54 .map(Path::getFileName)
55 .map(Object::toString)
56 .collect(Collectors.toList());
57
58 return new ListAssert<String>(entries);
59 }
60
61
62
63
64
65 public ListAssert<String> sortedEntryNames()
66 throws IOException {
67
68 isNotNull();
69
70 List<String> entries =
71 Files.list(actual)
72 .map(Path::getFileName)
73 .map(Object::toString)
74 .sorted()
75 .collect(Collectors.toList());
76
77 return new ListAssert<String>(entries);
78 }
79
80
81 }