JAVA-33535: Fix errors after mockito upgrade. (#16389)

* Fix eureka-client

* Fix eureka-server

* Fix spring-cloud-zuul

* Fix spring-reactive-data-couchbase

* Fix and cleanup apache-poi
This commit is contained in:
Harry9656 2024-04-13 23:54:45 +02:00 committed by GitHub
parent 4d6b46699c
commit f18a5c4472
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 47 additions and 14 deletions

View File

@ -14,14 +14,16 @@ import org.springframework.stereotype.Component;
matchIfMissing = true) matchIfMissing = true)
@Component @Component
public class ApplicationRunnerTaskExecutor implements ApplicationRunner { public class ApplicationRunnerTaskExecutor implements ApplicationRunner {
private TaskService taskService;
private final TaskService taskService;
public ApplicationRunnerTaskExecutor(TaskService taskService) { public ApplicationRunnerTaskExecutor(TaskService taskService) {
this.taskService = taskService; this.taskService = taskService;
} }
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) {
taskService.execute("application runner task"); taskService.execute("application runner task");
} }
} }

View File

@ -13,14 +13,14 @@ import org.springframework.stereotype.Component;
matchIfMissing = true) matchIfMissing = true)
@Component @Component
public class CommandLineTaskExecutor implements CommandLineRunner { public class CommandLineTaskExecutor implements CommandLineRunner {
private TaskService taskService; private final TaskService taskService;
public CommandLineTaskExecutor(TaskService taskService) { public CommandLineTaskExecutor(TaskService taskService) {
this.taskService = taskService; this.taskService = taskService;
} }
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) {
taskService.execute("command line runner task"); taskService.execute("command line runner task");
} }
} }

View File

@ -6,9 +6,9 @@ import org.springframework.stereotype.Service;
@Service @Service
public class TaskService { public class TaskService {
private static Logger logger = LoggerFactory.getLogger(TaskService.class); private static final Logger logger = LoggerFactory.getLogger(TaskService.class);
public void execute(String task) { public void execute(String task) {
logger.info("do " + task); logger.info("do {}", task);
} }
} }

View File

@ -1,16 +1,13 @@
package com.baeldung.prevent.commandline.application.runner.execution; package com.baeldung.prevent.commandline.application.runner.execution;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import com.baeldung.prevent.commandline.application.runner.execution.ApplicationRunnerTaskExecutor;
import com.baeldung.prevent.commandline.application.runner.execution.CommandLineTaskExecutor;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
@SpringBootTest @SpringBootTest
class RunApplicationIntegrationTest { class RunApplicationIntegrationTest {
@SpyBean @SpyBean
@ -21,6 +18,6 @@ class RunApplicationIntegrationTest {
@Test @Test
void whenContextLoads_thenRunnersRun() throws Exception { void whenContextLoads_thenRunnersRun() throws Exception {
verify(applicationRunnerTaskExecutor, times(1)).run(any()); verify(applicationRunnerTaskExecutor, times(1)).run(any());
verify(commandLineTaskExecutor, times(1)).run(any()); verify(commandLineTaskExecutor, times(1)).run(any(String[].class));
} }
} }

View File

@ -44,8 +44,18 @@
<version>${spring-boot.version}</version> <version>${spring-boot.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<properties>
<byte-buddy.version>1.14.13</byte-buddy.version>
</properties>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

View File

@ -44,8 +44,18 @@
<version>${spring-boot.version}</version> <version>${spring-boot.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<properties>
<byte-buddy.version>1.14.13</byte-buddy.version>
</properties>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

View File

@ -60,6 +60,12 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -82,6 +88,7 @@
<properties> <properties>
<spring-cloud-dependencies.version>2021.0.3</spring-cloud-dependencies.version> <spring-cloud-dependencies.version>2021.0.3</spring-cloud-dependencies.version>
<spring-cloud-netflix-zuul.version>2.2.7.RELEASE</spring-cloud-netflix-zuul.version> <spring-cloud-netflix-zuul.version>2.2.7.RELEASE</spring-cloud-netflix-zuul.version>
<byte-buddy.version>1.14.13</byte-buddy.version>
</properties> </properties>
</project> </project>

View File

@ -65,6 +65,12 @@
<version>${couchbaseMock.version}</version> <version>${couchbaseMock.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -129,6 +135,7 @@
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>11</maven.compiler.target>
<java.version>11</java.version> <java.version>11</java.version>
<byte-buddy.version>1.14.13</byte-buddy.version>
</properties> </properties>
</project> </project>