1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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<Temp> 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<Temp> 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<Temp> init = DataDaoVo.init(his, now, new DataDaoKey<Temp>() {
@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);
}
}