@Test @DisplayName("should unsubscribe a subscribing receiver") void unsubscribe() { DataReceiver receiver = new DataReceiver() { @Override public void dataReceived(String data) { assert false; } }; comInstance.subscribe(Direction.INTERNAL, receiver); comInstance.unsubscribe(Direction.INTERNAL, receiver); comInstance.transmitData(value, Direction.INTERNAL); }
@Override public void unsubscribe(Direction direction, DataReceiver receiver) { int index = -1; List<DataReceiver> receivers = this.subscribers.get(direction); for (int i = 0; i < receivers.size(); i++) { DataReceiver dataReceiver = receivers.get(i); if (dataReceiver == receiver) { index = i; } } if (index != -1) { receivers.remove(index); } }
CommunicationsMediatorImpl implements CommunicationsMediator { @Override public void unsubscribe(Direction direction, DataReceiver receiver) { int index = -1; List<DataReceiver> receivers = this.subscribers.get(direction); for (int i = 0; i < receivers.size(); i++) { DataReceiver dataReceiver = receivers.get(i); if (dataReceiver == receiver) { index = i; } } if (index != -1) { receivers.remove(index); } } }
CommunicationsMediatorImpl implements CommunicationsMediator { @Override public void unsubscribe(Direction direction, DataReceiver receiver) { int index = -1; List<DataReceiver> receivers = this.subscribers.get(direction); for (int i = 0; i < receivers.size(); i++) { DataReceiver dataReceiver = receivers.get(i); if (dataReceiver == receiver) { index = i; } } if (index != -1) { receivers.remove(index); } } CommunicationsMediatorImpl(); }
CommunicationsMediatorImpl implements CommunicationsMediator { @Override public void unsubscribe(Direction direction, DataReceiver receiver) { int index = -1; List<DataReceiver> receivers = this.subscribers.get(direction); for (int i = 0; i < receivers.size(); i++) { DataReceiver dataReceiver = receivers.get(i); if (dataReceiver == receiver) { index = i; } } if (index != -1) { receivers.remove(index); } } CommunicationsMediatorImpl(); @Override void transmitData(String data, Direction direction); @Override void subscribe(Direction direction, DataReceiver receiver); @Override void unsubscribe(Direction direction, DataReceiver receiver); }
CommunicationsMediatorImpl implements CommunicationsMediator { @Override public void unsubscribe(Direction direction, DataReceiver receiver) { int index = -1; List<DataReceiver> receivers = this.subscribers.get(direction); for (int i = 0; i < receivers.size(); i++) { DataReceiver dataReceiver = receivers.get(i); if (dataReceiver == receiver) { index = i; } } if (index != -1) { receivers.remove(index); } } CommunicationsMediatorImpl(); @Override void transmitData(String data, Direction direction); @Override void subscribe(Direction direction, DataReceiver receiver); @Override void unsubscribe(Direction direction, DataReceiver receiver);  }