diff --git a/library/src/main/java/com/pengrad/telegrambot/request/SetMyName.java b/library/src/main/java/com/pengrad/telegrambot/request/SetMyName.java index f7ca690d..a1251dea 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/SetMyName.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/SetMyName.java @@ -11,7 +11,6 @@ public SetMyName() { /** * * @param name New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language. - * @return */ public SetMyName name(String name) { add("name", name); @@ -21,7 +20,6 @@ public SetMyName name(String name) { /** * * @param languageCode A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose language there is no dedicated name. - * @return */ public SetMyName languageCode(String languageCode) { add("language_code", languageCode); diff --git a/library/src/test/java/com/pengrad/telegrambot/RetryInterceptor.java b/library/src/test/java/com/pengrad/telegrambot/RetryInterceptor.java index f9e10d77..59483f4b 100644 --- a/library/src/test/java/com/pengrad/telegrambot/RetryInterceptor.java +++ b/library/src/test/java/com/pengrad/telegrambot/RetryInterceptor.java @@ -16,6 +16,7 @@ public class RetryInterceptor implements Interceptor { private final int defaultSleepMillis; private final Gson gson = new Gson(); + private boolean enabled = true; public RetryInterceptor() { this(1000); @@ -25,8 +26,13 @@ public RetryInterceptor(int defaultSleepMillis) { this.defaultSleepMillis = defaultSleepMillis; } + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + @Override public Response intercept(Chain chain) throws IOException { + if (!enabled) return chain.proceed(chain.request()); Request request = chain.request(); Exception exception = null; int retries = 3; diff --git a/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java b/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java index e7c3797c..d2ade137 100644 --- a/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java @@ -70,13 +70,14 @@ public static TelegramBot createTestBot() { .connectTimeout(75, TimeUnit.SECONDS) .writeTimeout(75, TimeUnit.SECONDS) .readTimeout(75, TimeUnit.SECONDS) - .addInterceptor(new RetryInterceptor(1000)); + .addInterceptor(retry); if (localBuild) { okHttpBuilder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)); } return new TelegramBot.Builder(token).okHttpClient(okHttpBuilder.build()).build(); } + static RetryInterceptor retry = new RetryInterceptor(1000); static TelegramBot bot = createTestBot(); static Long chatId; static Long groupId; @@ -2352,8 +2353,13 @@ public void setMyShortDescription() { @Test public void setMyName() { + retry.setEnabled(false); BaseResponse response = bot.execute(new SetMyName().name("name").languageCode("en")); - assertTrue(response.isOk()); + if (!response.isOk()) { + assertEquals(429, response.errorCode()); + assertTrue(response.description().startsWith("Too Many Requests: retry after")); + } + retry.setEnabled(true); GetMyNameResponse nameResponse = bot.execute(new GetMyName().languageCode("en")); assertTrue(nameResponse.isOk());