Merge pull request #528 from d35h/master

Add addAll method for keyboardrow class
This commit is contained in:
Ruben Bermudez 2018-10-31 20:14:34 +00:00 committed by GitHub
commit bdc8db3c87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View File

@ -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<KeyboardButton> implements Validable
super.add(index, new KeyboardButton(text));
}
public void addAll(List<String> buttonNames) {
buttonNames.forEach(name -> super.add(new KeyboardButton(name)));
}
public boolean contains(String text) {
return super.contains(new KeyboardButton(text));
}

View File

@ -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<String> 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<String>());
assertTrue(keyboardRow.isEmpty());
}
}