Skip to content

Commit

Permalink
Address more ConstantCaseForConstants warnings.
Browse files Browse the repository at this point in the history
There are still so many more, but I ran out of steam.

Also, in Truth's `Platform` class, migrate off the deprecated `Splitter.onPattern`, and start using the now-non-`@Beta` `splitToList`.

PiperOrigin-RevId: 710073619
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Dec 28, 2024
1 parent 54b8c47 commit 4c89959
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
11 changes: 6 additions & 5 deletions core/src/main/java/com/google/common/truth/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ static void cleanStackTrace(Throwable throwable) {
private static final String DIFF_KEY = "diff (-expected +actual)";

static @Nullable ImmutableList<Fact> makeDiff(String expected, String actual) {
ImmutableList<String> expectedLines = splitLines(expected);
ImmutableList<String> actualLines = splitLines(actual);
List<String> expectedLines = splitLines(expected);
List<String> actualLines = splitLines(actual);
List<String> unifiedDiff =
generateUnifiedDiff(expectedLines, actualLines, /* contextSize= */ 3);
if (unifiedDiff.isEmpty()) {
Expand All @@ -137,11 +137,12 @@ static void cleanStackTrace(Throwable throwable) {
return ImmutableList.of(fact(DIFF_KEY, result));
}

private static ImmutableList<String> splitLines(String s) {
// splitToList is @Beta, so we avoid it.
return ImmutableList.copyOf(Splitter.onPattern("\r?\n").split(s));
private static List<String> splitLines(String s) {
return Splitter.on(NEWLINE_PATTERN).splitToList(s);
}

private static final Pattern NEWLINE_PATTERN = Pattern.compile("\r?\n");

abstract static class PlatformComparisonFailure extends ComparisonFailure {
private final String message;

Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/com/google/common/truth/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,12 @@ private String formatActualOrExpected(@Nullable Object o) {
private static String base16(byte[] bytes) {
StringBuilder sb = new StringBuilder(2 * bytes.length);
for (byte b : bytes) {
sb.append(hexDigits[(b >> 4) & 0xf]).append(hexDigits[b & 0xf]);
sb.append(hexDigitsUpper[(b >> 4) & 0xf]).append(hexDigitsUpper[b & 0xf]);
}
return sb.toString();
}

private static final char[] hexDigits = "0123456789ABCDEF".toCharArray();
private static final char[] hexDigitsUpper = "0123456789ABCDEF".toCharArray();

private static @Nullable Object arrayAsListRecursively(@Nullable Object input) {
if (input instanceof Object[]) {
Expand Down Expand Up @@ -983,20 +983,20 @@ private boolean tryFailForEmptyString(@Nullable Object expected) {

// From SourceCodeEscapers:

private static final char[] HEX_DIGITS = "0123456789abcdef".toCharArray();
private static final char[] hexDigitsLower = "0123456789abcdef".toCharArray();

private static char[] asUnicodeHexEscape(char c) {
// Equivalent to String.format("\\u%04x", (int) c);
char[] r = new char[6];
r[0] = '\\';
r[1] = 'u';
r[5] = HEX_DIGITS[c & 0xF];
r[5] = hexDigitsLower[c & 0xF];
c = (char) (c >>> 4);
r[4] = HEX_DIGITS[c & 0xF];
r[4] = hexDigitsLower[c & 0xF];
c = (char) (c >>> 4);
r[3] = HEX_DIGITS[c & 0xF];
r[3] = hexDigitsLower[c & 0xF];
c = (char) (c >>> 4);
r[2] = HEX_DIGITS[c & 0xF];
r[2] = hexDigitsLower[c & 0xF];
return r;
}

Expand Down

0 comments on commit 4c89959

Please sign in to comment.