Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace printHexBinary with using Formatter to avoid deps clash #58

Merged
merged 2 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import com.twosigma.webtau.expectation.equality.CompareToComparator;
import com.twosigma.webtau.expectation.equality.CompareToHandler;

import javax.xml.bind.DatatypeConverter;
import java.util.Arrays;
import java.util.Formatter;
import java.util.Objects;

public class ByteArrayCompareToHandler implements CompareToHandler {
Expand Down Expand Up @@ -78,6 +78,15 @@ private String portionOfArrayAsHex(byte[] array, int startIdx) {

String possibleEllipsisPrefix = startIdx > 0 ? "..." : "";
String possibleEllipsisSuffix = (startIdx + len) < array.length ? "..." : "";
return possibleEllipsisPrefix + DatatypeConverter.printHexBinary(subArray) + possibleEllipsisSuffix;
return possibleEllipsisPrefix + renderAsHex(subArray) + possibleEllipsisSuffix;
}

private String renderAsHex(byte[] content) {
Formatter formatter = new Formatter();
for (byte b : content) {
formatter.format("%02X", b);
}

return formatter.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void capture(String artifactName) {
requestHeader);
}

if (lastValidationResult.getRequestType() != null) {
if (lastValidationResult.getRequestType() != null && !lastValidationResult.isRequestBinary()) {
String fileName = "request." + fileExtensionForType(lastValidationResult.getRequestType());
FileUtils.writeTextContent(path.resolve(fileName),
prettyPrintContent(lastValidationResult.getRequestType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public String getRequestType() {
return requestBody != null ? requestBody.type() : null;
}

public boolean isRequestBinary() {
return requestBody != null && requestBody.isBinary();
}

public String getResponseType() {
return response.getContentType();
}
Expand Down