package helper; import com.yanzuoguang.util.helper.CheckerHelper; import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.vo.DataDaoKey; import com.yanzuoguang.util.vo.DataDaoVo; import org.junit.Assert; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; public class DataDaoVoTest { class Temp { long id; String productId; String productType; int value; int removeFlag; public Temp() { } public Temp(long id, String productId, String productType, int value, int removeFlag) { this.id = id; this.productId = productId; this.productType = productType; this.value = value; this.removeFlag = removeFlag; } } @Test public void testEn() { int id = 1; Temp last = new Temp(id++, "产品3", "类型3", 4, 0); List his = Arrays.asList( new Temp(id++, "产品1", "类型1", 1, 0), new Temp(id++, "产品1", "类型1", 2, 1), new Temp(id++, "产品1", "类型1", 3, 1), new Temp(id++, "产品1", "类型1", 4, 1), new Temp(id++, "产品2", "类型2", 4, 0), last ); List now = Arrays.asList( new Temp(id++, "产品1", "类型1", 9, 0), new Temp(id++, "产品2", "类型2", 43, 0), new Temp(id++, "产品4", "类型4", 95, 0) ); DataDaoVo init = DataDaoVo.init(his, now, new DataDaoKey() { @Override public String getKey(Temp from) { return StringHelper.getId(from.productId, from.productType); } }); Assert.assertEquals(init.getCreates().size(), 1); Assert.assertEquals(init.getUpdates().size(), 2); Assert.assertEquals(init.getRemoves().size(), 4); Assert.assertEquals(last.removeFlag, 1); } }