@Test
  public void shouldGetConstraintsByLabel() throws Exception {
    // given
    UniquenessConstraint constraint1 = new UniquenessConstraint(11, 66);
    UniquenessConstraint constraint2 = new UniquenessConstraint(11, 99);

    TxState txState =
        new TxStateImpl(
            mock(OldTxStateBridge.class), mock(PersistenceManager.class), mock(IdGeneration.class));
    KernelStatement state = mockedState(txState);
    when(inner.constraintsGetForLabelAndPropertyKey(10, 66))
        .thenAnswer(asAnswer(Collections.emptyList()));
    when(inner.constraintsGetForLabelAndPropertyKey(11, 99))
        .thenAnswer(asAnswer(Collections.emptyList()));
    when(inner.constraintsGetForLabel(10)).thenAnswer(asAnswer(Collections.emptyList()));
    when(inner.constraintsGetForLabel(11)).thenAnswer(asAnswer(asIterable(constraint1)));
    StateHandlingStatementOperations context = newTxStateOps(inner);
    context.uniquenessConstraintCreate(state, 10, 66);
    context.uniquenessConstraintCreate(state, 11, 99);

    // when
    Set<UniquenessConstraint> result = asSet(asIterable(context.constraintsGetForLabel(state, 11)));

    // then
    assertEquals(asSet(constraint1, constraint2), result);
  }
  @Test
  public void shouldNotAddConstraintAlreadyExistsInTheStore() throws Exception {
    // given
    UniquenessConstraint constraint = new UniquenessConstraint(10, 66);
    TxState txState = mock(TxState.class);
    when(txState.nodesWithLabelChanged(anyInt())).thenReturn(DiffSets.<Long>emptyDiffSets());
    KernelStatement state = mockedState(txState);
    when(inner.constraintsGetForLabelAndPropertyKey(10, 66))
        .thenAnswer(asAnswer(asList(constraint)));
    StateHandlingStatementOperations context = newTxStateOps(inner);

    // when
    context.uniquenessConstraintCreate(state, 10, 66);

    // then
    verify(txState).constraintIndexDoUnRemove(any(IndexDescriptor.class));
  }
  @Test
  public void shouldNeverDelegateWrites() throws Exception {
    KernelStatement state = mockedState();
    StateHandlingStatementOperations ctx = newTxStateOps(inner);

    // When
    ctx.indexCreate(state, 0, 0);
    ctx.nodeAddLabel(state, 0, 0);
    ctx.indexDrop(state, new IndexDescriptor(0, 0));
    ctx.nodeRemoveLabel(state, 0, 0);

    // These are kind of in between.. property key ids are created in
    // micro-transactions, so these methods
    // circumvent the normal state of affairs. We may want to rub the
    // genius-bumps over this at some point.
    // ctx.getOrCreateLabelId("0");
    // ctx.getOrCreatePropertyKeyId("0");

    verify(inner, times(2)).nodeHasLabel(state, 0, 0);
    verifyNoMoreInteractions(inner);
  }