LiveOperationRegistry { public void register(Operation operation) { Map<Long, Operation> callIds = liveOperations.computeIfAbsent(operation.getCallerAddress(), (key) -> new ConcurrentHashMap<>()); if (callIds.putIfAbsent(operation.getCallId(), operation) != null) { throw new IllegalStateException("Duplicate operation during registration of operation=" + operation); } }  void register(Operation operation); void deregister(Operation operation); void populate(LiveOperations liveOperations);  }
@Test public void when_registerDuplicateCallId_then_exception() throws UnknownHostException { r.register(createOperation("1.2.3.4", 1234, 2222L)); r.register(createOperation("1.2.3.4", 1234, 2223L)); exception.expect(IllegalStateException.class); r.register(createOperation("1.2.3.4", 1234, 2222L)); }