Merge pull request #792 from costalfy/master

Upgrade Spring Boot dependency in telegrambots-spring-boot-starter
This commit is contained in:
Ruben Bermudez 2020-10-21 20:08:11 +01:00 committed by GitHub
commit f83e2b3ccb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 160 additions and 139 deletions

View File

@ -190,6 +190,7 @@
</executions> </executions>
<configuration> <configuration>
<doclint>none</doclint> <doclint>none</doclint>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -70,8 +70,21 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<telegrambots.version>4.9.1</telegrambots.version>
<spring-boot.version>2.3.3.RELEASE</spring-boot.version>
<assertj-core.version>3.14.0</assertj-core.version>
<spring-boot.version>2.2.2.RELEASE</spring-boot.version> <maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>
<maven-clean-plugin.version>3.1.0</maven-clean-plugin.version>
<maven-assembly-plugin.version>3.1.1</maven-assembly-plugin.version>
<maven-source-plugin.version>3.1.0</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.1.0</maven-javadoc-plugin.version>
<jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
<maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version>
<maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
<maven-surefire-plugin.version>3.0.0-M3</maven-surefire-plugin.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
</properties> </properties>
<dependencies> <dependencies>
@ -79,7 +92,7 @@
<dependency> <dependency>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId> <artifactId>telegrambots</artifactId>
<version>4.9.1</version> <version>${telegrambots.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -104,7 +117,7 @@
<groupId>org.assertj</groupId> <groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId> <artifactId>assertj-core</artifactId>
<scope>test</scope> <scope>test</scope>
<version>3.14.0</version> <version>${assertj-core.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
@ -118,7 +131,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId> <artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version> <version>${maven-gpg-plugin.version}</version>
<executions> <executions>
<execution> <execution>
<id>sign-artifacts</id> <id>sign-artifacts</id>
@ -132,7 +145,7 @@
<plugin> <plugin>
<groupId>org.sonatype.plugins</groupId> <groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId> <artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version> <version>${nexus-staging-maven-plugin.version}</version>
<extensions>true</extensions> <extensions>true</extensions>
<configuration> <configuration>
<serverId>ossrh</serverId> <serverId>ossrh</serverId>
@ -142,7 +155,7 @@
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-clean-plugin</artifactId> <artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version> <version>${maven-clean-plugin.version}</version>
<executions> <executions>
<execution> <execution>
<id>clean-project</id> <id>clean-project</id>
@ -155,7 +168,7 @@
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-assembly-plugin</artifactId> <artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version> <version>${maven-assembly-plugin.version}</version>
<configuration> <configuration>
<descriptorRefs> <descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef> <descriptorRef>jar-with-dependencies</descriptorRef>
@ -174,7 +187,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>3.1.0</version> <version>${maven-source-plugin.version}</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>
@ -186,7 +199,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.0</version> <version>${maven-javadoc-plugin.version}</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>
@ -201,7 +214,7 @@
<plugin> <plugin>
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version> <version>${jacoco-maven-plugin.version}</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>
@ -220,7 +233,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId> <artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version> <version>${maven-enforcer-plugin.version}</version>
<executions> <executions>
<execution> <execution>
<id>enforce-versions</id> <id>enforce-versions</id>
@ -238,7 +251,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId> <artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version> <version>${maven-dependency-plugin.version}</version>
<executions> <executions>
<execution> <execution>
<id>copy</id> <id>copy</id>
@ -249,7 +262,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <version>${maven-surefire-plugin.version}</version>
</plugin> </plugin>
</plugins> </plugins>
<pluginManagement> <pluginManagement>
@ -257,7 +270,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>${maven-compiler-plugin.version}</version>
<configuration> <configuration>
<source>${java.version}</source> <source>${java.version}</source>
<target>${java.version}</target> <target>${java.version}</target>

View File

@ -10,92 +10,96 @@ import org.telegram.telegrambots.meta.generics.LongPollingBot;
import org.telegram.telegrambots.meta.generics.WebhookBot; import org.telegram.telegrambots.meta.generics.WebhookBot;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
class TestTelegramBotStarterConfiguration { class TestTelegramBotStarterConfiguration {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class, TelegramBotStarterConfiguration.class)); .withAllowBeanDefinitionOverriding(true)
.withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class,
TelegramBotStarterConfiguration.class));
@Test @Test
void createMockTelegramBotsApiWithDefaultSettings() { void createMockTelegramBotsApiWithDefaultSettings() {
this.contextRunner.run((context) -> { this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(TelegramBotsApi.class); assertThat(context).hasSingleBean(TelegramBotsApi.class);
assertThat(context).hasSingleBean(TelegramBotInitializer.class); assertThat(context).hasSingleBean(TelegramBotInitializer.class);
assertThat(context).doesNotHaveBean(LongPollingBot.class); assertThat(context).doesNotHaveBean(LongPollingBot.class);
assertThat(context).doesNotHaveBean(WebhookBot.class); assertThat(context).doesNotHaveBean(WebhookBot.class);
verifyNoMoreInteractions(context.getBean(TelegramBotsApi.class)); verifyNoMoreInteractions(context.getBean(TelegramBotsApi.class));
}); });
} }
@Test @Test
void createOnlyLongPollingBot() { void createOnlyLongPollingBot() {
this.contextRunner.withUserConfiguration(LongPollingBotConfig.class) this.contextRunner.withUserConfiguration(LongPollingBotConfig.class)
.run((context) -> { .run((context) -> {
assertThat(context).hasSingleBean(LongPollingBot.class); assertThat(context).hasSingleBean(LongPollingBot.class);
assertThat(context).doesNotHaveBean(WebhookBot.class); assertThat(context).doesNotHaveBean(WebhookBot.class);
TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class);
verify(telegramBotsApi, times(1)).registerBot( context.getBean(LongPollingBot.class) ); verify(telegramBotsApi,
verifyNoMoreInteractions(telegramBotsApi); times(1)).registerBot(context.getBean(LongPollingBot.class));
}); verifyNoMoreInteractions(telegramBotsApi);
} });
}
@Test @Test
void createOnlyWebhookBot() { void createOnlyWebhookBot() {
this.contextRunner.withUserConfiguration(WebhookBotConfig.class) this.contextRunner.withUserConfiguration(WebhookBotConfig.class)
.run((context) -> { .run((context) -> {
assertThat(context).hasSingleBean(WebhookBot.class); assertThat(context).hasSingleBean(WebhookBot.class);
assertThat(context).doesNotHaveBean(LongPollingBot.class); assertThat(context).doesNotHaveBean(LongPollingBot.class);
TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class);
verify(telegramBotsApi, times(1)).registerBot( context.getBean(WebhookBot.class) ); verify(telegramBotsApi,
verifyNoMoreInteractions(telegramBotsApi); times(1)).registerBot(context.getBean(WebhookBot.class));
}); verifyNoMoreInteractions(telegramBotsApi);
} });
}
@Test @Test
void createLongPoolingBotAndWebhookBot() { void createLongPoolingBotAndWebhookBot() {
this.contextRunner.withUserConfiguration(LongPollingBotConfig.class, WebhookBotConfig.class) this.contextRunner.withUserConfiguration(LongPollingBotConfig.class,
.run((context) -> { WebhookBotConfig.class)
assertThat(context).hasSingleBean(LongPollingBot.class); .run((context) -> {
assertThat(context).hasSingleBean(WebhookBot.class); assertThat(context).hasSingleBean(LongPollingBot.class);
assertThat(context).hasSingleBean(WebhookBot.class);
TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class);
verify(telegramBotsApi, times(1)).registerBot( context.getBean(LongPollingBot.class) ); verify(telegramBotsApi,
verify(telegramBotsApi, times(1)).registerBot( context.getBean(WebhookBot.class) ); times(1)).registerBot(context.getBean(LongPollingBot.class));
//verifyNoMoreInteractions(telegramBotsApi); verify(telegramBotsApi,
}); times(1)).registerBot(context.getBean(WebhookBot.class));
} //verifyNoMoreInteractions(telegramBotsApi);
});
}
@Configuration @Configuration
static class MockTelegramBotsApi{ static class MockTelegramBotsApi {
@Bean @Bean
public TelegramBotsApi telegramBotsApi() { public TelegramBotsApi telegramBotsApi() {
return mock(TelegramBotsApi.class); return mock(TelegramBotsApi.class);
} }
} }
@Configuration @Configuration
static class LongPollingBotConfig{ static class LongPollingBotConfig {
@Bean @Bean
public LongPollingBot longPollingBot() { public LongPollingBot longPollingBot() {
return mock(LongPollingBot.class); return mock(LongPollingBot.class);
} }
} }
@Configuration @Configuration
static class WebhookBotConfig{ static class WebhookBotConfig {
@Bean @Bean
public WebhookBot webhookBot() { public WebhookBot webhookBot() {
return mock(WebhookBot.class); return mock(WebhookBot.class);
} }
} }
} }

