Skip to content

Commit 60e402d

Browse files
committed
Declare JUnit test methods without public and the test prefix
Error Prone now fails the build on Picnic's JUnitMethodDeclaration too: JUnit 5 test and lifecycle methods are package-private, and a test method's name does not repeat that it is a test. Its suggested fix dropped public from 196 methods and the test prefix from ten names. Two of those came out awkward and were named by hand: _serialization is serialization, and main, which runs Main without arguments and expects its usage text, is printsUsageWithoutArguments. No @MethodSource relies on the name of a renamed method.
1 parent dd58e28 commit 60e402d

17 files changed

Lines changed: 209 additions & 209 deletions

‎buildSrc/src/main/groovy/open-java-format.error-prone-conventions.gradle‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pluginManager.withPlugin('java-gradle-plugin') {
2929
}
3030

3131
// The checks vfs-s3 makes build-breaking. The commented ones stay off until the code is fixed, one check at a
32-
// time: JUnitMethodDeclaration 206, StaticImport 84, LexicographicalAnnotationListing 46,
33-
// RedundantStringConversion 6, AlmostJavadoc 3 findings; the rest have none.
32+
// time: StaticImport 84, LexicographicalAnnotationListing 46, RedundantStringConversion 6, AlmostJavadoc 3
33+
// findings; the rest have none.
3434
tasks.withType(JavaCompile).configureEach {
3535
options.errorprone {
3636
//error('StaticImport')
@@ -41,7 +41,7 @@ tasks.withType(JavaCompile).configureEach {
4141
//error('PatternMatchingInstanceof')
4242
//error('UnnecessaryParentheses')
4343
//error('LexicographicalAnnotationListing')
44-
//error('JUnitMethodDeclaration')
44+
error('JUnitMethodDeclaration')
4545
error('JUnitClassModifiers')
4646
//error('MissingSummary')
4747
//error('AlmostJavadoc')

‎open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatConfigurableTest.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class PalantirJavaFormatConfigurableTest {
4646
private PalantirJavaFormatSettings settings;
4747

4848
@BeforeEach
49-
public void setUp() throws Exception {
49+
void setUp() throws Exception {
5050
TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory()
5151
.createLightFixtureBuilder(new DefaultLightProjectDescriptor(), getClass().getName());
5252
fixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
@@ -55,12 +55,12 @@ public void setUp() throws Exception {
5555
}
5656

5757
@AfterEach
58-
public void tearDown() throws Exception {
58+
void tearDown() throws Exception {
5959
fixture.tearDown();
6060
}
6161

6262
@Test
63-
public void buildsAPanelWithItsControls() {
63+
void buildsAPanelWithItsControls() {
6464
PalantirJavaFormatConfigurable configurable = new PalantirJavaFormatConfigurable(fixture.getProject());
6565

6666
JComponent component = requireNonNull(configurable.createComponent());
@@ -69,7 +69,7 @@ public void buildsAPanelWithItsControls() {
6969
}
7070

7171
@Test
72-
public void readsAndWritesTheEnabledSetting() throws Throwable {
72+
void readsAndWritesTheEnabledSetting() throws Throwable {
7373
State disabled = new State();
7474
disabled.setEnabled("false");
7575
settings.loadState(disabled);
@@ -93,7 +93,7 @@ public void readsAndWritesTheEnabledSetting() throws Throwable {
9393
}
9494

9595
@Test
96-
public void showsTheVersionOfThePlugin() {
96+
void showsTheVersionOfThePlugin() {
9797
// The "Plugin version" row: the version the platform read from the plugin's own descriptor, not "unknown".
9898
// Whatever the build stamped: CI checks out without tags, so there it is a commit hash rather than a
9999
// release-like version.

‎open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingServiceTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ final class PalantirJavaFormatFormattingServiceTest {
5757
private DelegatingFormatter delegatingFormatter;
5858

5959
@BeforeEach
60-
public void setUp() throws Exception {
60+
void setUp() throws Exception {
6161
TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory()
6262
.createLightFixtureBuilder(getProjectDescriptor(), getClass().getName());
6363
fixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
@@ -76,12 +76,12 @@ public void setUp() throws Exception {
7676
}
7777

7878
@AfterEach
79-
public void tearDown() throws Exception {
79+
void tearDown() throws Exception {
8080
fixture.tearDown();
8181
}
8282

8383
@Test
84-
public void defaultFormatSettings() throws Exception {
84+
void defaultFormatSettings() throws Exception {
8585
String input = Files.readString(
8686
Paths.get("../open-java-format/src/test/resources/com/palantir/javaformat/java/testdata/A.input"));
8787
String output = Files.readString(

‎open-java-format/src/test/java/com/palantir/javaformat/NewlinesTest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
final class NewlinesTest {
2828
@Test
29-
public void offsets() {
29+
void offsets() {
3030
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar\n")))
3131
.containsExactly(0, 4, 8);
3232
Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar")))
@@ -44,7 +44,7 @@ public void offsets() {
4444
}
4545

4646
@Test
47-
public void lines() {
47+
void lines() {
4848
Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar\n")))
4949
.containsExactly("foo\n", "bar\n");
5050
Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar")))
@@ -62,7 +62,7 @@ public void lines() {
6262
}
6363

6464
@Test
65-
public void terminalOffset() {
65+
void terminalOffset() {
6666
Iterator<Integer> it = Newlines.lineOffsetIterator("foo\nbar\n");
6767
it.next();
6868
it.next();
@@ -86,7 +86,7 @@ public void terminalOffset() {
8686
}
8787

8888
@Test
89-
public void terminalLine() {
89+
void terminalLine() {
9090
Iterator<String> it = Newlines.lineIterator("foo\nbar\n");
9191
it.next();
9292
it.next();

‎open-java-format/src/test/java/com/palantir/javaformat/java/CommandLineFlagsTest.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class CommandLineFlagsTest {
2929
// TODO(eaftan): Disallow passing both -lines and -offset/-length, like clang-format.
3030

3131
@Test
32-
public void formatInPlaceRequiresAtLeastOneFile() throws UsageException {
32+
void formatInPlaceRequiresAtLeastOneFile() throws UsageException {
3333
assertThatThrownBy(() -> Main.processArgs("-i")).isInstanceOf(UsageException.class);
3434

3535
assertThatThrownBy(() -> Main.processArgs("-i", "-")).isInstanceOf(UsageException.class);
@@ -39,7 +39,7 @@ public void formatInPlaceRequiresAtLeastOneFile() throws UsageException {
3939
}
4040

4141
@Test
42-
public void formatASubsetRequiresExactlyOneFile() throws UsageException {
42+
void formatASubsetRequiresExactlyOneFile() throws UsageException {
4343
Main.processArgs("-lines", "10", "Foo.java");
4444

4545
assertThatThrownBy(() -> Main.processArgs("-lines", "10")).isInstanceOf(UsageException.class);
@@ -59,7 +59,7 @@ public void formatASubsetRequiresExactlyOneFile() throws UsageException {
5959
// TODO(eaftan): clang-format allows a single offset with no length, which means to format
6060
// up to the end of the file. We should match that behavior.
6161
@Test
62-
public void numberOfOffsetsMustMatchNumberOfLengths() throws UsageException {
62+
void numberOfOffsetsMustMatchNumberOfLengths() throws UsageException {
6363
Main.processArgs("-offset", "10", "-length", "20", "Foo.java");
6464

6565
assertThatThrownBy(() -> Main.processArgs("-offset", "10", "-length", "20", "-offset", "50", "Foo.java"))
@@ -70,7 +70,7 @@ public void numberOfOffsetsMustMatchNumberOfLengths() throws UsageException {
7070
}
7171

7272
@Test
73-
public void noFilesToFormatRequiresEitherHelpOrVersion() throws UsageException {
73+
void noFilesToFormatRequiresEitherHelpOrVersion() throws UsageException {
7474
Main.processArgs("-version");
7575

7676
Main.processArgs("-help");
@@ -81,7 +81,7 @@ public void noFilesToFormatRequiresEitherHelpOrVersion() throws UsageException {
8181
}
8282

8383
@Test
84-
public void stdinAndFiles() {
84+
void stdinAndFiles() {
8585
try {
8686
Main.processArgs("-", "A.java");
8787
fail("fail");
@@ -91,7 +91,7 @@ public void stdinAndFiles() {
9191
}
9292

9393
@Test
94-
public void inPlaceStdin() {
94+
void inPlaceStdin() {
9595
try {
9696
Main.processArgs("-i", "-");
9797
fail("fail");
@@ -101,7 +101,7 @@ public void inPlaceStdin() {
101101
}
102102

103103
@Test
104-
public void inPlaceDryRun() {
104+
void inPlaceDryRun() {
105105
try {
106106
Main.processArgs("--replace", "--dry-run", "A.java");
107107
fail("fail");
@@ -118,7 +118,7 @@ public void inPlaceDryRun() {
118118
}
119119

120120
@Test
121-
public void assumeFileNameOnlyWorksWithStdin() {
121+
void assumeFileNameOnlyWorksWithStdin() {
122122
try {
123123
Main.processArgs("--assume-filename=Foo.java", "Foo.java");
124124
fail("fail");

‎open-java-format/src/test/java/com/palantir/javaformat/java/CommandLineOptionsParserTest.java‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class CommandLineOptionsParserTest {
3737
public Path testFolder;
3838

3939
@Test
40-
public void defaults() {
40+
void defaults() {
4141
CommandLineOptions options = CommandLineOptionsParser.parse(Collections.<String>emptyList());
4242
assertThat(options.files()).isEmpty();
4343
assertThat(options.stdin()).isFalse();
@@ -56,7 +56,7 @@ public void defaults() {
5656
}
5757

5858
@Test
59-
public void hello() {
59+
void hello() {
6060
CommandLineOptions options =
6161
CommandLineOptionsParser.parse(Arrays.asList("-lines=1:10,20:30", "-i", "Hello.java", "Goodbye.java"));
6262
assertThat(options.lines().asRanges()).containsExactly(Range.closedOpen(0, 10), Range.closedOpen(19, 30));
@@ -65,32 +65,32 @@ public void hello() {
6565
}
6666

6767
@Test
68-
public void stdin() {
68+
void stdin() {
6969
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-")).stdin()).isTrue();
7070
}
7171

7272
@Test
73-
public void styleFlagsAreUnsupported() {
73+
void styleFlagsAreUnsupported() {
7474
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-aosp", "--aosp", "-a", "--ojf", "-ojf"))
7575
.unsupportedFlags())
7676
.containsExactly("-aosp", "--aosp", "-a", "--ojf", "-ojf");
7777
}
7878

7979
@Test
80-
public void help() {
80+
void help() {
8181
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-help")).help())
8282
.isTrue();
8383
}
8484

8585
@Test
86-
public void lengths() {
86+
void lengths() {
8787
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-length", "1", "--length", "2"))
8888
.lengths())
8989
.containsExactly(1, 2);
9090
}
9191

9292
@Test
93-
public void lines() {
93+
void lines() {
9494
assertThat(CommandLineOptionsParser.parse(
9595
Arrays.asList("--lines", "1:2", "-lines=4:5", "--line", "7:8", "-line=10:11"))
9696
.lines()
@@ -103,70 +103,70 @@ public void lines() {
103103
}
104104

105105
@Test
106-
public void offset() {
106+
void offset() {
107107
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-offset", "1", "--offset", "2"))
108108
.offsets())
109109
.containsExactly(1, 2);
110110
}
111111

112112
@Test
113-
public void inPlace() {
113+
void inPlace() {
114114
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-i", "A.java")).inPlace())
115115
.isTrue();
116116
}
117117

118118
@Test
119-
public void version() {
119+
void version() {
120120
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-v")).version())
121121
.isTrue();
122122
}
123123

124124
@Test
125-
public void skipSortingImports() {
125+
void skipSortingImports() {
126126
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--skip-sorting-imports"))
127127
.sortImports())
128128
.isFalse();
129129
}
130130

131131
@Test
132-
public void skipRemovingUnusedImports() {
132+
void skipRemovingUnusedImports() {
133133
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--skip-removing-unused-imports"))
134134
.removeUnusedImports())
135135
.isFalse();
136136
}
137137

138138
@Test
139-
public void dryRun() {
139+
void dryRun() {
140140
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--dry-run")).dryRun())
141141
.isTrue();
142142
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-n")).dryRun()).isTrue();
143143
}
144144

145145
@Test
146-
public void setExitIfChanged() {
146+
void setExitIfChanged() {
147147
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--set-exit-if-changed"))
148148
.setExitIfChanged())
149149
.isTrue();
150150
}
151151

152152
@Test
153-
public void mergedLines() {
153+
void mergedLines() {
154154
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-lines=1:5", "-lines=2:8"))
155155
.lines()
156156
.asRanges())
157157
.containsExactly(Range.closedOpen(0, 8));
158158
}
159159

160160
@Test
161-
public void repeatedLines() {
161+
void repeatedLines() {
162162
assertThat(CommandLineOptionsParser.parse(Arrays.asList("-lines=1:1", "-lines=1:1"))
163163
.lines()
164164
.asRanges())
165165
.containsExactly(Range.closedOpen(0, 1));
166166
}
167167

168168
@Test
169-
public void paramsFile() throws IOException {
169+
void paramsFile() throws IOException {
170170
Path outer = Files.createFile(testFolder.resolve("outer"));
171171
Path exit = Files.createFile(testFolder.resolve("exit"));
172172
Path nested = Files.createFile(testFolder.resolve("nested"));
@@ -182,7 +182,7 @@ public void paramsFile() throws IOException {
182182
}
183183

184184
@Test
185-
public void paramsFileWithNesting() throws IOException {
185+
void paramsFileWithNesting() throws IOException {
186186
Path outer = Files.createFile(testFolder.resolve("outer"));
187187
Path exit = Files.createFile(testFolder.resolve("exit"));
188188
Path nested1 = Files.createFile(testFolder.resolve("nested1"));
@@ -202,7 +202,7 @@ public void paramsFileWithNesting() throws IOException {
202202
}
203203

204204
@Test
205-
public void paramsFileWithRecursion() throws IOException {
205+
void paramsFileWithRecursion() throws IOException {
206206
Path outer = Files.createFile(testFolder.resolve("outer"));
207207
Path exit = Files.createFile(testFolder.resolve("exit"));
208208
Path nested1 = Files.createFile(testFolder.resolve("nested1"));
@@ -221,7 +221,7 @@ public void paramsFileWithRecursion() throws IOException {
221221
}
222222

223223
@Test
224-
public void paramsFileWithQuotesAndWhitespaces() throws IOException {
224+
void paramsFileWithQuotesAndWhitespaces() throws IOException {
225225
Path outer = Files.createFile(testFolder.resolve("outer with whitespace"));
226226
Path exit = Files.createFile(testFolder.resolve("exit with whitespace"));
227227
Path nested = Files.createFile(testFolder.resolve("nested with whitespace"));
@@ -237,7 +237,7 @@ public void paramsFileWithQuotesAndWhitespaces() throws IOException {
237237
}
238238

239239
@Test
240-
public void assumeFilename() {
240+
void assumeFilename() {
241241
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--assume-filename", "Foo.java"))
242242
.assumeFilename())
243243
.hasValue("Foo.java");
@@ -246,7 +246,7 @@ public void assumeFilename() {
246246
}
247247

248248
@Test
249-
public void skipReflowLongStrings() {
249+
void skipReflowLongStrings() {
250250
assertThat(CommandLineOptionsParser.parse(Arrays.asList("--skip-reflowing-long-strings"))
251251
.reflowLongStrings())
252252
.isFalse();

0 commit comments

Comments
 (0)