Skip to content

Commit 7a8b95f

Browse files
committed
Merge pull request #137 from dreis2211
* pr/137: Fix spring-javaformat-checkstyle tests Closes gh-137
2 parents 6b0dcf2 + cbc020c commit 7a8b95f

File tree

7 files changed

+62
-8
lines changed

7 files changed

+62
-8
lines changed

spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/AssertionsAuditListener.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public void auditFinished(AuditEvent event) {
7575
private void runCheck(String check) {
7676
String description = this.filenames.toString();
7777
if (check.startsWith("+")) {
78-
assertThat(this.message).as(description).contains(check.substring(1));
78+
assertThat(this.message.toString()).as(description).contains(check.substring(1));
7979
}
8080
else if (check.startsWith("-")) {
81-
assertThat(this.message).as(description).doesNotContain(check.substring(1));
81+
assertThat(this.message.toString()).as(description).doesNotContain(check.substring(1));
8282
}
8383
}
8484

spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/SpringChecksTests.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Arrays;
2525
import java.util.Collection;
2626
import java.util.List;
27+
import java.util.Locale;
2728
import java.util.Properties;
2829
import java.util.stream.Collectors;
2930

@@ -71,13 +72,16 @@ public SpringChecksTests(Parameter parameter) throws Exception {
7172

7273
@Test
7374
public void processHasExpectedResults() throws Exception {
75+
Locale previousLocale = Locale.getDefault();
76+
Locale.setDefault(Locale.ENGLISH);
7477
Configuration configuration = loadConfiguration();
7578
RootModule rootModule = createRootModule(configuration);
7679
try {
7780
processAndCheckResults(rootModule);
7881
}
7982
finally {
8083
rootModule.destroy();
84+
Locale.setDefault(previousLocale);
8185
}
8286
}
8387

@@ -100,7 +104,7 @@ private RootModule createRootModule(Configuration configuration) throws Checksty
100104
}
101105

102106
private void processAndCheckResults(RootModule rootModule) throws CheckstyleException {
103-
rootModule.addListener(this.parameter.getAssersionsListener());
107+
rootModule.addListener(this.parameter.getAssertionsListener());
104108
if (!RUNNING_ON_WINDOWS) {
105109
printDebugInfo(this.parameter.getSourceFile());
106110
}
@@ -127,7 +131,7 @@ private static class Parameter {
127131

128132
private final File sourceFile;
129133

130-
private final AssertionsAuditListener assersionsListener;
134+
private final AssertionsAuditListener assertionsListener;
131135

132136
private final File configFile;
133137

@@ -136,7 +140,7 @@ private static class Parameter {
136140
this.sourceFile = new File(SOURCES_DIR, sourceName);
137141
File configFile = new File(CONFIGS_DIR, this.name + ".xml");
138142
this.configFile = (configFile.exists() ? configFile : DEFAULT_CONFIG);
139-
this.assersionsListener = new AssertionsAuditListener(readChecks(this.name + ".txt"));
143+
this.assertionsListener = new AssertionsAuditListener(readChecks(this.name + ".txt"));
140144
}
141145

142146
private List<String> readChecks(String name) {
@@ -156,8 +160,8 @@ public File getConfigFile() {
156160
return this.configFile;
157161
}
158162

159-
public AssertionsAuditListener getAssersionsListener() {
160-
return this.assersionsListener;
163+
public AssertionsAuditListener getAssertionsListener() {
164+
return this.assertionsListener;
161165
}
162166

163167
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
+The name of the outer type and the file do not match
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
+0 errors

spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/NewlineAtEndOfFile.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
public class MissingNewLine {
17+
public class NewlineAtEndOfFile {
1818

1919
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2017-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* This is an example of a class name not matching its filename.
19+
*
20+
* @author Christoph Dreis
21+
*/
22+
public class NameNotMatching {
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2017-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* This is a valid example of a class name matching its filename.
19+
*
20+
* @author Christoph Dreis
21+
*/
22+
public class OuterTypeFilenameValid {
23+
24+
}

0 commit comments

Comments
 (0)