Skip to content

Commit

Permalink
Fix equals
Browse files Browse the repository at this point in the history
  • Loading branch information
pengrad committed Apr 7, 2024
1 parent cfaefca commit 977a08f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ public Integer year() {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Birthdate)) return false;
if (o == null || getClass() != o.getClass()) return false;
Birthdate birthdate = (Birthdate) o;
return Objects.equals(day, birthdate.day)
&& Objects.equals(month, birthdate.month)
&& Objects.equals(year, birthdate.year);
return Objects.equals(day, birthdate.day) && Objects.equals(month, birthdate.month) && Objects.equals(year, birthdate.year);
}

@Override
Expand All @@ -41,9 +39,9 @@ public int hashCode() {
@Override
public String toString() {
return "Birthday{" +
"day=" + day +
", month=" + month +
", year=" + year +
'}';
"day=" + day +
", month=" + month +
", year=" + year +
'}';
}
}
15 changes: 2 additions & 13 deletions library/src/main/java/com/pengrad/telegrambot/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,9 @@ public Boolean canConnectToBusiness() {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof User)) return false;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return Objects.equals(id, user.id)
&& Objects.equals(is_bot, user.is_bot)
&& Objects.equals(first_name, user.first_name)
&& Objects.equals(last_name, user.last_name)
&& Objects.equals(username, user.username)
&& Objects.equals(language_code, user.language_code)
&& Objects.equals(is_premium, user.is_premium)
&& Objects.equals(added_to_attachment_menu, user.added_to_attachment_menu)
&& Objects.equals(can_join_groups, user.can_join_groups)
&& Objects.equals(can_read_all_group_messages, user.can_read_all_group_messages)
&& Objects.equals(supports_inline_queries, user.supports_inline_queries)
&& Objects.equals(can_connect_to_business, user.can_connect_to_business);
return Objects.equals(id, user.id) && Objects.equals(is_bot, user.is_bot) && Objects.equals(first_name, user.first_name) && Objects.equals(last_name, user.last_name) && Objects.equals(username, user.username) && Objects.equals(language_code, user.language_code) && Objects.equals(is_premium, user.is_premium) && Objects.equals(added_to_attachment_menu, user.added_to_attachment_menu) && Objects.equals(can_join_groups, user.can_join_groups) && Objects.equals(can_read_all_group_messages, user.can_read_all_group_messages) && Objects.equals(supports_inline_queries, user.supports_inline_queries) && Objects.equals(can_connect_to_business, user.can_connect_to_business);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ public Integer[] userIds() {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof UsersShared)) return false;
if (o == null || getClass() != o.getClass()) return false;
UsersShared that = (UsersShared) o;
return Objects.equals(request_id, that.request_id)
&& Arrays.equals(user_ids, that.user_ids)
&& Arrays.equals(users, that.users);
return Objects.equals(request_id, that.request_id) && Arrays.equals(user_ids, that.user_ids) && Arrays.equals(users, that.users);
}

@Override
Expand All @@ -50,9 +48,9 @@ public int hashCode() {
@Override
public String toString() {
return "UsersShared{" +
"request_id=" + request_id +
", user_ids=" + Arrays.toString(user_ids) +
", users=" + Arrays.toString(users) +
'}';
"request_id=" + request_id +
", user_ids=" + Arrays.toString(user_ids) +
", users=" + Arrays.toString(users) +
'}';
}
}
6 changes: 6 additions & 0 deletions library/src/test/java/com/pengrad/telegrambot/ModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,18 @@ public void testEquals() throws ReflectiveOperationException {
f.setAccessible(true);
f.set(update, 1);

Chat chat = new Chat();
f = Chat.class.getDeclaredField("id");
f.setAccessible(true);
f.set(chat, 1L);

for (Class<?> c : classes) {
EqualsVerifierApi<?> verifierApi = EqualsVerifier.forClass(c)
.usingGetClass()
.withPrefabValues(Update.class, Update.class.getDeclaredConstructor().newInstance(), update)
.withPrefabValues(Message.class, Message.class.getDeclaredConstructor().newInstance(), message)
.withPrefabValues(CallbackQuery.class, CallbackQuery.class.getDeclaredConstructor().newInstance(), callbackQuery)
.withPrefabValues(Chat.class, new Chat(), chat)
.suppress(Warning.STRICT_HASHCODE)
.suppress(Warning.NONFINAL_FIELDS);

Expand Down

0 comments on commit 977a08f

Please sign in to comment.