#325 Implement equals() and hashCode() in SendMessage
This commit is contained in:
parent
49c0fef3c5
commit
4121a6f8c9
@ -187,6 +187,35 @@ public class SendMessage extends BotApiMethod<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof SendMessage)) {
|
||||
return false;
|
||||
}
|
||||
SendMessage sendMessage = (SendMessage) o;
|
||||
return Objects.equals(chatId, sendMessage.chatId)
|
||||
&& Objects.equals(disableNotification, sendMessage.disableNotification)
|
||||
&& Objects.equals(disableWebPagePreview, sendMessage.disableWebPagePreview)
|
||||
&& Objects.equals(parseMode, sendMessage.parseMode)
|
||||
&& Objects.equals(replyMarkup, sendMessage.replyMarkup)
|
||||
&& Objects.equals(replyToMessageId, sendMessage.replyToMessageId)
|
||||
&& Objects.equals(text, sendMessage.text)
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(
|
||||
chatId,
|
||||
disableNotification,
|
||||
disableWebPagePreview,
|
||||
parseMode,
|
||||
replyMarkup,
|
||||
replyToMessageId,
|
||||
text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SendMessage{" +
|
||||
|
@ -0,0 +1,25 @@
|
||||
package org.telegram.telegrambots.api.methods.send;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SendMessageTest {
|
||||
|
||||
@Test
|
||||
public void comparison() throws Exception {
|
||||
SendMessage sm1 = new SendMessage().setChatId(1L).setText("Hello World");
|
||||
SendMessage sm2 = new SendMessage().setChatId(1L).setText("Hello World");
|
||||
SendMessage noMessage = new SendMessage().setChatId(1L);
|
||||
SendMessage disabledNotification = new SendMessage().setChatId(1L).setText("Hello World").disableNotification();
|
||||
|
||||
assertTrue(sm1.equals(sm2));
|
||||
assertFalse(sm1.equals(noMessage));
|
||||
assertFalse(sm1.equals(disabledNotification));
|
||||
|
||||
assertTrue(sm1.hashCode() == sm2.hashCode());
|
||||
assertFalse(sm1.hashCode() == noMessage.hashCode());
|
||||
assertFalse(sm1.hashCode() == disabledNotification.hashCode());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user