Skip to content

Commit

Permalink
修复设置仅包含字段不生效的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dadiyang committed Jan 11, 2020
1 parent 74780c7 commit 760a6c9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
<dependency>
<groupId>com.github.dadiyang</groupId>
<artifactId>equator</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
```

或者下载 [equator-1.0.2.jar](https://github.com/dadiyang/equator/releases/download/v1.0.2/equator-1.0.2.jar) ,并添加到 classpath 下。
或者下载 [equator-1.0.3.jar](https://github.com/dadiyang/equator/releases/download/v1.0.3/equator-1.0.3.jar) ,并添加到 classpath 下。

## 调用方法

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.dadiyang</groupId>
<artifactId>equator</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<packaging>jar</packaging>
<parent>
<groupId>org.sonatype.oss</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@ protected boolean isFieldEquals(FieldInfo fieldInfo) {
if (isExclude(fieldInfo)) {
return true;
}
// 如果有指定需要包含的字段而且当前字段不在需要包含的字段中则不比对
if (!isInclude(fieldInfo)) {
return true;
}
// 如果有指定需要包含的字段
if (includeFields == null || includeFields.isEmpty() || !includeFields.contains(fieldInfo.getFieldName())) {
return nullableEquals(fieldInfo.getFirstVal(), fieldInfo.getSecondVal());
} else {
return true;
}
return nullableEquals(fieldInfo.getFirstVal(), fieldInfo.getSecondVal());
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/github/dadiyang/equator/EquatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public void getDiffFields() {
}
fields.sort(getStringComparator());
expectDiffField.sort(getStringComparator());
System.out.println(Arrays.toString(expectDiffField.toArray()) + " " + Arrays.toString(fields.toArray()));
assertArrayEquals("不等的属性与预期不一致", expectDiffField.toArray(), fields.toArray());
}

Expand Down
23 changes: 23 additions & 0 deletions src/test/java/com/github/dadiyang/equator/SimpleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.dadiyang.equator;

import org.junit.Test;

import java.util.Collections;
import java.util.Date;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class SimpleTest {
@Test
public void includeTest() {
Date now = new Date();
User user1 = new User(0, "noteq2", now, new String[]{"program", "coding"});
User user2 = new User(1, "yang", now, new String[]{"program2", "coding2"});
Equator equator = new GetterBaseEquator(Collections.singletonList("expireTime"), null);
List<FieldInfo> infos = equator.getDiffFields(user1, user2);
assertEquals(0, infos.size());
assertTrue(equator.isEquals(user1, user2));
}
}

0 comments on commit 760a6c9

Please sign in to comment.