package com.epam.rft.atsy.persistence.repositories;

import com.epam.rft.atsy.persistence.entities.CandidateEntity;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;

import java.util.List;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;

public class CandidateRepositoryIT extends AbstractRepositoryIT {

    @Autowired
    private CandidateRepository candidateRepository;

    @Test
    public void findAllCandidatesByFilterRequestWithValidData() {
        for (int i = 1; i < 9; i++) {

            //Given
            String name = "", email = "", phone = "";

            if (i / 2 > 0) {
                name = "date";
            }

            if (i % 4 == 0) {
                email = "atsy.";
            }

            if (i % 8 == 0) {
                phone = "36";
            }

            //When
            List<CandidateEntity> result
                    = this.candidateRepository.findAllCandidatesByFilterRequest(name, email, phone, new Sort(Sort.DEFAULT_DIRECTION, "name"));

            System.err.println("i="+ i);
            System.err.println("name:" + name);
            System.err.println("email:" + email);
            System.err.println("phone:" + phone);
            System.err.println(result);
            //Then
            assertCandidateEntityList(result, name, email, phone);
        }
    }

    private void assertCandidateEntityList(List<CandidateEntity> actual,
                                           String expectedName,
                                           String expectedEmail,
                                           String expectedPhone) {

        for (CandidateEntity entity : actual) {

            assertThat(entity, notNullValue());

            if (!expectedName.isEmpty()) {
                assertThat(entity.getName(), notNullValue());
                assertThat(entity.getName(), containsString(expectedName));
            }

            if (!expectedEmail.isEmpty()) {
                assertThat(entity.getEmail(), notNullValue());
                assertThat(entity.getEmail(), containsString(expectedEmail));
            }

            if (!expectedPhone.isEmpty()) {
                assertThat(entity.getPhone(), notNullValue());
                assertThat(entity.getPhone(), containsString(expectedPhone));
            }

        }
    }
}

@@ -109,16 +109,131 @@
 Entity;%0A
+import com.epam.rft.atsy.persistence.entities.ChannelEntity;%0Aimport com.sun.javafx.scene.control.skin.VirtualFlow;%0A
 import o
@@ -352,24 +352,77 @@
 main.Sort;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0A
 import java.
@@ -658,322 +658,1042 @@
     
-@Autowired%0A    private CandidateRepository candidateRepository;%0A%0A    @Te
+private static String possibleName = %22date A%22;%0A    private static String possibleEmail = %22atsy.%22;%0A    private static String possiblePhone = %2277%22;%0A%0A    private static List%3CCandidateEntity%3E positiveTestCases =%0A            Arrays.asLi
 st
+(
 %0A    
-public void findAllCandidatesByFilterRequestWithValidData() %7B%0A        for (int i = 1; i %3C 9; i++) %7B%0A%0A            //Given%0A            String name = %22%22, email = %22%22, phone = %22%22;%0A%0A            if (i / 2 %3E 0) %7B%0A                name = %22date%22;
+                CandidateEntity.builder().name(%22%22).email(%22%22).phone(%22%22).build(),%0A                    CandidateEntity.builder().name(%22%22).email(%22%22).phone(possiblePhone).build(),%0A                    CandidateEntity.builder().name(%22%22).email(possibleEmail).phone(%22%22).build(),%0A                    CandidateEntity.builder().name(possibleName).email(%22%22).phone(%22%22).build(),%0A                    CandidateEntity.builder().name(%22%22).email(possibleEmail).phone(possiblePhone).build(),%0A                    CandidateEntity.builder().name(possibleName).email(%22%22).phone(possiblePhone).build(),%0A                    CandidateEntity.builder().name(possibleName).email(possibleEmail).phone(%22%22).build(),%0A                    CandidateEntity.builder().name(possibleName).email(possibleEmail).phone(possiblePhone).build()%0A
 %0A   
@@ -1705,73 +1705,218 @@
     
-%7D
+);
 %0A%0A    
-        if (i %25 4 == 0) %7B%0A                email = %22atsy.%22;
+@Autowired%0A    private CandidateRepository candidateRepository;%0A%0A    @Test%0A    public void findAllCandidatesByFilterRequestWithValidData() %7B%0A        for (CandidateEntity candidate : positiveTestCases) %7B
 %0A   
@@ -1916,34 +1916,39 @@
 ) %7B%0A            
-%7D%0A
+//Given
 %0A            if 
@@ -1948,69 +1948,140 @@
     
-if (i %25 8 == 0) %7B%0A                phone = %2236%22;%0A            %7D
+String name = candidate.getName();%0A            String email = candidate.getEmail();%0A            String phone = candidate.getPhone();
 %0A%0A  
@@ -2286,49 +2286,8 @@
 );%0A%0A
-            System.err.println(%22i=%22+ i);%0A
     

Add decision tree for positive test cases