package com.atlassian.stash.internal.rest.user;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import java.util.Collections;

import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public final class ValidatorsTest {

    @Mock
    private Validator validator;
    @Mock
    private ConstraintViolation<Object> constraintViolation;

    @Test
    public void testSatisfiedConstraints() throws Exception {
        when(validator.validate(anyObject())).thenReturn(Collections.<ConstraintViolation<Object>>emptySet());
        Validators.validateConstraints(validator, new Object());
    }

    @Test(expected = ConstraintViolationException.class)
    public void testInvalidConstraints() throws Exception {
        when(validator.validate(anyObject())).thenReturn(Collections.singleton(constraintViolation));
        Validators.validateConstraints(validator, new Object());
    }

}