View File

@ -14,27 +14,22 @@ import org.telegram.telegrambots.meta.generics.LongPollingBot;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession; import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.*;
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;
class TestTelegramBotStarterRegistrationHooks { class TestTelegramBotStarterRegistrationHooks {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() private static final DefaultBotSession someBotSession = new DefaultBotSession();
.withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class, TelegramBotStarterConfiguration.class)); private static final TelegramBotsApi mockTelegramBotsApi = mock(TelegramBotsApi.class);
// Terrible workaround for mockito loosing annotations on methods
// Terrible workaround for mockito loosing annotations on methods private static boolean hookCalled = false;
private static boolean hookCalled = false; private static boolean hookCalledWithSession = false;
private static boolean hookCalledWithSession = false; private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
private static final DefaultBotSession someBotSession = new DefaultBotSession(); .withAllowBeanDefinitionOverriding(true)
.withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class,
private static final TelegramBotsApi mockTelegramBotsApi = mock(TelegramBotsApi.class); TelegramBotStarterConfiguration.class));
@Test @Test
void longPollingBotWithAnnotatedMethodshouldBeCalled() throws TelegramApiRequestException { void longPollingBotWithAnnotatedMethodshouldBeCalled() throws TelegramApiRequestException {
when(mockTelegramBotsApi.registerBot(any(LongPollingBot.class))).thenReturn(someBotSession); when(mockTelegramBotsApi.registerBot(any(LongPollingBot.class))).thenReturn(someBotSession);
@ -45,48 +40,56 @@ class TestTelegramBotStarterRegistrationHooks {
final LongPollingBot bot = context.getBean(LongPollingBot.class); final LongPollingBot bot = context.getBean(LongPollingBot.class);
final TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class); final TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class);
assertThat(hookCalled).isTrue(); assertThat(hookCalled).isTrue();
assertThat(hookCalledWithSession).isTrue(); assertThat(hookCalledWithSession).isTrue();
verify(telegramBotsApi, times(1)).registerBot(bot); verify(telegramBotsApi,
verifyNoMoreInteractions(telegramBotsApi); times(1)).registerBot(bot);
verifyNoMoreInteractions(telegramBotsApi);
}); });
} }
@Configuration @Configuration
static class MockTelegramBotsApi{ static class MockTelegramBotsApi {
@Bean @Bean
public TelegramBotsApi telegramBotsApi() { public TelegramBotsApi telegramBotsApi() {
return mockTelegramBotsApi; return mockTelegramBotsApi;
} }
} }
@Configuration @Configuration
static class LongPollingBotConfig{ static class LongPollingBotConfig {
@Bean @Bean
public LongPollingBot longPollingBot() { return new AnnotatedLongPollingBot(); } public LongPollingBot longPollingBot() {
} return new AnnotatedLongPollingBot();
}
}
static class AnnotatedLongPollingBot extends TelegramLongPollingBot { static class AnnotatedLongPollingBot extends TelegramLongPollingBot {
@Override @Override
public void onUpdateReceived(final Update update) {} public void onUpdateReceived(final Update update) {
}
@Override @Override
public String getBotUsername() { return null; } public String getBotUsername() {
return null;
}
@Override @Override
public String getBotToken() { return null; } public String getBotToken() {
return null;
}
@AfterBotRegistration @AfterBotRegistration
public void afterBotHook() { public void afterBotHook() {
hookCalled = true; hookCalled = true;
} }
@AfterBotRegistration @AfterBotRegistration
public void afterBotHookWithSession(BotSession session) { public void afterBotHookWithSession(BotSession session) {
hookCalledWithSession = session.equals(someBotSession); hookCalledWithSession = session.equals(someBotSession);
} }
} }
} }