Exemple #1
0
  @Before
  public void setup() throws Exception {
    // TODO: figure out how initialization can be refactored with @InjectMocks
    final StorageNode n = new StorageNode("node1", storage);
    node = spy(n);

    nodeContext = new StorageExecutionContext(communicationContext, node);
    nodeContext = spy(nodeContext);
    n.configure(nodeContext);
    node.configure(nodeContext);

    Mockito.reset(node);
    verifyZeroInteractions(nodeContext);
    verifyZeroInteractions(storage);
    verifyZeroInteractions(node);

    assertEquals("node1", node.getId());
    assertEquals("NEW", node.getState());

    // verify(node, atLeastOnce()).getId();
    // verify(node).getState();

    verifyZeroInteractions(nodeContext, storage, node);

    doAnswer(
            invocation -> {
              final StorageOperation op = (StorageOperation) invocation.getArguments()[0];
              doReturn(op).when(operationContext).operation();
              return operationContext;
            })
        .when(nodeContext)
        .contextFor(any(StorageOperation.class));
  }
Exemple #2
0
  private void manageNode(ControlMessage.Builder builder) {
    final ControlMessage msg = builder.setSender("Anonymous").build();

    try {
      nodeContext.onMessage(node.getId(), Messages.MessageTypes.ControlMessage, msg);
    } catch (Exception e) {
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      }
      throw new RuntimeException(e);
    }
  }