package io.ebean.xtest.internal.api;

import io.ebeaninternal.api.BindParams;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

public class BindParamsTest {

  @Test
  public void test_hash() {

    BindParams bindParams = new BindParams();

    List<String> ids = Arrays.asList("1", "2", "3");
    bindParams.setParameter("ids", ids);
    BindParams.Param param = bindParams.parameter("ids");
    assertEquals(3, param.queryBindCount());
    assertFalse(bindParams.isSameBindHash());
    bindParams.updateHash();

    List<String> ids2 = Arrays.asList("1", "2", "3", "4");
    bindParams.setParameter("ids", ids2);
    assertEquals(4, param.queryBindCount());
    assertFalse(bindParams.isSameBindHash());
    bindParams.updateHash();

    List<String> ids3 = Arrays.asList("2", "99", "44");
    bindParams.setParameter("ids", ids3);
    assertEquals(3, param.queryBindCount());
    assertFalse(bindParams.isSameBindHash());
    bindParams.updateHash();

    List<String> ids4 = Arrays.asList("4545", "3499", "3444");
    bindParams.setParameter("ids", ids4);
    assertEquals(3, param.queryBindCount());
    assertTrue(bindParams.isSameBindHash());
  }

}
