File tree Expand file tree Collapse file tree 3 files changed +68
-3
lines changed
springboot-starter/src/test/java/com/codingapi/springboot/framework/domain Expand file tree Collapse file tree 3 files changed +68
-3
lines changed Original file line number Diff line number Diff line change 22
33import com .codingapi .springboot .framework .event .DemoChangeEvent ;
44import com .codingapi .springboot .framework .event .EventPusher ;
5- import lombok .AllArgsConstructor ;
5+ import com .codingapi .springboot .framework .serializable .JsonSerializable ;
6+ import com .codingapi .springboot .framework .serializable .MapSerializable ;
7+ import lombok .Getter ;
68
7- @ AllArgsConstructor
8- public class Demo {
9+ public class Demo implements JsonSerializable , MapSerializable {
910
11+ @ Getter
12+ private long id ;
13+ @ Getter
1014 private String name ;
1115
16+ public Demo (String name ) {
17+ this .name = name ;
18+ this .id = System .currentTimeMillis ();
19+ }
20+
1221 public void changeName (String name ) {
1322 String beforeName = this .name ;
1423 this .name = name ;
Original file line number Diff line number Diff line change 1+ package com .codingapi .springboot .framework .domain ;
2+
3+ import lombok .Getter ;
4+ import lombok .Setter ;
5+
6+ @ Setter
7+ @ Getter
8+ public class DemoEntity {
9+
10+ private Integer id ;
11+ private String name ;
12+
13+
14+ }
Original file line number Diff line number Diff line change 1+ package com .codingapi .springboot .framework .domain ;
2+
3+ import com .alibaba .fastjson .JSONObject ;
4+ import com .codingapi .springboot .framework .convert .BeanConvertor ;
5+ import org .junit .jupiter .api .Test ;
6+ import org .springframework .boot .test .context .SpringBootTest ;
7+
8+ import java .util .Map ;
9+
10+ import static org .junit .jupiter .api .Assertions .assertEquals ;
11+
12+ @ SpringBootTest
13+ class DemoTest {
14+
15+ @ Test
16+ void eventTest () {
17+ Demo demo = new Demo ("xiaoming" );
18+ demo .changeName ("xiaomi" );
19+ }
20+
21+ @ Test
22+ void jsonTest () {
23+ Demo demo = new Demo ("xiaoming" );
24+ JSONObject json = JSONObject .parseObject (demo .toJson ());
25+ assertEquals (json .getString ("name" ), demo .getName (), "json serializable error" );
26+ }
27+
28+ @ Test
29+ void mapTest () {
30+ Demo demo = new Demo ("xiaoming" );
31+ Map <String , Object > map = demo .toMap ();
32+ assertEquals (map .get ("name" ), demo .getName (), "map serializable error" );
33+ }
34+
35+ @ Test
36+ void convertTest () {
37+ Demo demo = new Demo ("xiaoming" );
38+ DemoEntity entity = BeanConvertor .convert (demo , DemoEntity .class );
39+ assertEquals (entity .getName (), demo .getName (), "convert serializable error" );
40+ }
41+
42+ }
You can’t perform that action at this time.
0 commit comments