### Question:
IntegrityValidator { public void validateSchemaRule( SchemaRule schemaRule ) throws TransactionFailureException { if ( schemaRule instanceof ConstraintRule ) { ConstraintRule constraintRule = (ConstraintRule) schemaRule; if ( constraintRule.getConstraintDescriptor().enforcesUniqueness() ) { try { indexes.validateIndex( constraintRule.getOwnedIndex() ); } catch ( UniquePropertyValueValidationException e ) { throw new TransactionFailureException( Status.Transaction.TransactionValidationFailed, e, "Index validation failed" ); } catch ( IndexNotFoundKernelException | IndexPopulationFailedKernelException e ) { throw new TransactionFailureException( Status.Transaction.TransactionValidationFailed, e, "Index population failure" ); } } } } IntegrityValidator( NeoStores neoStores, IndexingService indexes ); void validateNodeRecord( NodeRecord record ); void validateTransactionStartKnowledge( long lastCommittedTxWhenTransactionStarted ); void validateSchemaRule( SchemaRule schemaRule );  }### Answer:
@Test public void shouldValidateUniquenessIndexes() throws Exception { NeoStores store = mock( NeoStores.class ); IndexingService indexes = mock(IndexingService.class); IntegrityValidator validator = new IntegrityValidator( store, indexes ); UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel( 1, 1 ); doThrow( new UniquePropertyValueValidationException( constraint, ConstraintValidationException.Phase.VERIFICATION, new RuntimeException() ) ) .when( indexes ).validateIndex( 2L ); ConstraintRule record = ConstraintRule.constraintRule( 1L, constraint, 2L ); try { validator.validateSchemaRule( record ); fail("Should have thrown integrity error."); } catch ( Exception e ) { } }