Skip to content

Commit bb15966

Browse files
authored
Merge pull request #11 from slonopotamus/windows-tests
Fix test failures on Windows causes by unexpected \r in JSON serialization
2 parents c6adbd2 + 04225de commit bb15966

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

gitlfs-client/src/test/java/ru/bozaro/gitlfs/client/HttpReplay.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ public HttpReplay(@NotNull List<HttpRecord> records) {
2828
public HttpResponse executeMethod(@NotNull HttpUriRequest request) throws IOException {
2929
final HttpRecord record = records.pollFirst();
3030
Assert.assertNotNull(record);
31-
Assert.assertEquals(record.getRequest().toString(), new HttpRecord.Request(request).toString());
31+
32+
final String expected = record.getRequest().toString();
33+
final String actual = new HttpRecord.Request(request).toString();
34+
Assert.assertEquals(actual, expected);
35+
3236
return record.getResponse().toHttpResponse();
3337
}
3438

gitlfs-common/src/main/java/ru/bozaro/gitlfs/common/JsonHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
import com.fasterxml.jackson.annotation.JsonInclude;
44
import com.fasterxml.jackson.core.JsonProcessingException;
5+
import com.fasterxml.jackson.core.util.DefaultIndenter;
6+
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
57
import com.fasterxml.jackson.databind.ObjectMapper;
68
import com.fasterxml.jackson.databind.SerializationFeature;
79
import com.fasterxml.jackson.databind.util.StdDateFormat;
810
import org.jetbrains.annotations.NotNull;
911

12+
import static com.fasterxml.jackson.core.util.DefaultPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR;
13+
1014
/**
1115
* Json utility class.
1216
*
@@ -25,6 +29,12 @@ public static ObjectMapper createMapper() {
2529
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
2630
mapper.enable(SerializationFeature.INDENT_OUTPUT);
2731
mapper.setDateFormat(new StdDateFormat());
32+
33+
// By default, pretty printer uses system newline. Explicitly configure it to use \n
34+
mapper.setDefaultPrettyPrinter(
35+
new DefaultPrettyPrinter(DEFAULT_ROOT_VALUE_SEPARATOR)
36+
.withObjectIndenter(new DefaultIndenter(" ", "\n")));
37+
2838
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
2939
return mapper;
3040
}

0 commit comments

Comments
 (0)