Skip to content

Commit 836c1a0

Browse files
committed
Polish tests
1 parent 4adf445 commit 836c1a0

File tree

11 files changed

+70
-65
lines changed

11 files changed

+70
-65
lines changed

Diff for: spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/src/io/spring/javaformat/eclipse/MessagesTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@
2929
public class MessagesTests {
3030

3131
@Test
32-
public void bindHasCorrectMessage() {
32+
void bindHasCorrectMessage() {
3333
String message = NLS.bind(Messages.springFormatSettingsImportError, "reason");
3434
assertThat(message).isEqualTo("Error importing project specific settings: reason");
3535
}

Diff for: spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/src/io/spring/javaformat/eclipse/projectsettings/ProjectPropertiesTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ public class ProjectPropertiesTests {
4444
public File temp;
4545

4646
@Test
47-
public void addFromFolderAddsEclipseProperties() throws IOException {
47+
void addFromFolderAddsEclipseProperties() throws IOException {
4848
File file = new File(this.temp, "eclipse.properties");
4949
writeProperties(file, "2018");
5050
ProjectProperties properties = new ProjectProperties();
@@ -53,7 +53,7 @@ public void addFromFolderAddsEclipseProperties() throws IOException {
5353
}
5454

5555
@Test
56-
public void addFromFolderWhenAlreadySetDoesNotOverwrite() throws IOException {
56+
void addFromFolderWhenAlreadySetDoesNotOverwrite() throws IOException {
5757
ProjectProperties properties = new ProjectProperties();
5858
File folder1 = new File(this.temp, "1");
5959
folder1.mkdirs();
@@ -67,15 +67,15 @@ public void addFromFolderWhenAlreadySetDoesNotOverwrite() throws IOException {
6767
}
6868

6969
@Test
70-
public void addFromEmptyFolderUsesDefaults() throws IOException {
70+
void addFromEmptyFolderUsesDefaults() throws IOException {
7171
ProjectProperties properties = new ProjectProperties();
7272
properties.addFromFolder(this.temp);
7373
String currentYear = String.valueOf(LocalDate.now().getYear());
7474
assertThat(properties.get("copyright-year")).isEqualTo(currentYear);
7575
}
7676

7777
@Test
78-
public void getModifiedContentReplacesCopyrightYear() throws IOException {
78+
void getModifiedContentReplacesCopyrightYear() throws IOException {
7979
String year = "2016-2020";
8080
File file = new File(this.temp, "eclipse.properties");
8181
writeProperties(file, year);

Diff for: spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/src/io/spring/javaformat/eclipse/projectsettings/ProjectSettingsFileTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,21 +39,21 @@ public class ProjectSettingsFileTests {
3939
public File temp;
4040

4141
@Test
42-
public void fromFileAdaptsFile() throws Exception {
42+
void fromFileAdaptsFile() throws Exception {
4343
File file = new File(this.temp, "file");
4444
writeText(file, "test");
4545
ProjectSettingsFile projectSettingsFile = ProjectSettingsFile.fromFile(file);
4646
assertThat(projectSettingsFile.getName()).isEqualTo(file.getName());
4747
assertThat(projectSettingsFile.getContent(JavaFormatConfig.DEFAULT))
48-
.hasSameContentAs(new ByteArrayInputStream("test".getBytes()));
48+
.hasSameContentAs(new ByteArrayInputStream("test".getBytes()));
4949
}
5050

5151
@Test
52-
public void fromClasspathResourceAdaptsResource() throws Exception {
52+
void fromClasspathResourceAdaptsResource() throws Exception {
5353
ProjectSettingsFile projectSettingsFile = ProjectSettingsFile.fromClasspath(getClass(), "test.txt");
5454
assertThat(projectSettingsFile.getName()).isEqualTo("test.txt");
5555
assertThat(projectSettingsFile.getContent(JavaFormatConfig.DEFAULT))
56-
.hasSameContentAs(new ByteArrayInputStream("test".getBytes()));
56+
.hasSameContentAs(new ByteArrayInputStream("test".getBytes()));
5757
}
5858

5959
private void writeText(File file, String s) throws FileNotFoundException {

Diff for: spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/src/io/spring/javaformat/eclipse/projectsettings/ProjectSettingsFilesLocatorTests.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,23 +45,23 @@ public class ProjectSettingsFilesLocatorTests {
4545
public File temp;
4646

4747
@Test
48-
public void locateSettingsFilesWhenNoFoldersShouldReturnDefault() throws IOException {
48+
void locateSettingsFilesWhenNoFoldersReturnsDefault() throws IOException {
4949
ProjectSettingsFiles files = new ProjectSettingsFilesLocator().locateSettingsFiles();
50-
assertThat(files.iterator()).extracting(ProjectSettingsFile::getName).containsOnly("org.eclipse.jdt.core.prefs",
51-
"org.eclipse.jdt.ui.prefs");
50+
assertThat(files.iterator()).extracting(ProjectSettingsFile::getName)
51+
.containsOnly("org.eclipse.jdt.core.prefs", "org.eclipse.jdt.ui.prefs");
5252
}
5353

5454
@Test
55-
public void locateSettingsFilesOnlyFindPrefs() throws Exception {
55+
void locateSettingsFilesOnlyFindPrefs() throws Exception {
5656
writeFile(this.temp, "foo.prefs");
5757
writeFile(this.temp, "bar.notprefs");
5858
ProjectSettingsFiles files = new ProjectSettingsFilesLocator(this.temp).locateSettingsFiles();
59-
assertThat(files.iterator()).extracting(ProjectSettingsFile::getName).containsOnly("org.eclipse.jdt.core.prefs",
60-
"org.eclipse.jdt.ui.prefs", "foo.prefs");
59+
assertThat(files.iterator()).extracting(ProjectSettingsFile::getName)
60+
.containsOnly("org.eclipse.jdt.core.prefs", "org.eclipse.jdt.ui.prefs", "foo.prefs");
6161
}
6262

6363
@Test
64-
public void locateSettingsFilesWhenMultipleFoldersFindsInEarliest() throws Exception {
64+
void locateSettingsFilesWhenMultipleFoldersFindsInEarliest() throws Exception {
6565
File folder1 = new File(this.temp, "1");
6666
writeFile(folder1, "foo.prefs", "foo1");
6767
File folder2 = new File(this.temp, "2");
@@ -71,32 +71,32 @@ public void locateSettingsFilesWhenMultipleFoldersFindsInEarliest() throws Excep
7171
Map<String, ProjectSettingsFile> found = new LinkedHashMap<>();
7272
files.iterator().forEachRemaining((f) -> found.put(f.getName(), f));
7373
assertThat(found.get("foo.prefs").getContent(JavaFormatConfig.DEFAULT))
74-
.hasSameContentAs(new ByteArrayInputStream("foo1".getBytes()));
74+
.hasSameContentAs(new ByteArrayInputStream("foo1".getBytes()));
7575
assertThat(found.get("org.eclipse.jdt.core.prefs").getContent(JavaFormatConfig.DEFAULT))
76-
.hasSameContentAs(new ByteArrayInputStream("core2".getBytes()));
76+
.hasSameContentAs(new ByteArrayInputStream("core2".getBytes()));
7777
}
7878

7979
@Test
80-
public void jdtCorePrefsFormatterWhenDefaultShouldUseTabs() throws IOException {
80+
void jdtCorePrefsFormatterWhenDefaultUsesTabs() throws IOException {
8181
ProjectSettingsFiles files = new ProjectSettingsFilesLocator().locateSettingsFiles();
8282
ProjectSettingsFile file = get(files, "org.eclipse.jdt.core.prefs");
8383
try (InputStream content = file.getContent(JavaFormatConfig.DEFAULT)) {
8484
Properties properties = new Properties();
8585
properties.load(content);
8686
assertThat(properties.get("org.eclipse.jdt.core.javaFormatter"))
87-
.isEqualTo("io.spring.javaformat.eclipse.formatter.jdk11.tabs");
87+
.isEqualTo("io.spring.javaformat.eclipse.formatter.jdk11.tabs");
8888
}
8989
}
9090

9191
@Test
92-
public void jdtCorePrefsFormatterWhenSpacesShouldUseSpaces() throws IOException {
92+
void jdtCorePrefsFormatterWhenSpacesUsesSpaces() throws IOException {
9393
ProjectSettingsFiles files = new ProjectSettingsFilesLocator().locateSettingsFiles();
9494
ProjectSettingsFile file = get(files, "org.eclipse.jdt.core.prefs");
9595
try (InputStream content = file.getContent(JavaFormatConfig.of(JavaBaseline.V8, IndentationStyle.SPACES))) {
9696
Properties properties = new Properties();
9797
properties.load(content);
9898
assertThat(properties.get("org.eclipse.jdt.core.javaFormatter"))
99-
.isEqualTo("io.spring.javaformat.eclipse.formatter.jdk8.spaces");
99+
.isEqualTo("io.spring.javaformat.eclipse.formatter.jdk8.spaces");
100100
}
101101
}
102102

Diff for: spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/src/io/spring/javaformat/eclipse/projectsettings/ProjectSettingsFilesTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,14 +52,14 @@ public class ProjectSettingsFilesTests {
5252
public File temp;
5353

5454
@Test
55-
public void iteratorIteratesFiles() throws Exception {
55+
void iteratorIteratesFiles() throws Exception {
5656
ProjectSettingsFile file = ProjectSettingsFile.fromFile(new File(this.temp, "file.prefs"));
5757
ProjectSettingsFiles files = new ProjectSettingsFiles(Collections.singleton(file), new ProjectProperties());
5858
assertThat(files).containsOnly(file);
5959
}
6060

6161
@Test
62-
public void applyToProjectWithoutFileCopiesToDotSettings() throws Exception {
62+
void applyToProjectWithoutFileCopiesToDotSettings() throws Exception {
6363
ProjectSettingsFile file = createPrefsFile();
6464
ProjectSettingsFiles files = new ProjectSettingsFiles(Collections.singleton(file), new ProjectProperties());
6565
IProject project = mock(IProject.class);
@@ -78,7 +78,7 @@ public void applyToProjectWithoutFileCopiesToDotSettings() throws Exception {
7878
}
7979

8080
@Test
81-
public void applyToProjectWithFileMergesToDotSettings() throws Exception {
81+
void applyToProjectWithFileMergesToDotSettings() throws Exception {
8282
ProjectSettingsFile file = createPrefsFile();
8383
ProjectSettingsFiles files = new ProjectSettingsFiles(Collections.singleton(file), new ProjectProperties());
8484
IProject project = mock(IProject.class);
@@ -87,7 +87,7 @@ public void applyToProjectWithFileMergesToDotSettings() throws Exception {
8787
given(project.getFile(".settings/foo.prefs")).willReturn(projectFile);
8888
given(projectFile.exists()).willReturn(true);
8989
given(projectFile.getContents(true))
90-
.willReturn(new ByteArrayInputStream("a=b\n".getBytes(StandardCharsets.UTF_8)));
90+
.willReturn(new ByteArrayInputStream("a=b\n".getBytes(StandardCharsets.UTF_8)));
9191
ByteArrayOutputStream out = new ByteArrayOutputStream();
9292
will((invocation) -> {
9393
invocation.getArgument(0, InputStream.class).transferTo(out);

Diff for: spring-javaformat-gradle/spring-javaformat-gradle-plugin/src/test/java/io/spring/javaformat/gradle/CheckTaskTests.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2022 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,13 +52,13 @@ public class CheckTaskTests {
5252
public File temp;
5353

5454
@Test
55-
public void checkOk() throws IOException {
55+
void checkOk() throws IOException {
5656
BuildResult result = this.gradleBuild.source("src/test/resources/check-ok").build("check");
5757
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
5858
}
5959

6060
@Test
61-
public void whenFirstInvocationSucceedsThenSecondInvocationIsUpToDate() throws IOException {
61+
void whenFirstInvocationSucceedsThenSecondInvocationIsUpToDate() throws IOException {
6262
GradleBuild gradleBuild = this.gradleBuild.source("src/test/resources/check-ok");
6363
BuildResult result = gradleBuild.build("check");
6464
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
@@ -67,7 +67,7 @@ public void whenFirstInvocationSucceedsThenSecondInvocationIsUpToDate() throws I
6767
}
6868

6969
@Test
70-
public void whenFirstInvocationSucceedsAndSourceIsModifiedThenSecondInvocationSucceeds() throws IOException {
70+
void whenFirstInvocationSucceedsAndSourceIsModifiedThenSecondInvocationSucceeds() throws IOException {
7171
copyFolder(new File("src/test/resources/check-ok").toPath(), this.temp.toPath());
7272
GradleBuild gradleBuild = this.gradleBuild.source(this.temp);
7373
BuildResult result = gradleBuild.build("check");
@@ -79,7 +79,7 @@ public void whenFirstInvocationSucceedsAndSourceIsModifiedThenSecondInvocationSu
7979
}
8080

8181
@Test
82-
public void whenFirstInvocationSucceedsAndIndentationStyleIsChangedThenSecondInvocationFails() throws IOException {
82+
void whenFirstInvocationSucceedsAndIndentationStyleIsChangedThenSecondInvocationFails() throws IOException {
8383
GradleBuild gradleBuild = this.gradleBuild.source("src/test/resources/check-ok");
8484
BuildResult result = gradleBuild.build("check");
8585
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
@@ -90,7 +90,7 @@ public void whenFirstInvocationSucceedsAndIndentationStyleIsChangedThenSecondInv
9090
}
9191

9292
@Test
93-
public void whenFirstInvocationFailsAndIndentationStyleIsChangedThenSecondInvocationSucceeds() throws IOException {
93+
void whenFirstInvocationFailsAndIndentationStyleIsChangedThenSecondInvocationSucceeds() throws IOException {
9494
GradleBuild gradleBuild = this.gradleBuild.source("src/test/resources/check-spaces");
9595
BuildResult result = gradleBuild.buildAndFail("check");
9696
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.FAILED);
@@ -101,7 +101,8 @@ public void whenFirstInvocationFailsAndIndentationStyleIsChangedThenSecondInvoca
101101
}
102102

103103
@Test
104-
public void whenFirstInvocationSucceedsAndJavaBaselineIsChangedThenSecondInvocationSucceedsAndThirdIsUpToDate() throws IOException {
104+
void whenFirstInvocationSucceedsAndJavaBaselineIsChangedThenSecondInvocationSucceedsAndThirdIsUpToDate()
105+
throws IOException {
105106
GradleBuild gradleBuild = this.gradleBuild.source("src/test/resources/check-ok");
106107
BuildResult result = gradleBuild.build("check");
107108
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
@@ -114,13 +115,13 @@ public void whenFirstInvocationSucceedsAndJavaBaselineIsChangedThenSecondInvocat
114115
}
115116

116117
@Test
117-
public void checkBad() throws IOException {
118+
void checkBad() throws IOException {
118119
BuildResult result = this.gradleBuild.source("src/test/resources/check-bad").buildAndFail("check");
119120
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.FAILED);
120121
}
121122

122123
@Test
123-
public void whenFirstInvocationFailsThenSecondInvocationFails() throws IOException {
124+
void whenFirstInvocationFailsThenSecondInvocationFails() throws IOException {
124125
GradleBuild gradleBuild = this.gradleBuild.source("src/test/resources/check-bad");
125126
BuildResult result = gradleBuild.buildAndFail("check");
126127
assertThat(result.task(":checkFormatMain").getOutcome()).isEqualTo(TaskOutcome.FAILED);

Diff for: spring-javaformat-gradle/spring-javaformat-gradle-plugin/src/test/java/io/spring/javaformat/gradle/FormatTaskTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2022 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ public class FormatTaskTests {
4444
private final GradleBuild gradleBuild = new GradleBuild();
4545

4646
@Test
47-
public void checkOk() throws IOException {
47+
void checkOk() throws IOException {
4848
BuildResult result = this.gradleBuild.source("src/test/resources/format").build("format");
4949
assertThat(result.task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
5050
File formattedFile = new File(this.gradleBuild.getProjectDir(), "src/main/java/simple/Simple.java");
@@ -53,7 +53,7 @@ public void checkOk() throws IOException {
5353
}
5454

5555
@Test
56-
public void checkUpToDate() throws IOException {
56+
void checkUpToDate() throws IOException {
5757
GradleRunner runner = this.gradleBuild.source("src/test/resources/format").prepareRunner("format");
5858
// Format that changes files
5959
assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
@@ -64,7 +64,7 @@ public void checkUpToDate() throws IOException {
6464
}
6565

6666
@Test
67-
public void notUpToDateWhenJavaBaselineChanges() throws IOException {
67+
void notUpToDateWhenJavaBaselineChanges() throws IOException {
6868
GradleRunner runner = this.gradleBuild.source("src/test/resources/format").prepareRunner("format");
6969
// Format that changes files
7070
assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
@@ -78,7 +78,7 @@ public void notUpToDateWhenJavaBaselineChanges() throws IOException {
7878
}
7979

8080
@Test
81-
public void notUpToDateWhenIndentationStyleChanges() throws IOException {
81+
void notUpToDateWhenIndentationStyleChanges() throws IOException {
8282
GradleRunner runner = this.gradleBuild.source("src/test/resources/format").prepareRunner("format");
8383
// Format that changes files
8484
assertThat(runner.build().task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
@@ -92,7 +92,7 @@ public void notUpToDateWhenIndentationStyleChanges() throws IOException {
9292
}
9393

9494
@Test
95-
public void checkSpacesOk() throws IOException {
95+
void checkSpacesOk() throws IOException {
9696
BuildResult result = this.gradleBuild.source("src/test/resources/format-spaces").build("format");
9797
assertThat(result.task(":formatMain").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
9898
File formattedFile = new File(this.gradleBuild.getProjectDir(), "src/main/java/simple/Simple.java");

Diff for: spring-javaformat/spring-javaformat-formatter-tests/src/test/java/io/spring/javaformat/formatter/FileEditTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ public class FileEditTests {
5151
private FileEdit fileEdit;
5252

5353
@BeforeEach
54-
public void setup() throws IOException {
54+
void setup() throws IOException {
5555
this.source = new File(this.temp, "source.txt");
5656
this.expected = new File(this.temp, "expected.txt");
5757
Files.copy(new File("src/test/resources/source/javadoc-top.txt").toPath(), this.source.toPath(),
@@ -64,33 +64,33 @@ public void setup() throws IOException {
6464
}
6565

6666
@Test
67-
public void getFileShouldReturnFile() throws Exception {
67+
void getFileReturnsFile() throws Exception {
6868
assertThat(this.fileEdit.getFile()).isEqualTo(this.source);
6969
}
7070

7171
@Test
72-
public void hasEditsWhenHasEditsShouldReturnTrue() throws Exception {
72+
void hasEditsWhenHasEditsReturnsTrue() throws Exception {
7373
assertThat(this.fileEdit.hasEdits()).isTrue();
7474
}
7575

7676
@Test
77-
public void hasEditsWhenHasNoEditsShouldReturnFalse() throws Exception {
77+
void hasEditsWhenHasNoEditsReturnsFalse() throws Exception {
7878
String content = read(this.expected);
7979
this.textEdit = new Formatter().format(content);
8080
this.fileEdit = new FileEdit(this.source, UTF_8, content, this.textEdit);
8181
assertThat(this.fileEdit.hasEdits()).isFalse();
8282
}
8383

8484
@Test
85-
public void saveShouldSaveContent() throws Exception {
85+
void saveSavesContent() throws Exception {
8686
String expected = read(this.expected);
8787
assertThat(read(this.source)).isNotEqualTo(expected);
8888
this.fileEdit.save();
8989
assertThat(read(this.source)).isEqualTo(expected);
9090
}
9191

9292
@Test
93-
public void getFormattedContentShouldReturnFormattedContent() throws Exception {
93+
void getFormattedContentReturnsFormattedContent() throws Exception {
9494
String expected = read(this.expected);
9595
assertThat(this.fileEdit.getFormattedContent()).isEqualTo(expected);
9696
}

0 commit comments

Comments
 (0)