optimize: redesign table diff method (#227)

This commit is contained in:
vran
2022-06-07 22:38:09 +08:00
committed by GitHub
parent ebfe669a01
commit 1dc0e10210
25 changed files with 1048 additions and 607 deletions

View File

@@ -0,0 +1,94 @@
package com.databasir.core.domain.document.diff;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class BaseTypeFieldEqualFunctionTest {
@Test
public void testApplyAllNull() {
BaseTypeFieldEqualFunction equalFunction = new BaseTypeFieldEqualFunction(List.of());
// Setup
final Object that = null;
final Object other = null;
// Run the test
final Boolean result = equalFunction.apply(that, other);
// Verify the results
assertTrue(result);
}
@Test
public void testApplySimpleObject() {
SimpleObject that = SimpleObject.builder()
.id(1)
.height(180L)
.name("test")
.build();
SimpleObject other = SimpleObject.builder()
.id(1)
.height(180L)
.name("test")
.build();
BaseTypeFieldEqualFunction equalFunction = new BaseTypeFieldEqualFunction(List.of());
final Boolean result = equalFunction.apply(that, other);
assertTrue(result);
}
@Test
public void testApplyComplexObject() {
SimpleObject thatItem = SimpleObject.builder()
.id(1)
.height(180L)
.name("test")
.build();
ComplexObject thatObj = new ComplexObject();
thatObj.setId(1);
thatObj.setName("eq");
thatObj.setItems(List.of(thatItem));
SimpleObject otherItem = SimpleObject.builder()
.id(1)
.height(180L)
.name("test")
.build();
ComplexObject otherObj = new ComplexObject();
otherObj.setId(1);
otherObj.setName("eq");
otherObj.setItems(List.of(otherItem));
BaseTypeFieldEqualFunction equalFunction = new BaseTypeFieldEqualFunction(List.of());
final Boolean result = equalFunction.apply(thatObj, otherObj);
assertTrue(result);
}
@Test
public void testApplyComplexObject2() {
SimpleObject thatItem = SimpleObject.builder()
.id(1)
.height(180L)
.name("test")
.build();
ComplexObject thatObj = new ComplexObject();
thatObj.setId(1);
thatObj.setName("eq");
thatObj.setItems(List.of(thatItem));
ComplexObject otherObj = new ComplexObject();
otherObj.setId(1);
otherObj.setName("eq");
otherObj.setItems(List.of());
BaseTypeFieldEqualFunction equalFunction = new BaseTypeFieldEqualFunction(List.of());
final Boolean result = equalFunction.apply(thatObj, otherObj);
assertFalse(result);
}
}

View File

@@ -0,0 +1,17 @@
package com.databasir.core.domain.document.diff;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class ComplexObject {
private Integer id;
private String name;
private List<SimpleObject> items = new ArrayList<>();
}

View File

@@ -0,0 +1,16 @@
package com.databasir.core.domain.document.diff;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class SimpleObject {
private Integer id;
private Long height;
private String name;
}