package fi.hsl.parkandride.core.domain;

import static fi.hsl.parkandride.core.domain.FacilityStatus.IN_OPERATION;
import static fi.hsl.parkandride.core.domain.PricingMethod.CUSTOM;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;

import org.geolatte.geom.Geometry;
import org.geolatte.geom.Polygon;
import org.junit.Test;
import org.mockito.Mockito;

public class ViolationTest {
    private final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

    @Test
    public void nonCapacityViolation_is_not_translated() {
        assertThat(path(nameViolation())).isEqualTo("name.fi");
    }

    private String path(ConstraintViolation<Facility> cv) {
        return new Violation(cv).path;
    }

    private ConstraintViolation<Facility> nameViolation() {
        Facility f = validFacility();
        f.operatorId  = 1l;
        f.status = IN_OPERATION;
        f.contacts.emergency = 1l;
        f.contacts.operator = 1l;
        f.name = new MultilingualString("", "Test", "Test");
        return toFacilityConstraintViolation(f);
    }

    private ConstraintViolation<Facility> toFacilityConstraintViolation(Facility f) {
        Set<ConstraintViolation<Facility>> violations = validator.validate(f);
        assertThat(violations).hasSize(1);
        return violations.iterator().next();
    }

    private Facility validFacility() {
        Facility f = new Facility();
        f.operatorId  = 1l;
        f.status = IN_OPERATION;
        f.pricingMethod = CUSTOM;
        f.contacts.emergency = 1l;
        f.contacts.operator = 1l;
        f.name = new MultilingualString("Test", "Test", "Test");
        f.location = Mockito.mock(Polygon.class);

        Set<ConstraintViolation<Facility>> violations = validator.validate(f);
        assertThat(violations).isEmpty();

        return f;
    }
}
@@ -378,43 +378,8 @@
 r;%0A%0A
-import org.geolatte.geom.Geometry;%0A
 impo
@@ -434,36 +434,8 @@
 est;
-%0Aimport org.mockito.Mockito;
 %0A%0Apu
@@ -1741,34 +1741,28 @@
 n = 
-Mockito.mock(Polygon.class
+Polygon.createEmpty(
 );%0A%0A

fix Polygon mock