Skip to content
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,7 +21,6 @@

public class IProtoResponseImpl implements IProtoMessage {

private StringBuilder stringBuilder;
protected MapValue header;
protected MapValue body;
protected Map<Integer, Value> headerMap;
Expand Down Expand Up @@ -51,19 +50,13 @@ protected static Map<Integer, Value> convertMap(MapValue map) {

@Override
public String toString() {
if (this.stringBuilder == null) {
this.stringBuilder = new StringBuilder();
}

this.stringBuilder.append("IProtoResponseImpl(header = ").append(getHeader().toJson());
String result = "IProtoResponseImpl(header = " + getHeader().toJson();

if (getBody() != null) {
this.stringBuilder.append(", body = ").append(getBody().toJson());
result += ", body = " + getBody().toJson();
}

this.stringBuilder.append(")");

return this.stringBuilder.toString();
return result + ")";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2026 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY
* All Rights Reserved.
*/

package io.tarantool.core.unit.protocol;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.msgpack.value.ValueFactory;

import static io.tarantool.core.protocol.requests.IProtoConstant.MP_IPROTO_REQUEST_TYPE;
import io.tarantool.core.protocol.IProtoResponseImpl;

public class IProtoResponseImplTest {

@Test
public void testToStringDoesNotDuplicateOnRepeatedCalls() {
IProtoResponseImpl response =
new IProtoResponseImpl(
ValueFactory.newMap(MP_IPROTO_REQUEST_TYPE, ValueFactory.newInteger(0)),
ValueFactory.emptyMap());

String first = response.toString();
String second = response.toString();

assertTrue(first.startsWith("IProtoResponseImpl(header = "));
assertEquals(first, second);
}
}
Loading