package data; import com.google.common.collect.Sets; import org.testng.Assert; import org.testng.annotations.Test; import java.util.HashMap; import java.util.HashSet; import java.util.Set; @Test public class SetsTest { private HashMap map; private Table table; private Row row; private StubTestDatabase testDatabase; public void uniqueKeyRepeated() { map = new HashMap(); map.put("foo", new PrimaryKey("abc")); testDatabase = new StubTestDatabase(map); table = new Table("foo", testDatabase, "efg"); Row row = new Row(table); row.setColumnValue("abc", "123"); row.setColumnValue("efg", "456"); Set firstSet = new HashSet(); firstSet.add(row); row = new Row(table); row.setColumnValue("abc", "321"); row.setColumnValue("efg", "456"); Set secondSet = new HashSet(); secondSet.add(row); Assert.assertEquals(1, Sets.intersection(firstSet, secondSet).size()); Assert.assertEquals(1, Sets.union(firstSet, secondSet).size()); } public void primaryKeyRepeated() { map = new HashMap(); map.put("foo", new PrimaryKey("abc")); testDatabase = new StubTestDatabase(map); table = new Table("foo", testDatabase, "efg"); Row row = new Row(table); row.setColumnValue("abc", "123"); row.setColumnValue("efg", "654"); Set firstSet = new HashSet(); firstSet.add(row); row = new Row(table); row.setColumnValue("abc", "123"); row.setColumnValue("efg", "456"); Set secondSet = new HashSet(); secondSet.add(row); Assert.assertEquals(1, Sets.intersection(firstSet, secondSet).size()); Assert.assertEquals(1, Sets.union(firstSet, secondSet).size()); } public void noPrimaryKeyWithUniqueKey() { map = new HashMap(); testDatabase = new StubTestDatabase(map); table = new Table("foo", testDatabase, "efg"); Row row = new Row(table); row.setColumnValue("abc", "123"); row.setColumnValue("efg", "654"); Set firstSet = new HashSet(); firstSet.add(row); row = new Row(table); row.setColumnValue("abc", "123"); row.setColumnValue("efg", "456"); Set secondSet = new HashSet(); secondSet.add(row); Assert.assertEquals(0, Sets.intersection(firstSet, secondSet).size()); Assert.assertEquals(2, Sets.union(firstSet, secondSet).size()); } public void noPrimaryKeyWithUniqueKeyAndSomeColumnsNull() { map = new HashMap(); testDatabase = new StubTestDatabase(map); table = new Table("foo", testDatabase, "efg"); Row row = new Row(table); row.setColumnValue("abc", null); row.setColumnValue("efg", "654"); Set firstSet = new HashSet(); firstSet.add(row); row = new Row(table); row.setColumnValue("abc", "123"); row.setColumnValue("efg", "456"); Set secondSet = new HashSet(); secondSet.add(row); Assert.assertEquals(0, Sets.intersection(firstSet, secondSet).size()); Assert.assertEquals(2, Sets.union(firstSet, secondSet).size()); } } row.setColumnValue("abc", null); row.setColumnValue("efg", "654"); Set firstSet = new HashSet(); firstSet.add(row); row = new Row(table); row.setColumnValue("abc", "123"); r