From b79911b45ff99d7fd7c366acb5714d417d82e3f0 Mon Sep 17 00:00:00 2001 From: Andy Costanza Date: Tue, 11 Aug 2020 12:17:33 +0200 Subject: [PATCH 1/3] fix(javadoc): add missing configuration to generate javadoc the error message before this fix was: Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.1.0:jar (default) on project telegrambots-meta: MavenReportException: Error while generating Javadoc: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set. --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 91026843..523f4dfd 100644 --- a/pom.xml +++ b/pom.xml @@ -190,6 +190,7 @@ none + ${java.home}/bin/javadoc From 3c5163990be84d425874dbe736fec0bc1830f806 Mon Sep 17 00:00:00 2001 From: Andy Costanza Date: Tue, 11 Aug 2020 12:29:35 +0200 Subject: [PATCH 2/3] feat(spring boot): Upgrade spring boot dependency to 2.3.2.RELEASE I'll fix UT too because in Spring Boot 2.3.X, ApplicationContextRunner disables bean overriding by default. To enable it, I set withAllowBeanDefinitionOverriding to true. https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#applicationcontextrunner-disables-bean-overriding-by-default for more informations --- telegrambots-spring-boot-starter/pom.xml | 41 +++-- .../TestTelegramBotStarterConfiguration.java | 166 +++++++++--------- ...stTelegramBotStarterRegistrationHooks.java | 91 +++++----- 3 files changed, 159 insertions(+), 139 deletions(-) diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index 7155c80e..46b5b2c2 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -70,8 +70,21 @@ UTF-8 UTF-8 + 4.9.1 + 2.3.2.RELEASE + 3.14.0 - 2.2.2.RELEASE + 1.6 + 1.6.8 + 3.1.0 + 3.1.1 + 3.1.0 + 3.1.0 + 0.8.4 + 3.0.0-M2 + 3.1.1 + 3.0.0-M3 + 3.8.1 @@ -79,7 +92,7 @@ org.telegram telegrambots - 4.9.1 + ${telegrambots.version} org.springframework.boot @@ -104,7 +117,7 @@ org.assertj assertj-core test - 3.14.0 + ${assertj-core.version} @@ -118,7 +131,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.6 + ${maven-gpg-plugin.version} sign-artifacts @@ -132,7 +145,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.8 + ${nexus-staging-maven-plugin.version} true ossrh @@ -142,7 +155,7 @@ maven-clean-plugin - 3.1.0 + ${maven-clean-plugin.version} clean-project @@ -155,7 +168,7 @@ maven-assembly-plugin - 3.1.1 + ${maven-assembly-plugin.version} jar-with-dependencies @@ -174,7 +187,7 @@ org.apache.maven.plugins maven-source-plugin - 3.1.0 + ${maven-source-plugin.version} @@ -186,7 +199,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.1.0 + ${maven-javadoc-plugin.version} @@ -201,7 +214,7 @@ org.jacoco jacoco-maven-plugin - 0.8.4 + ${jacoco-maven-plugin.version} @@ -220,7 +233,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.0.0-M2 + ${maven-enforcer-plugin.version} enforce-versions @@ -238,7 +251,7 @@ org.apache.maven.plugins maven-dependency-plugin - 3.1.1 + ${maven-dependency-plugin.version} copy @@ -249,7 +262,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M3 + ${maven-surefire-plugin.version} @@ -257,7 +270,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + ${maven-compiler-plugin.version} ${java.version} ${java.version} diff --git a/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterConfiguration.java b/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterConfiguration.java index 42a2d1cc..09cbec19 100644 --- a/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterConfiguration.java +++ b/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterConfiguration.java @@ -10,92 +10,96 @@ import org.telegram.telegrambots.meta.generics.LongPollingBot; import org.telegram.telegrambots.meta.generics.WebhookBot; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.*; class TestTelegramBotStarterConfiguration { - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class, TelegramBotStarterConfiguration.class)); + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withAllowBeanDefinitionOverriding(true) + .withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class, + TelegramBotStarterConfiguration.class)); - @Test - void createMockTelegramBotsApiWithDefaultSettings() { - this.contextRunner.run((context) -> { - assertThat(context).hasSingleBean(TelegramBotsApi.class); - assertThat(context).hasSingleBean(TelegramBotInitializer.class); - assertThat(context).doesNotHaveBean(LongPollingBot.class); - assertThat(context).doesNotHaveBean(WebhookBot.class); - verifyNoMoreInteractions(context.getBean(TelegramBotsApi.class)); - }); - } - - @Test - void createOnlyLongPollingBot() { - this.contextRunner.withUserConfiguration(LongPollingBotConfig.class) - .run((context) -> { - assertThat(context).hasSingleBean(LongPollingBot.class); - assertThat(context).doesNotHaveBean(WebhookBot.class); - - TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); - - verify(telegramBotsApi, times(1)).registerBot( context.getBean(LongPollingBot.class) ); - verifyNoMoreInteractions(telegramBotsApi); - }); - } - - @Test - void createOnlyWebhookBot() { - this.contextRunner.withUserConfiguration(WebhookBotConfig.class) - .run((context) -> { - assertThat(context).hasSingleBean(WebhookBot.class); - assertThat(context).doesNotHaveBean(LongPollingBot.class); - - TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); - - verify(telegramBotsApi, times(1)).registerBot( context.getBean(WebhookBot.class) ); - verifyNoMoreInteractions(telegramBotsApi); - }); - } - - @Test - void createLongPoolingBotAndWebhookBot() { - this.contextRunner.withUserConfiguration(LongPollingBotConfig.class, WebhookBotConfig.class) - .run((context) -> { - assertThat(context).hasSingleBean(LongPollingBot.class); - assertThat(context).hasSingleBean(WebhookBot.class); + @Test + void createMockTelegramBotsApiWithDefaultSettings() { + this.contextRunner.run((context) -> { + assertThat(context).hasSingleBean(TelegramBotsApi.class); + assertThat(context).hasSingleBean(TelegramBotInitializer.class); + assertThat(context).doesNotHaveBean(LongPollingBot.class); + assertThat(context).doesNotHaveBean(WebhookBot.class); + verifyNoMoreInteractions(context.getBean(TelegramBotsApi.class)); + }); + } - TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); - - verify(telegramBotsApi, times(1)).registerBot( context.getBean(LongPollingBot.class) ); - verify(telegramBotsApi, times(1)).registerBot( context.getBean(WebhookBot.class) ); - //verifyNoMoreInteractions(telegramBotsApi); - }); - } + @Test + void createOnlyLongPollingBot() { + this.contextRunner.withUserConfiguration(LongPollingBotConfig.class) + .run((context) -> { + assertThat(context).hasSingleBean(LongPollingBot.class); + assertThat(context).doesNotHaveBean(WebhookBot.class); - @Configuration - static class MockTelegramBotsApi{ + TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); - @Bean - public TelegramBotsApi telegramBotsApi() { - return mock(TelegramBotsApi.class); - } - } - - @Configuration - static class LongPollingBotConfig{ - @Bean - public LongPollingBot longPollingBot() { - return mock(LongPollingBot.class); - } - } - - @Configuration - static class WebhookBotConfig{ - @Bean - public WebhookBot webhookBot() { - return mock(WebhookBot.class); - } - } + verify(telegramBotsApi, + times(1)).registerBot(context.getBean(LongPollingBot.class)); + verifyNoMoreInteractions(telegramBotsApi); + }); + } + + @Test + void createOnlyWebhookBot() { + this.contextRunner.withUserConfiguration(WebhookBotConfig.class) + .run((context) -> { + assertThat(context).hasSingleBean(WebhookBot.class); + assertThat(context).doesNotHaveBean(LongPollingBot.class); + + TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); + + verify(telegramBotsApi, + times(1)).registerBot(context.getBean(WebhookBot.class)); + verifyNoMoreInteractions(telegramBotsApi); + }); + } + + @Test + void createLongPoolingBotAndWebhookBot() { + this.contextRunner.withUserConfiguration(LongPollingBotConfig.class, + WebhookBotConfig.class) + .run((context) -> { + assertThat(context).hasSingleBean(LongPollingBot.class); + assertThat(context).hasSingleBean(WebhookBot.class); + + TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); + + verify(telegramBotsApi, + times(1)).registerBot(context.getBean(LongPollingBot.class)); + verify(telegramBotsApi, + times(1)).registerBot(context.getBean(WebhookBot.class)); + //verifyNoMoreInteractions(telegramBotsApi); + }); + } + + @Configuration + static class MockTelegramBotsApi { + + @Bean + public TelegramBotsApi telegramBotsApi() { + return mock(TelegramBotsApi.class); + } + } + + @Configuration + static class LongPollingBotConfig { + @Bean + public LongPollingBot longPollingBot() { + return mock(LongPollingBot.class); + } + } + + @Configuration + static class WebhookBotConfig { + @Bean + public WebhookBot webhookBot() { + return mock(WebhookBot.class); + } + } } diff --git a/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java b/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java index 2f108d81..1764c4ad 100644 --- a/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java +++ b/telegrambots-spring-boot-starter/src/test/java/org/telegram/telegrambots/starter/TestTelegramBotStarterRegistrationHooks.java @@ -14,27 +14,22 @@ import org.telegram.telegrambots.meta.generics.LongPollingBot; import org.telegram.telegrambots.updatesreceivers.DefaultBotSession; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; class TestTelegramBotStarterRegistrationHooks { - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class, TelegramBotStarterConfiguration.class)); - - // Terrible workaround for mockito loosing annotations on methods - private static boolean hookCalled = false; - private static boolean hookCalledWithSession = false; - private static final DefaultBotSession someBotSession = new DefaultBotSession(); - - private static final TelegramBotsApi mockTelegramBotsApi = mock(TelegramBotsApi.class); + private static final DefaultBotSession someBotSession = new DefaultBotSession(); + private static final TelegramBotsApi mockTelegramBotsApi = mock(TelegramBotsApi.class); + // Terrible workaround for mockito loosing annotations on methods + private static boolean hookCalled = false; + private static boolean hookCalledWithSession = false; + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withAllowBeanDefinitionOverriding(true) + .withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class, + TelegramBotStarterConfiguration.class)); @Test - void longPollingBotWithAnnotatedMethodshouldBeCalled() throws TelegramApiRequestException { + void longPollingBotWithAnnotatedMethodshouldBeCalled() throws TelegramApiRequestException { when(mockTelegramBotsApi.registerBot(any(LongPollingBot.class))).thenReturn(someBotSession); @@ -45,48 +40,56 @@ class TestTelegramBotStarterRegistrationHooks { final LongPollingBot bot = context.getBean(LongPollingBot.class); final TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); - assertThat(hookCalled).isTrue(); - assertThat(hookCalledWithSession).isTrue(); - verify(telegramBotsApi, times(1)).registerBot(bot); - verifyNoMoreInteractions(telegramBotsApi); + assertThat(hookCalled).isTrue(); + assertThat(hookCalledWithSession).isTrue(); + verify(telegramBotsApi, + times(1)).registerBot(bot); + verifyNoMoreInteractions(telegramBotsApi); }); } - @Configuration - static class MockTelegramBotsApi{ + @Configuration + static class MockTelegramBotsApi { - @Bean - public TelegramBotsApi telegramBotsApi() { - return mockTelegramBotsApi; - } - } - - @Configuration - static class LongPollingBotConfig{ - @Bean - public LongPollingBot longPollingBot() { return new AnnotatedLongPollingBot(); } - } + @Bean + public TelegramBotsApi telegramBotsApi() { + return mockTelegramBotsApi; + } + } - static class AnnotatedLongPollingBot extends TelegramLongPollingBot { + @Configuration + static class LongPollingBotConfig { + @Bean + public LongPollingBot longPollingBot() { + return new AnnotatedLongPollingBot(); + } + } - @Override - public void onUpdateReceived(final Update update) {} + static class AnnotatedLongPollingBot extends TelegramLongPollingBot { - @Override - public String getBotUsername() { return null; } + @Override + public void onUpdateReceived(final Update update) { + } - @Override - public String getBotToken() { return null; } + @Override + public String getBotUsername() { + return null; + } - @AfterBotRegistration - public void afterBotHook() { + @Override + public String getBotToken() { + return null; + } + + @AfterBotRegistration + public void afterBotHook() { hookCalled = true; } @AfterBotRegistration - public void afterBotHookWithSession(BotSession session) { + public void afterBotHookWithSession(BotSession session) { hookCalledWithSession = session.equals(someBotSession); } - } + } } From f3626b7bf155642b036dc0858b1b1896abaabcde Mon Sep 17 00:00:00 2001 From: Andy Costanza Date: Tue, 25 Aug 2020 17:25:36 +0200 Subject: [PATCH 3/3] feat(spring boot): Upgrade spring boot dependency to 2.3.3.RELEASE --- telegrambots-spring-boot-starter/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegrambots-spring-boot-starter/pom.xml b/telegrambots-spring-boot-starter/pom.xml index 46b5b2c2..90b989ab 100644 --- a/telegrambots-spring-boot-starter/pom.xml +++ b/telegrambots-spring-boot-starter/pom.xml @@ -71,7 +71,7 @@ UTF-8 4.9.1 - 2.3.2.RELEASE + 2.3.3.RELEASE 3.14.0 1.6