/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */
package org.elasticsearch.xpack.sql.plan.logical;

import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.sql.plan.TableIdentifier;
import org.elasticsearch.xpack.sql.tree.Location;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;

public class UnresolvedRelationTests extends ESTestCase {
    public void testEqualsAndHashCode() {
        Location location = new Location(between(1, 1000), between(1, 1000));
        TableIdentifier table = new TableIdentifier(location, randomAlphaOfLength(5));
        String alias = randomBoolean() ? null : randomAlphaOfLength(5);
        String unresolvedMessage = randomAlphaOfLength(5);
        UnresolvedRelation relation = new UnresolvedRelation(location, table, alias, unresolvedMessage);
        List<Function<UnresolvedRelation, UnresolvedRelation>> mutators = new ArrayList<>();
        mutators.add(r -> new UnresolvedRelation(
            new Location(r.location().getLineNumber() + 1, r.location().getColumnNumber()), r.table(), r.alias(), r.unresolvedMessage()));
        mutators.add(r -> new UnresolvedRelation(
            r.location(), new TableIdentifier(r.location(), r.table().index() + "m"), r.alias(), r.unresolvedMessage()));
        mutators.add(r -> new UnresolvedRelation(
            r.location(),
            r.table(),
            randomValueOtherThan(r.alias(), () -> randomBoolean() ? null : randomAlphaOfLength(5)),
            r.unresolvedMessage()));
        mutators.add(r -> new UnresolvedRelation(
            r.location(), r.table(), r.alias(), randomValueOtherThan(r.unresolvedMessage(), () -> randomAlphaOfLength(5))));
        checkEqualsAndHashCode(relation,
            r -> new UnresolvedRelation(r.location(), r.table(), r.alias(), r.unresolvedMessage()),
            r -> randomFrom(mutators).apply(r));
    }
}

@@ -435,16 +435,17 @@
 cation;%0A
+%0A
 import j
@@ -483,24 +483,50 @@
 .util.List;%0A
+import java.util.Objects;%0A
 import java.
@@ -1371,38 +1371,74 @@
 mber()),
- r.table(), r.alias(),
+%0A            r.table(),%0A            r.alias(),%0A           
  r.unres
@@ -1530,16 +1530,28 @@
 ation(),
+%0A           
  new Tab
@@ -1602,27 +1602,51 @@
  + %22m%22),
- r.alias(),
+%0A            r.alias(),%0A           
  r.unres
@@ -1798,19 +1798,80 @@
 Than
-(r.alias(),
+Many(%0A                a -%3E Objects.equals(a, r.alias()),%0A               
  () 
@@ -2035,38 +2035,74 @@
 ation(),
- r.table(), r.alias(),
+%0A            r.table(),%0A            r.alias(),%0A           
  randomV

Fix test for UnresolvedRelation