Skip to content

Commit

Permalink
Updates for checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Oct 23, 2024
1 parent 6adb4ab commit 0117192
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -295,8 +296,9 @@ class FileWalker extends SimpleFileVisitor<Path> {
Path foundFile;

FileWalker(StubConfiguration stubConfiguration) {
this.latestSnapshotVersion = LATEST.stream().anyMatch(s -> s.equals(stubConfiguration.version.toLowerCase()));
this.latestReleaseVersion = RELEASE.equals(stubConfiguration.version.toLowerCase());
this.latestSnapshotVersion = LATEST.stream()
.anyMatch(s -> s.equals(stubConfiguration.version.toLowerCase(Locale.ROOT)));
this.latestReleaseVersion = RELEASE.equals(stubConfiguration.version.toLowerCase(Locale.ROOT));
this.matcherWithDot = FileSystems.getDefault().getPathMatcher("glob:" + matcherGlob(stubConfiguration, "."));
this.matcherWithoutDot = FileSystems.getDefault().getPathMatcher("glob:" + matcherGlob(stubConfiguration, "/"));
}
Expand Down Expand Up @@ -368,12 +370,12 @@ private DefaultArtifactVersionWrapper replaceWithSnapshotIfSameVersions(
private File folderWithPredefinedName(File[] files) {
if (this.latestSnapshotVersion) {
return Arrays.stream(files)
.filter(file -> LATEST.stream().anyMatch(s -> s.equals(file.getName().toLowerCase())))
.filter(file -> LATEST.stream().anyMatch(s -> s.equals(file.getName().toLowerCase(Locale.ROOT))))
.findFirst()
.orElse(null);
}
return Arrays.stream(files)
.filter(file -> RELEASE.equals(file.getName().toLowerCase()))
.filter(file -> RELEASE.equals(file.getName().toLowerCase(Locale.ROOT)))
.findFirst()
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.cloud.contract.stubrunner;

import java.util.Locale;

import org.springframework.util.StringUtils;

/**
Expand Down Expand Up @@ -128,7 +130,7 @@ public boolean groupIdAndArtifactMatches(String ivyNotationAsString) {
* @return {@code true} for a snapshot or a LATEST (+) version.
*/
public boolean isVersionChanging() {
return DEFAULT_VERSION.equals(this.version) || this.version.toLowerCase().contains("snapshot");
return DEFAULT_VERSION.equals(this.version) || this.version.toLowerCase(Locale.ROOT).contains("snapshot");
}

public String getGroupId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
Expand Down Expand Up @@ -213,7 +214,7 @@ private static Map<String, String> stubRunnerProps() {
Set<String> propertyNames = properties.stringPropertyNames();
propertyNames.stream()
// stubrunner.properties.foo.bar=baz
.filter(s -> s.toLowerCase().startsWith("stubrunner.properties"))
.filter(s -> s.toLowerCase(Locale.ROOT).startsWith("stubrunner.properties"))
// foo.bar=baz
.forEach(s -> map.put(s.substring("stubrunner.properties".length() + 1), System.getProperty(s)));
return map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.cloud.contract.stubrunner;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -81,7 +82,7 @@ public static String getProperty(Map<String, String> options, String propName) {
}

private static String appendPrefixIfNecessary(String prop) {
if (prop.toLowerCase().startsWith("stubrunner")) {
if (prop.toLowerCase(Locale.ROOT).startsWith("stubrunner")) {
return prop;
}
return STUBRUNNER_PROPERTIES + "." + prop;
Expand All @@ -95,7 +96,7 @@ private static String doGetProp(String stubRunnerProp) {
}
return systemProp;
}
String convertedEnvProp = stubRunnerProp.replaceAll("\\.", "_").replaceAll("-", "_").toUpperCase();
String convertedEnvProp = stubRunnerProp.replaceAll("\\.", "_").replaceAll("-", "_").toUpperCase(Locale.ROOT);
String envVar = FETCHER.envVar(convertedEnvProp);
if (log.isTraceEnabled()) {
log.trace("Environment variable [" + convertedEnvProp + "] has value [" + envVar + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.inject.Inject;
Expand Down Expand Up @@ -269,7 +270,7 @@ public void setTestFramework(TestFramework testFramework) {
}

public void setTestFramework(String testFramework) {
this.testFramework.set(TestFramework.valueOf(testFramework.toUpperCase()));
this.testFramework.set(TestFramework.valueOf(testFramework.toUpperCase(Locale.ROOT)));
}

public Property<TestMode> getTestMode() {
Expand All @@ -281,7 +282,7 @@ public void setTestMode(TestMode testMode) {
}

public void setTestMode(String testMode) {
this.testMode.set(TestMode.valueOf(testMode.toUpperCase()));
this.testMode.set(TestMode.valueOf(testMode.toUpperCase(Locale.ROOT)));
}

public Property<String> getBasePackageForTests() {
Expand Down Expand Up @@ -469,7 +470,7 @@ public void setContractsMode(StubRunnerProperties.StubsMode contractsMode) {
}

public void setContractsMode(String contractsMode) {
this.contractsMode.set(StubRunnerProperties.StubsMode.valueOf(contractsMode.toUpperCase()));
this.contractsMode.set(StubRunnerProperties.StubsMode.valueOf(contractsMode.toUpperCase(Locale.ROOT)));
}

public Property<String> getPackageWithBaseClasses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -71,7 +72,7 @@ void storeContractAsYaml(SingleContractMetadata metadata) {
private String byteBodyToAFileForTestMethod(SingleContractMetadata metadata, FromFileProperty property,
CommunicationType side) {
GeneratedClassDataForMethod classDataForMethod = classDataForMethod(metadata);
String newFileName = classDataForMethod.getMethodName() + "_" + side.name().toLowerCase() + "_"
String newFileName = classDataForMethod.getMethodName() + "_" + side.name().toLowerCase(Locale.ROOT) + "_"
+ property.fileName();
writeFileForBothIdeAndBuildTool(metadata, property.asBytes(), newFileName);
return newFileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.cloud.contract.verifier.builder;

import java.util.Locale;

import org.springframework.cloud.contract.spec.internal.ExecutionProperty;
import org.springframework.cloud.contract.spec.internal.Request;
import org.springframework.cloud.contract.spec.internal.Url;
Expand Down Expand Up @@ -51,7 +53,7 @@ private Url getUrl(Request request) {

private void addUrl(Url buildUrl, Request request) {
Object testSideUrl = MapConverter.getTestSideValues(buildUrl);
String method = request.getMethod().getServerValue().toString().toLowerCase();
String method = request.getMethod().getServerValue().toString().toLowerCase(Locale.ROOT);
String url = testSideUrl.toString();
if (!(testSideUrl instanceof ExecutionProperty)) {
url = this.bodyParser.quotedShortText(testSideUrl.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.cloud.contract.verifier.builder;

import java.util.Locale;

import org.springframework.cloud.contract.spec.internal.ExecutionProperty;
import org.springframework.cloud.contract.spec.internal.FromFileProperty;
import org.springframework.cloud.contract.spec.internal.Request;
Expand Down Expand Up @@ -43,7 +45,7 @@ public MethodVisitor<When> apply(SingleContractMetadata metadata) {
void appendMethodAndBody(SingleContractMetadata metadata) {
Request request = metadata.getContract().getRequest();
ContentType type = metadata.getInputTestContentType();
String method = request.getMethod().getServerValue().toString().toLowerCase();
String method = request.getMethod().getServerValue().toString().toLowerCase(Locale.ROOT);
if (request.getBody() != null) {
String contentType = StringUtils.hasText(metadata.getDefinedInputTestContentType())
? metadata.getDefinedInputTestContentType() : type.getMimeType();
Expand All @@ -61,11 +63,11 @@ else if (body instanceof FromFileProperty) {
else {
value = "\"" + requestBodyAsString(metadata) + "\"";
}
this.blockBuilder.addIndented(
".build(\"" + method.toUpperCase() + "\", entity(" + value + ", \"" + contentType + "\"))");
this.blockBuilder.addIndented(".build(\"" + method.toUpperCase(Locale.ROOT) + "\", entity(" + value + ", \""
+ contentType + "\"))");
}
else {
this.blockBuilder.addIndented(".build(\"" + method.toUpperCase() + "\")");
this.blockBuilder.addIndented(".build(\"" + method.toUpperCase(Locale.ROOT) + "\")");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.cloud.contract.verifier.builder;

import java.util.Locale;

import org.springframework.cloud.contract.spec.internal.ExecutionProperty;
import org.springframework.cloud.contract.spec.internal.Request;
import org.springframework.cloud.contract.spec.internal.Url;
Expand Down Expand Up @@ -53,7 +55,7 @@ private Url getUrl(Request request) {

private void addUrl(Url buildUrl, Request request) {
Object testSideUrl = MapConverter.getTestSideValues(buildUrl);
String method = request.getMethod().getServerValue().toString().toLowerCase();
String method = request.getMethod().getServerValue().toString().toLowerCase(Locale.ROOT);
String url = testSideUrl.toString();
if (!(testSideUrl instanceof ExecutionProperty)) {
url = this.bodyParser.quotedShortText(testSideUrl.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -273,7 +274,7 @@ static MatchingType from(String string) {
return Arrays.stream(values())
.filter(matchingType -> matchingType.name()
.replace("_", "")
.equalsIgnoreCase(string.toLowerCase().replace("_", "")))
.equalsIgnoreCase(string.toLowerCase(Locale.ROOT).replace("_", "")))
.findFirst()
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -78,7 +79,7 @@ public Response exchange(Request request) {
}

private String url(Request request) {
String url = request.scheme().name().toLowerCase() + ":" + this.hostAndPort
String url = request.scheme().name().toLowerCase(Locale.ROOT) + ":" + this.hostAndPort
+ (request.path().startsWith("/") ? request.path() : "/" + request.path());
if (!request.queryParams().isEmpty()) {
return url + "?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.springframework.cloud.contract.spec.internal.HttpMethods;
Expand Down Expand Up @@ -69,7 +70,7 @@ public class Request {
public String contentType() {
Object value = this.headers.entrySet()
.stream()
.filter(e -> e.getKey().toLowerCase().equals("content-type"))
.filter(e -> e.getKey().toLowerCase(Locale.ROOT).equals("content-type"))
.findFirst()
.orElse(new AbstractMap.SimpleEntry<>("", null))
.getValue();
Expand Down Expand Up @@ -169,7 +170,7 @@ public static class MethodBuilder {
* @return builder
*/
public Request.Builder method(String method, String path) {
return new Request.Builder(HttpMethods.HttpMethod.valueOf(method.toUpperCase()), path);
return new Request.Builder(HttpMethods.HttpMethod.valueOf(method.toUpperCase(Locale.ROOT)), path);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.cloud.contract.verifier.messaging.stream;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -60,9 +61,9 @@ else if (channels.size() > 0) {
log.debug("Found following channels [" + channels + "] for destination [" + destination + "]. "
+ "Will pick the one that matches the default channel name or the first one if none is matching");
}
String defaultChannelName = channels.get(defaultChannel.name().toLowerCase());
String defaultChannelName = channels.get(defaultChannel.name().toLowerCase(Locale.ROOT));
String matchingChannelName = StringUtils.hasText(defaultChannelName)
? defaultChannel.name().toLowerCase() : channels.keySet().iterator().next();
? defaultChannel.name().toLowerCase(Locale.ROOT) : channels.keySet().iterator().next();
if (log.isDebugEnabled()) {
log.debug("Picked channel name is [" + matchingChannelName + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Deque;
import java.util.Locale;

/**
* A utility class that helps to convert names.
Expand Down Expand Up @@ -104,7 +105,7 @@ public static String camelCase(String className) {
if (isEmpty(className)) {
return className;
}
String firstChar = className.substring(0, 1).toLowerCase();
String firstChar = className.substring(0, 1).toLowerCase(Locale.ROOT);
return firstChar + className.substring(1);
}

Expand All @@ -115,7 +116,7 @@ public static String capitalize(String className) {
if (isEmpty(className)) {
return className;
}
String firstChar = className.substring(0, 1).toUpperCase();
String firstChar = className.substring(0, 1).toUpperCase(Locale.ROOT);
return firstChar + className.substring(1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -169,7 +170,7 @@ private MappingBuilder requestHeaders(MappingBuilder request, Operation operatio
org.springframework.http.HttpHeaders headers = operation.getRequest().getHeaders();
// TODO: whitelist headers
for (String name : headers.keySet()) {
if (!this.headerBlackList.contains(name.toLowerCase())) {
if (!this.headerBlackList.contains(name.toLowerCase(Locale.ROOT))) {
if ("content-type".equalsIgnoreCase(name) && this.contentType != null) {
continue;
}
Expand Down Expand Up @@ -239,7 +240,7 @@ private HttpHeaders responseHeaders(Operation operation) {
org.springframework.http.HttpHeaders headers = operation.getResponse().getHeaders();
HttpHeaders result = new HttpHeaders();
for (String name : headers.keySet()) {
if (!this.headerBlackList.contains(name.toLowerCase())) {
if (!this.headerBlackList.contains(name.toLowerCase(Locale.ROOT))) {
result = result.plus(new HttpHeader(name, headers.get(name)));
}
}
Expand Down

0 comments on commit 0117192

Please sign in to comment.