Skip to content

Commit 5665cc3

Browse files
authored
Merge pull request #3365 from hazendaz/pom-cleanup
tests: Cleanup equals
2 parents aaa5927 + 6712a8f commit 5665cc3

File tree

13 files changed

+26
-74
lines changed

13 files changed

+26
-74
lines changed

src/test/java/org/apache/ibatis/domain/blog/Author.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,8 @@ public boolean equals(Object o) {
106106
|| (password != null ? !password.equals(author.password) : author.password != null)) {
107107
return false;
108108
}
109-
if ((username != null ? !username.equals(author.username) : author.username != null) || (favouriteSection != null
110-
? !favouriteSection.equals(author.favouriteSection) : author.favouriteSection != null)) {
111-
return false;
112-
}
113-
114-
return true;
109+
return username != null ? username.equals(author.username) : author.username == null && favouriteSection != null
110+
? favouriteSection.equals(author.favouriteSection) : author.favouriteSection == null;
115111
}
116112

117113
@Override

src/test/java/org/apache/ibatis/domain/blog/ComplexImmutableAuthor.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,10 @@ public boolean equals(Object o) {
5252

5353
final ComplexImmutableAuthor that = (ComplexImmutableAuthor) o;
5454

55-
if ((bio != null ? !bio.equals(that.bio) : that.bio != null) || favouriteSection != that.favouriteSection
56-
|| (theComplexImmutableAuthorId != null ? !theComplexImmutableAuthorId.equals(that.theComplexImmutableAuthorId)
57-
: that.theComplexImmutableAuthorId != null)) {
58-
return false;
59-
}
60-
61-
return true;
55+
return bio != null ? bio.equals(that.bio)
56+
: that.bio == null && favouriteSection == that.favouriteSection && theComplexImmutableAuthorId != null
57+
? theComplexImmutableAuthorId.equals(that.theComplexImmutableAuthorId)
58+
: that.theComplexImmutableAuthorId == null;
6259
}
6360

6461
@Override

src/test/java/org/apache/ibatis/domain/blog/ComplexImmutableAuthorId.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,9 @@ public boolean equals(Object o) {
5555

5656
final ComplexImmutableAuthorId that = (ComplexImmutableAuthorId) o;
5757

58-
if (id != that.id || (email != null ? !email.equals(that.email) : that.email != null)
59-
|| (password != null ? !password.equals(that.password) : that.password != null)
60-
|| (username != null ? !username.equals(that.username) : that.username != null)) {
61-
return false;
62-
}
63-
64-
return true;
58+
return id == that.id && email != null ? email.equals(that.email)
59+
: that.email == null && password != null ? password.equals(that.password)
60+
: that.password == null && username != null ? username.equals(that.username) : that.username == null;
6561
}
6662

6763
@Override

src/test/java/org/apache/ibatis/domain/blog/ImmutableAuthor.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,8 @@ public boolean equals(Object o) {
7373
|| (password != null ? !password.equals(author.password) : author.password != null)) {
7474
return false;
7575
}
76-
if ((username != null ? !username.equals(author.username) : author.username != null) || (favouriteSection != null
77-
? !favouriteSection.equals(author.favouriteSection) : author.favouriteSection != null)) {
78-
return false;
79-
}
80-
81-
return true;
76+
return username != null ? username.equals(author.username) : author.username == null && favouriteSection != null
77+
? favouriteSection.equals(author.favouriteSection) : author.favouriteSection == null;
8278
}
8379

8480
@Override

src/test/java/org/apache/ibatis/domain/blog/PostLite.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ public boolean equals(Object o) {
5454

5555
final PostLite that = (PostLite) o;
5656

57-
if (blogId != that.blogId || (theId != null ? !theId.equals(that.theId) : that.theId != null)) {
58-
return false;
59-
}
60-
61-
return true;
57+
return blogId == that.blogId && theId != null ? theId.equals(that.theId) : that.theId == null;
6258
}
6359

6460
@Override

src/test/java/org/apache/ibatis/domain/blog/PostLiteId.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,11 +45,7 @@ public boolean equals(Object o) {
4545

4646
final PostLiteId that = (PostLiteId) o;
4747

48-
if (id != that.id) {
49-
return false;
50-
}
51-
52-
return true;
48+
return id == that.id;
5349
}
5450

