1
2
3
4
5 package com.qulice.errorprone;
6
7 import org.hamcrest.MatcherAssert;
8 import org.hamcrest.Matchers;
9 import org.junit.jupiter.api.Assertions;
10 import org.junit.jupiter.api.Test;
11
12
13
14
15
16
17 final class XpluginTest {
18
19 @Test
20 void switchesQuliceOwnPatternsOff() {
21 MatcherAssert.assertThat(
22 "the patterns Qulice disables must always be disabled",
23 new Xplugin("").argument(),
24 Matchers.equalTo(
25 String.join(
26 " ",
27 "-Xplugin:ErrorProne",
28 "-Xep:InvalidBlockTag:OFF",
29 "-Xep:OperatorPrecedence:OFF",
30 "-Xep:UnicodeInCode:OFF"
31 )
32 )
33 );
34 }
35
36 @Test
37 void appendsFlagsOfProjectLast() {
38 MatcherAssert.assertThat(
39 "the project must have the last word on every pattern",
40 new Xplugin("-Xep:OperatorPrecedence:ERROR").argument(),
41 Matchers.endsWith(
42 "-Xep:UnicodeInCode:OFF -Xep:OperatorPrecedence:ERROR"
43 )
44 );
45 }
46
47 @Test
48 void takesFlagsSeparatedByCommas() {
49 MatcherAssert.assertThat(
50 "commas must separate flags just like spaces do",
51 new Xplugin(" -Xep:UnusedVariable:OFF, -Xep:SelfAssignment:OFF ")
52 .argument(),
53 Matchers.endsWith(
54 "-Xep:UnusedVariable:OFF -Xep:SelfAssignment:OFF"
55 )
56 );
57 }
58
59 @Test
60 void countsPatternsThatFire() {
61 MatcherAssert.assertThat(
62 "ErrorProne cannot stay silent about how many patterns it applies",
63 new Xplugin("").patterns(),
64 Matchers.greaterThan(100)
65 );
66 }
67
68 @Test
69 void countsOnePatternFewerWhenProjectSwitchesOneOff() {
70 MatcherAssert.assertThat(
71 "a pattern the project switches off must leave the count",
72 new Xplugin("-Xep:UnusedVariable:OFF").patterns(),
73 Matchers.equalTo(new Xplugin("").patterns() - 1)
74 );
75 }
76
77 @Test
78 void countsOnePatternMoreWhenProjectSwitchesOneBackOn() {
79 MatcherAssert.assertThat(
80 "a pattern the project switches back on must join the count",
81 new Xplugin("-Xep:OperatorPrecedence:ERROR").patterns(),
82 Matchers.equalTo(new Xplugin("").patterns() + 1)
83 );
84 }
85
86 @Test
87 void refusesFlagErrorProneWouldNotUnderstand() {
88 MatcherAssert.assertThat(
89 "the flag that cannot work must be named in the failure",
90 Assertions.assertThrows(
91 IllegalArgumentException.class,
92 () -> new Xplugin("-Xlint:all").argument(),
93 "a flag that is not an ErrorProne one must be refused"
94 ).getMessage(),
95 Matchers.containsString("-Xlint:all")
96 );
97 }
98 }