From a59cadc537d78df392fea9304398cfa69096d4b4 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Mon, 26 Aug 2024 18:26:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=20diff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/ValidatableStringRecordTests.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/test/java/xyz/zhouxy/plusone/commons/model/ValidatableStringRecordTests.java b/src/test/java/xyz/zhouxy/plusone/commons/model/ValidatableStringRecordTests.java index 885adfb..c67811c 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/model/ValidatableStringRecordTests.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/model/ValidatableStringRecordTests.java @@ -6,6 +6,10 @@ import cn.hutool.core.util.ObjectUtil; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; + +import org.apache.commons.lang3.builder.DiffBuilder; +import org.apache.commons.lang3.builder.DiffResult; +import org.apache.commons.lang3.builder.ToStringStyle; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,8 +41,7 @@ class ValidatableStringRecordTests { Username.of("ZhouXY108"), Username.of("code_108"), Username.of("Luquan"), - Username.of("Code108") - ); + Username.of("Code108")); log.info("{}", Collections.max(usernames)); Function compare = o -> o.value().toLowerCase(); log.info("{}", Collections.max(usernames, Comparator.comparing(compare))); @@ -51,6 +54,9 @@ class ValidatableStringRecordTests { obj.setUsername(Username.of("ZhouXY108")); log.info("snapshot: {}", snapshot); log.info("obj: {}", obj); + + DiffResult userDiffResult = User.Diff.diff(snapshot, obj); + log.info("userDiffResult: {}", userDiffResult); } } @@ -61,6 +67,19 @@ class User implements Serializable { private static final long serialVersionUID = 3549288698636099823L; Username username; Email email; + + static class Diff { + public static DiffResult diff(User left, User right) { + return DiffBuilder.builder() + .setLeft(left) + .setRight(right) + .setStyle(ToStringStyle.JSON_STYLE) + .build() + .append("username", left.username, right.username) + .append("email", left.email, right.email) + .build(); + } + } } @ValueObject