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
This commit is contained in:
Andy Costanza 2020-08-11 12:29:35 +02:00
parent b79911b45f
commit 3c5163990b
3 changed files with 159 additions and 139 deletions

View File

@ -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.2.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>

View File

@ -10,15 +10,14 @@ 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));
.withAllowBeanDefinitionOverriding(true)
.withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class,
TelegramBotStarterConfiguration.class));
@Test
void createMockTelegramBotsApiWithDefaultSettings() {
@ -40,7 +39,8 @@ class TestTelegramBotStarterConfiguration {
TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class);
verify(telegramBotsApi, times(1)).registerBot( context.getBean(LongPollingBot.class) );
verify(telegramBotsApi,
times(1)).registerBot(context.getBean(LongPollingBot.class));
verifyNoMoreInteractions(telegramBotsApi);
});
}
@ -54,22 +54,26 @@ class TestTelegramBotStarterConfiguration {
TelegramBotsApi telegramBotsApi = context.getBean(TelegramBotsApi.class);
verify(telegramBotsApi, times(1)).registerBot( context.getBean(WebhookBot.class) );
verify(telegramBotsApi,
times(1)).registerBot(context.getBean(WebhookBot.class));
verifyNoMoreInteractions(telegramBotsApi);
});
}
@Test
void createLongPoolingBotAndWebhookBot() {
this.contextRunner.withUserConfiguration(LongPollingBotConfig.class, WebhookBotConfig.class)
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) );
verify(telegramBotsApi,
times(1)).registerBot(context.getBean(LongPollingBot.class));
verify(telegramBotsApi,
times(1)).registerBot(context.getBean(WebhookBot.class));
//verifyNoMoreInteractions(telegramBotsApi);
});
}

View File

@ -14,24 +14,19 @@ 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));
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 static final DefaultBotSession someBotSession = new DefaultBotSession();
private static final TelegramBotsApi mockTelegramBotsApi = mock(TelegramBotsApi.class);
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withAllowBeanDefinitionOverriding(true)
.withConfiguration(AutoConfigurations.of(MockTelegramBotsApi.class,
TelegramBotStarterConfiguration.class));
@Test
void longPollingBotWithAnnotatedMethodshouldBeCalled() throws TelegramApiRequestException {
@ -47,7 +42,8 @@ class TestTelegramBotStarterRegistrationHooks {
assertThat(hookCalled).isTrue();
assertThat(hookCalledWithSession).isTrue();
verify(telegramBotsApi, times(1)).registerBot(bot);
verify(telegramBotsApi,
times(1)).registerBot(bot);
verifyNoMoreInteractions(telegramBotsApi);
});
}
@ -65,19 +61,26 @@ class TestTelegramBotStarterRegistrationHooks {
@Configuration
static class LongPollingBotConfig {
@Bean
public LongPollingBot longPollingBot() { return new AnnotatedLongPollingBot(); }
public LongPollingBot longPollingBot() {
return new AnnotatedLongPollingBot();
}
}
static class AnnotatedLongPollingBot extends TelegramLongPollingBot {
@Override
public void onUpdateReceived(final Update update) {}
public void onUpdateReceived(final Update update) {
}
@Override
public String getBotUsername() { return null; }
public String getBotUsername() {
return null;
}
@Override
public String getBotToken() { return null; }
public String getBotToken() {
return null;
}
@AfterBotRegistration
public void afterBotHook() {