Skip to content

Commit

Permalink
Fix pattern in assertion.
Browse files Browse the repository at this point in the history
  • Loading branch information
eamonnmcmanus committed Jul 26, 2023
1 parent f72f871 commit 44edf61
Showing 1 changed file with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void assertFormattingAlwaysEmitsUsLocale(Locale locale) {
DateType.DATE.createAdapterFactory(DateFormat.SHORT, DateFormat.SHORT));
assertFormatted("Jan 1, 1970,? 12:00:00\\hAM",
DateType.DATE.createAdapterFactory(DateFormat.MEDIUM, DateFormat.MEDIUM));
assertFormatted("January 1, 1970,? 12:00:00\\hAM UTC",
assertFormatted("January 1, 1970(,| at)? 12:00:00\\hAM UTC",
DateType.DATE.createAdapterFactory(DateFormat.LONG, DateFormat.LONG));
assertFormatted("Thursday, January 1, 1970(,| at)? 12:00:00\\hAM " + utcFull,
DateType.DATE.createAdapterFactory(DateFormat.FULL, DateFormat.FULL));
Expand Down Expand Up @@ -224,20 +224,7 @@ private static TypeAdapter<Date> dateAdapter(TypeAdapterFactory adapterFactory)
private static void assertFormatted(String formattedPattern, TypeAdapterFactory adapterFactory) {
TypeAdapter<Date> adapter = dateAdapter(adapterFactory);
String json = adapter.toJson(new Date(0));
try {
assertThat(json).matches(toLiteral(formattedPattern));
} catch (AssertionError e) {
StringBuilder sb = new StringBuilder();
char[] chars = json.toCharArray();
for (char c : chars) {
if (c >= ' ' && c <= '~') {
sb.append(c);
} else {
sb.append(String.format("\\u%04x", (int) c));
}
}
throw new AssertionError(sb.toString(), e);
}
assertThat(json).matches(toLiteral(formattedPattern));
}

@SuppressWarnings("UndefinedEquals")
Expand Down

0 comments on commit 44edf61

Please sign in to comment.