From 4efaa253b8048ef987c1462cdaeee0c5a5970120 Mon Sep 17 00:00:00 2001 From: d35h Date: Sun, 14 Oct 2018 21:45:49 +0200 Subject: [PATCH 1/2] Add addAll method for keyboardrow --- .../meta/api/objects/replykeyboard/buttons/KeyboardRow.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java index 571e19d6..3381a09b 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java @@ -4,6 +4,7 @@ import org.telegram.telegrambots.meta.api.interfaces.Validable; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import java.util.ArrayList; +import java.util.List; /** * @author Ruben Bermudez @@ -20,6 +21,10 @@ public class KeyboardRow extends ArrayList implements Validable super.add(index, new KeyboardButton(text)); } + public void addAll(List buttonNames) { + buttonNames.forEach(KeyboardButton::new); + } + public boolean contains(String text) { return super.contains(new KeyboardButton(text)); } From dc62f9ce63b04ac9ad374d451a45ad6901eeae38 Mon Sep 17 00:00:00 2001 From: d35h Date: Sun, 14 Oct 2018 22:11:04 +0200 Subject: [PATCH 2/2] Add tests --- .../replykeyboard/buttons/KeyboardRow.java | 2 +- .../buttons/KeyboardRowTest.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java index 3381a09b..b1b76ecb 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRow.java @@ -22,7 +22,7 @@ public class KeyboardRow extends ArrayList implements Validable } public void addAll(List buttonNames) { - buttonNames.forEach(KeyboardButton::new); + buttonNames.forEach(name -> super.add(new KeyboardButton(name))); } public boolean contains(String text) { diff --git a/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java new file mode 100644 index 00000000..3e4f87f6 --- /dev/null +++ b/telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/api/objects/replykeyboard/buttons/KeyboardRowTest.java @@ -0,0 +1,34 @@ +package org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static java.util.Arrays.asList; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +public class KeyboardRowTest { + + private static final List BUTTON_NAMES = asList("Carlotta Valdes", "Jimmy Stewart"); + + @Test + public void shouldAddAllButtons() { + final KeyboardRow keyboardRow = new KeyboardRow(); + keyboardRow.addAll(BUTTON_NAMES); + assertThat(keyboardRow.size(), is(2)); + assertThat(keyboardRow.get(0).getText(), is("Carlotta Valdes")); + assertThat(keyboardRow.get(1).getText(), is("Jimmy Stewart")); + } + + @Test + public void shouldAddNoButtons() { + final KeyboardRow keyboardRow = new KeyboardRow(); + keyboardRow.addAll(new ArrayList()); + assertTrue(keyboardRow.isEmpty()); + } + +}