1
2
3
4
5 package com.qulice.checkstyle;
6
7 import com.qulice.spi.Violation;
8 import org.hamcrest.Description;
9 import org.hamcrest.TypeSafeMatcher;
10
11
12
13
14
15
16
17 final class ViolationMatcher extends TypeSafeMatcher<Violation> {
18
19
20
21
22 private final String message;
23
24
25
26
27 private final String file;
28
29
30
31
32 private final String line;
33
34
35
36
37 private final String check;
38
39
40
41
42
43
44 ViolationMatcher(final String message, final String file) {
45 this(message, file, "", "");
46 }
47
48
49
50
51
52
53
54
55
56 ViolationMatcher(final String message, final String file,
57 final String line, final String check) {
58 super();
59 this.message = message;
60 this.file = file;
61 this.line = line;
62 this.check = check;
63 }
64
65 @Override
66 public boolean matchesSafely(final Violation item) {
67 return item.message().contains(this.message)
68 && item.file().endsWith(this.file)
69 && this.lineMatches(item)
70 && this.checkMatches(item);
71 }
72
73 @Override
74 public void describeTo(final Description description) {
75 description.appendText("doesn't match");
76 }
77
78
79
80
81
82
83 private boolean checkMatches(final Violation item) {
84 return this.check.isEmpty()
85 || !this.check.isEmpty() && item.name().equals(this.check);
86 }
87
88
89
90
91
92
93 private boolean lineMatches(final Violation item) {
94 return this.line.isEmpty()
95 || !this.line.isEmpty() && item.lines().equals(this.line);
96 }
97 }