package cn.novalon.manage.db.dao;

import org.junit.jupiter.api.Test;
import org.springframework.data.relational.core.query.Criteria;

/**
 * QueryUtil测试类
 */
class QueryUtilTest {

    @Test
    void testOrCriteriaConstruction() {
        String[] blurrys = {"username", "email"};
        String val = "search";
        
        // 当前的实现方式
        Criteria orCriteria = Criteria.empty();
        for (String s : blurrys) {
            orCriteria = orCriteria.or(s).like("%" + val + "%");
        }
        
        System.out.println("当前实现的Criteria: " + orCriteria);
        
        // 正确的实现方式
        Criteria correctOrCriteria = Criteria.where("username").like("%" + val + "%")
                .or("email").like("%" + val + "%");
        
        System.out.println("正确实现的Criteria: " + correctOrCriteria);
        
        // 比较两种实现
        System.out.println("两种实现是否相同: " + orCriteria.equals(correctOrCriteria));
    }
}
