mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-13 11:09:10 +01:00
Handle nullable case caused by tests
Add mock to test. Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
parent
2de86222b7
commit
ffd2cc1a8c
2 changed files with 17 additions and 4 deletions
|
@ -71,6 +71,7 @@ import bisq.common.util.Tuple2;
|
||||||
import bisq.common.util.Utilities;
|
import bisq.common.util.Utilities;
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.Message;
|
||||||
|
|
||||||
import com.google.inject.name.Named;
|
import com.google.inject.name.Named;
|
||||||
|
|
||||||
|
@ -430,7 +431,11 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
|
||||||
.map(Map.Entry::getValue)
|
.map(Map.Entry::getValue)
|
||||||
.filter(payload -> shouldTransmitPayloadToPeer(peerCapabilities, objToPayload.apply(payload)))
|
.filter(payload -> shouldTransmitPayloadToPeer(peerCapabilities, objToPayload.apply(payload)))
|
||||||
.filter(payload -> {
|
.filter(payload -> {
|
||||||
if (exceededSizeLimit.get() || totalSize.addAndGet(payload.toProtoMessage().getSerializedSize()) > limit) {
|
Message message = payload.toProtoMessage();
|
||||||
|
if (message == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (exceededSizeLimit.get() || totalSize.addAndGet(message.getSerializedSize()) > limit) {
|
||||||
exceededSizeLimit.set(true);
|
exceededSizeLimit.set(true);
|
||||||
}
|
}
|
||||||
return !exceededSizeLimit.get();
|
return !exceededSizeLimit.get();
|
||||||
|
@ -444,7 +449,11 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
|
||||||
.map(Map.Entry::getValue)
|
.map(Map.Entry::getValue)
|
||||||
.filter(payload -> shouldTransmitPayloadToPeer(peerCapabilities, objToPayload.apply(payload)))
|
.filter(payload -> shouldTransmitPayloadToPeer(peerCapabilities, objToPayload.apply(payload)))
|
||||||
.filter(payload -> {
|
.filter(payload -> {
|
||||||
if (exceededSizeLimit.get() || totalSize.addAndGet(payload.toProtoMessage().getSerializedSize()) > limit) {
|
Message message = payload.toProtoMessage();
|
||||||
|
if (message == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (exceededSizeLimit.get() || totalSize.addAndGet(message.getSerializedSize()) > limit) {
|
||||||
exceededSizeLimit.set(true);
|
exceededSizeLimit.set(true);
|
||||||
}
|
}
|
||||||
return !exceededSizeLimit.get();
|
return !exceededSizeLimit.get();
|
||||||
|
|
|
@ -19,6 +19,8 @@ package bisq.network.p2p.storage.mocks;
|
||||||
|
|
||||||
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
|
import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stub implementation of a PersistableNetworkPayload that can be used in tests
|
* Stub implementation of a PersistableNetworkPayload that can be used in tests
|
||||||
* to provide canned answers to calls. Useful if the tests don't care about the implementation
|
* to provide canned answers to calls. Useful if the tests don't care about the implementation
|
||||||
|
@ -29,6 +31,7 @@ import bisq.network.p2p.storage.payload.PersistableNetworkPayload;
|
||||||
public class PersistableNetworkPayloadStub implements PersistableNetworkPayload {
|
public class PersistableNetworkPayloadStub implements PersistableNetworkPayload {
|
||||||
private final boolean hashSizeValid;
|
private final boolean hashSizeValid;
|
||||||
private final byte[] hash;
|
private final byte[] hash;
|
||||||
|
private final protobuf.PersistableNetworkPayload mockPayload;
|
||||||
|
|
||||||
public PersistableNetworkPayloadStub(boolean hashSizeValid) {
|
public PersistableNetworkPayloadStub(boolean hashSizeValid) {
|
||||||
this(hashSizeValid, new byte[]{1});
|
this(hashSizeValid, new byte[]{1});
|
||||||
|
@ -41,11 +44,12 @@ public class PersistableNetworkPayloadStub implements PersistableNetworkPayload
|
||||||
private PersistableNetworkPayloadStub(boolean hashSizeValid, byte[] hash) {
|
private PersistableNetworkPayloadStub(boolean hashSizeValid, byte[] hash) {
|
||||||
this.hashSizeValid = hashSizeValid;
|
this.hashSizeValid = hashSizeValid;
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
|
mockPayload = mock(protobuf.PersistableNetworkPayload.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public protobuf.PersistableNetworkPayload toProtoMessage() {
|
public protobuf.PersistableNetworkPayload toProtoMessage() {
|
||||||
throw new UnsupportedOperationException("Stub does not support protobuf");
|
return mockPayload;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue