Declare JUnit test methods without public and the test prefix · openjavaformat/open-java-format@60e402d · GitHub
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

‎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

0 commit comments

Comments
 (0)