@@ -0,0 +1,2100 @@
+package org.jtalks.poulpe.validation.unique;%0A%0Aimport static org.testng.Assert.*;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.*;%0A%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Aimport javax.validation.ConstraintValidatorContext;%0A%0Aimport org.jtalks.poulpe.model.entity.Component;%0Aimport org.testng.annotations.BeforeMethod;%0Aimport org.testng.annotations.Test;%0A%0A/**%0A * @author Alexey Grigorev%0A */%0Apublic class UniqueConstraintValidatorTest %7B%0A    %0A    private UniqueConstraintValidator validator;%0A    private UniquenessViolatorsRetriever uniquenessViolatorsRetriever;%0A    private EntityWrapper entityWrapper;%0A    private ConstraintValidatorContext context;%0A    private Component entity;%0A%0A    @BeforeMethod%0A    public void beforeMethod() %7B%0A        validator = new UniqueConstraintValidator();%0A        uniquenessViolatorsRetriever = mock(UniquenessViolatorsRetriever.class);%0A        validator.setUniquenessViolatorsRetriever(uniquenessViolatorsRetriever);%0A        %0A        entity = new Component();%0A        entityWrapper = new EntityWrapper(entity);%0A        context = mock(ConstraintValidatorContext.class);%0A    %7D%0A%0A    @Test%0A    public void retrieverChecked() %7B%0A        validator.isValid(entity, context);%0A        verify(uniquenessViolatorsRetriever).duplicatesFor(entityWrapper);%0A    %7D%0A    %0A    @Test%0A    public void isValidWhenEmpty() %7B%0A        givenNoDuplicates();%0A        boolean valid = validator.isValid(entity, context);%0A        assertTrue(valid);%0A    %7D%0A%0A    private void givenNoDuplicates() %7B%0A        List%3CEntityWrapper%3E emptyList = Collections.emptyList();%0A        when(uniquenessViolatorsRetriever.duplicatesFor(entityWrapper)).thenReturn(emptyList);%0A    %7D%0A    %0A    @Test%0A    public void isNotValidWhenNotEmpty() %7B%0A        givenDuplicates();%0A        boolean valid = validator.isValid(entity, context);%0A        assertFalse(valid);%0A    %7D%0A%0A    private void givenDuplicates() %7B%0A        List%3CEntityWrapper%3E emptyList = Collections.singletonList(entityWrapper);%0A        when(uniquenessViolatorsRetriever.duplicatesFor(entityWrapper)).thenReturn(emptyList);%0A    %7D%0A%7D%0A

test for UniqueConstraintValidatorTest