/
AliasForAndConverterTest.java
65 lines (49 loc) · 1.49 KB
/
AliasForAndConverterTest.java
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
package com.keroz.beancopyutils;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
import com.keroz.beancopyutils.annotation.AliasFor;
import com.keroz.beancopyutils.annotation.Converter;
import org.junit.jupiter.api.Test;
import lombok.Data;
import lombok.ToString;
public class AliasForAndConverterTest {
@Data
public static class Source {
private long timestamp = 1603941172886L;
}
@Data
@ToString
public static class Target {
@AliasFor("timestamp")
@Converter(TimestampToDateConverter.class)
private Date date;
}
public static class TimestampToDateConverter implements com.keroz.beancopyutils.converter.Converter<Long, Date> {
@Override
public Date convert(Long source) {
System.out.println(this);
return new Date(source);
}
}
@Test
public void testAliasForAndConverter() {
Target t = BeanCopyUtils.copy(new Source(), Target.class);
System.out.println(t);
}
@Test
public void testConverterSingleton() {
int threadNum = 10;
CountDownLatch latch = new CountDownLatch(threadNum);
for (int i = 0; i < threadNum; i++) {
new Thread(() -> {
BeanCopyUtils.copy(new Source(), Target.class);
latch.countDown();
}).start();
}
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}