Merge pull request #792 from costalfy/master
Upgrade Spring Boot dependency in telegrambots-spring-boot-starter
This commit is contained in:
commit
f83e2b3ccb
1
pom.xml
1
pom.xml
@ -190,6 +190,7 @@
|
||||
</executions>
|
||||
<configuration>
|
||||
<doclint>none</doclint>
|
||||
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -70,8 +70,21 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<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>
|
||||
|
||||
<dependencies>
|
||||
@ -79,7 +92,7 @@
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>4.9.1</version>
|
||||
<version>${telegrambots.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -104,7 +117,7 @@
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>3.14.0</version>
|
||||
<version>${assertj-core.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@ -118,7 +131,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<version>${maven-gpg-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
@ -132,7 +145,7 @@
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>1.6.8</version>
|
||||
<version>${nexus-staging-maven-plugin.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<serverId>ossrh</serverId>
|
||||
@ -142,7 +155,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>${maven-clean-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>clean-project</id>
|
||||
@ -155,7 +168,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>${maven-assembly-plugin.version}</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
@ -174,7 +187,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>${maven-source-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -186,7 +199,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>${maven-javadoc-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -201,7 +214,7 @@
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.4</version>
|
||||
<version>${jacoco-maven-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -220,7 +233,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0-M2</version>
|
||||
<version>${maven-enforcer-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-versions</id>
|
||||
@ -238,7 +251,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>${maven-dependency-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
@ -249,7 +262,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M3</version>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
@ -257,7 +270,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user