|
| 1 | +package org.telegram.telegrambots.meta.api.methods.managed; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; |
| 5 | + |
| 6 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 9 | + |
| 10 | +/** |
| 11 | + * @author Ruben Bermudez |
| 12 | + * @version 10.0 |
| 13 | + */ |
| 14 | +public class TestSetManagedBotAccessSettings { |
| 15 | + |
| 16 | + @Test |
| 17 | + public void testSetManagedBotAccessSettingsGetPath() { |
| 18 | + SetManagedBotAccessSettings method = SetManagedBotAccessSettings.builder() |
| 19 | + .userId(123456789L) |
| 20 | + .isAccessRestricted(false) |
| 21 | + .build(); |
| 22 | + |
| 23 | + assertEquals("setManagedBotAccessSettings", method.getMethod()); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + public void testSetManagedBotAccessSettingsValidation() { |
| 28 | + SetManagedBotAccessSettings method = SetManagedBotAccessSettings.builder() |
| 29 | + .userId(123456789L) |
| 30 | + .isAccessRestricted(false) |
| 31 | + .build(); |
| 32 | + |
| 33 | + assertDoesNotThrow(method::validate); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testSetManagedBotAccessSettingsMissingUserId() { |
| 38 | + assertThrows(NullPointerException.class, () -> SetManagedBotAccessSettings.builder() |
| 39 | + .isAccessRestricted(false) |
| 40 | + .build()); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testSetManagedBotAccessSettingsMissingIsAccessRestricted() { |
| 45 | + assertThrows(NullPointerException.class, () -> SetManagedBotAccessSettings.builder() |
| 46 | + .userId(123456789L) |
| 47 | + .build()); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testSetManagedBotAccessSettingsZeroUserId() { |
| 52 | + SetManagedBotAccessSettings method = SetManagedBotAccessSettings.builder() |
| 53 | + .userId(0L) |
| 54 | + .isAccessRestricted(false) |
| 55 | + .build(); |
| 56 | + |
| 57 | + assertThrows(TelegramApiValidationException.class, method::validate); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testSetManagedBotAccessSettingsWithAddedUserIds() { |
| 62 | + SetManagedBotAccessSettings method = SetManagedBotAccessSettings.builder() |
| 63 | + .userId(123456789L) |
| 64 | + .isAccessRestricted(true) |
| 65 | + .addedUserId(111L) |
| 66 | + .addedUserId(222L) |
| 67 | + .build(); |
| 68 | + |
| 69 | + assertDoesNotThrow(method::validate); |
| 70 | + assertEquals(2, method.getAddedUserIds().size()); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void testSetManagedBotAccessSettingsTooManyAddedUserIds() { |
| 75 | + SetManagedBotAccessSettings.SetManagedBotAccessSettingsBuilder<?, ?> builder = SetManagedBotAccessSettings.builder() |
| 76 | + .userId(123456789L) |
| 77 | + .isAccessRestricted(true); |
| 78 | + |
| 79 | + for (int i = 1; i <= 11; i++) { |
| 80 | + builder.addedUserId((long) i); |
| 81 | + } |
| 82 | + SetManagedBotAccessSettings method = builder.build(); |
| 83 | + |
| 84 | + assertThrows(TelegramApiValidationException.class, method::validate); |
| 85 | + } |
| 86 | +} |
0 commit comments