5551
@Override

src/test/java/org/apache/ibatis/domain/misc/CustomBeanWrapperFactory.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,10 +23,7 @@
2323
public class CustomBeanWrapperFactory implements ObjectWrapperFactory {
2424
@Override
2525
public boolean hasWrapperFor(Object object) {
26-
if (object instanceof Author) {
27-
return true;
28-
}
29-
return false;
26+
return object instanceof Author;
3027
}
3128

3229
@Override

src/test/java/org/apache/ibatis/submitted/cglib_lazy_error/Person.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ public boolean equals(Object o) {
3838
return false;
3939
}
4040

41-
if (id != null ? !id.equals(person.id) : person.id != null) {
42-
return false;
43-
}
44-
45-
return true;
41+
return id != null ? id.equals(person.id) : person.id == null;
4642
}
4743

4844
@Override

src/test/java/org/apache/ibatis/submitted/constructor_columnprefix/EntityKey.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ public boolean equals(Object obj) {
4242
return false;
4343
}
4444
EntityKey other = (EntityKey) obj;
45-
if (!Objects.equals(id, other.id)) {
46-
return false;
47-
}
48-
return true;
45+
return Objects.equals(id, other.id);
4946
}
5047
}

src/test/java/org/apache/ibatis/submitted/extendresultmap/TestModel.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ public boolean equals(Object obj) {
6060
return false;
6161
}
6262
TestModel other = (TestModel) obj;
63-
if (!Objects.equals(a, other.a) || !Objects.equals(b, other.b)) {
64-
return false;
65-
}
66-
return true;
63+
return Objects.equals(a, other.a) && Objects.equals(b, other.b);
6764
}
6865

6966
@Override

src/test/java/org/apache/ibatis/submitted/foreach_map/IntBoolMapEntry.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ public boolean equals(Object o) {
5151

5252
IntBoolMapEntry mapEntry = (IntBoolMapEntry) o;
5353

54-
if ((key != null ? !key.equals(mapEntry.key) : mapEntry.key != null)
55-
|| (value != null ? !value.equals(mapEntry.value) : mapEntry.value != null)) {
56-
return false;
57-
}
58-
59-
return true;
54+
return key != null ? key.equals(mapEntry.key)
55+
: mapEntry.key == null && value == null ? value.equals(mapEntry.value) : mapEntry.value == null;
6056
}
6157

6258
@Override

src/test/java/org/apache/ibatis/submitted/foreach_map/NestedBeanMapEntry.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,8 @@ public boolean equals(Object o) {
7171

7272
NestedBeanMapEntry map3Entry = (NestedBeanMapEntry) o;
7373

74-
if (!Objects.equals(keya, map3Entry.keya) || !Objects.equals(keyb, map3Entry.keyb)
75-
|| !Objects.equals(valuea, map3Entry.valuea) || !Objects.equals(valueb, map3Entry.valueb)) {
76-
return false;
77-
}
78-
79-
return true;
74+
return Objects.equals(keya, map3Entry.keya) && Objects.equals(keyb, map3Entry.keyb)
75+
&& Objects.equals(valuea, map3Entry.valuea) && Objects.equals(valueb, map3Entry.valueb);
8076
}
8177

8278
@Override

src/test/java/org/apache/ibatis/submitted/foreach_map/StringStringMapEntry.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ public boolean equals(Object o) {
5151

5252
StringStringMapEntry mapEntry = (StringStringMapEntry) o;
5353

54-
if ((key != null ? !key.equals(mapEntry.key) : mapEntry.key != null)
55-
|| (value != null ? !value.equals(mapEntry.value) : mapEntry.value != null)) {
56-
return false;
57-
}
58-
59-
return true;
54+
return key != null ? key.equals(mapEntry.key)
55+
: mapEntry.key == null && value != null ? value.equals(mapEntry.value) : mapEntry.value == null;
6056
}
6157

6258
@Override
@@ -67,7 +63,7 @@ public int hashCode() {
6763

6864
@Override
6965
public String toString() {
70-
return '{' + key.toString() + '=' + value + '}';
66+
return '{' + key + '=' + value + '}';
7167
}
7268

7369
private String key;

0 commit comments

Comments
 (0)