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
18 final class ViolationMatcher extends TypeSafeMatcher<Violation> {
19
20
21
22
23 private final String message;
24
25
26
27
28 private final String file;
29
30
31
32
33 private final String line;
34
35
36
37
38 private final String check;
39
40
41
42
43
44
45
46 ViolationMatcher(final String message, final String file) {
47 this(message, file, "", "");
48 }
49
50
51
52
53
54
55
56
57
58 ViolationMatcher(final String message, final String file,
59 final String line, final String check) {
60 super();
61 this.message = message;
62 this.file = file;
63 this.line = line;
64 this.check = check;
65 }
66
67 @Override
68 public boolean matchesSafely(final Violation item) {
69 return item.message().contains(this.message)
70 && item.file().endsWith(this.file)
71 && this.lineMatches(item)
72 && this.checkMatches(item);
73 }
74
75 @Override
76 public void describeTo(final Description description) {
77 description.appendText("doesn't match");
78 }
79
80 private boolean checkMatches(final Violation item) {
81 return this.check.isEmpty()
82 || !this.check.isEmpty() && item.name().equals(this.check);
83 }
84
85 private boolean lineMatches(final Violation item) {
86 return this.line.isEmpty()
87 || !this.line.isEmpty() && item.lines().equals(this.line);
88 }
89 }