package io.xlate.validation.constraintvalidation;

import java.util.HashMap;
import java.util.Map;

import javax.validation.ConstraintValidatorContext;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import io.xlate.validation.constraints.Expression;

@ExtendWith(MockitoExtension.class)
@RunWith(JUnitPlatform.class)
class ExpressionValidatorTest {

    ExpressionValidator target;

    @Mock ConstraintValidatorContext context;

    @Mock Expression annotation;

    /*@BeforeEach
    void initialize() {
        target = new ExpressionValidator();
    }*/

    @Test
    void testLiteralTrue() {
        target = new ExpressionValidator();
        Mockito.when(annotation.value()).thenReturn("true");
        target.initialize(annotation);
        Assertions.assertTrue(target.isValid(null, context));
    }

    @Test
    void testLiteralFalse() {
        target = new ExpressionValidator();
        Mockito.when(annotation.value()).thenReturn("false");
        target.initialize(annotation);
        Assertions.assertFalse(target.isValid(null, context));
    }

    @Test
    void testStringIdentityTrue() {
        target = new ExpressionValidator();
        Mockito.when(annotation.value()).thenReturn("'I' == 'I'");
        target.initialize(annotation);
        Assertions.assertTrue(target.isValid(null, context));
    }

    @Test
    void testNumericComparison() {
        target = new ExpressionValidator();
        Mockito.when(annotation.value()).thenReturn("self.smaller lt self.larger");
        Map<String, Integer> data = new HashMap<>();
        data.put("smaller", 1);
        data.put("larger", 2);
        target.initialize(annotation);
        Assertions.assertTrue(target.isValid(data, context));
    }


}

@@ -40,24 +40,47 @@
 alidation;%0A%0A
+import java.util.Date;%0A
 import java.
@@ -93,16 +93,16 @@
 ashMap;%0A
-
 import j
@@ -210,16 +210,57 @@
 rtions;%0A
+import org.junit.jupiter.api.BeforeEach;%0A
 import o
@@ -796,10 +796,8 @@
     
-/*
 @Bef
@@ -881,10 +881,8 @@
    %7D
-*/
 %0A%0A  
@@ -922,52 +922,8 @@
 ) %7B%0A
-        target = new ExpressionValidator();%0A
     
@@ -1131,52 +1131,8 @@
 ) %7B%0A
-        target = new ExpressionValidator();%0A
     
@@ -1348,52 +1348,8 @@
 ) %7B%0A
-        target = new ExpressionValidator();%0A
     
@@ -1568,52 +1568,8 @@
 ) %7B%0A
-        target = new ExpressionValidator();%0A
     
@@ -1872,11 +1872,373 @@
 %0A    %7D%0A%0A
+    @Test%0A    void testDateComparison() %7B%0A        Mockito.when(annotation.value()).thenReturn(%22self.earlier lt self.later%22);%0A        Map%3CString, Date%3E data = new HashMap%3C%3E();%0A        data.put(%22earlier%22, new Date(1));%0A        data.put(%22later%22, new Date());%0A        target.initialize(annotation);%0A        Assertions.assertTrue(target.isValid(data, context));%0A    %7D
 %0A%7D%0A

Test cleanup