Skip to content

Commit

Permalink
drop mockito-inline dependency (#1753)
Browse files Browse the repository at this point in the history
* drop dependency

* fix tests

* checkstyle

* clean-up
  • Loading branch information
wind57 authored Oct 5, 2024
1 parent ba5d26b commit 80974a0
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 57 deletions.
14 changes: 0 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
<surefire-reports-directory>surefire-reports</surefire-reports-directory>
<failsafe-reports-directory>failsafe-reports</failsafe-reports-directory>
<!-- Dependency Versions -->
<mockito-inline.version>4.8.1</mockito-inline.version>
<spring-cloud-commons.version>4.1.5-SNAPSHOT</spring-cloud-commons.version>
<spring-cloud-config.version>4.1.4-SNAPSHOT</spring-cloud-config.version>
<spring-cloud-bus.version>4.1.3-SNAPSHOT</spring-cloud-bus.version>
Expand Down Expand Up @@ -155,19 +154,6 @@
<scope>import</scope>
</dependency>

<!--Spring Boot 3.1 uses Mockito 5.x. Mockito 5.x has removed support for mockito-inline.-->
<!--https://github.com/mockito/mockito/issues/2877-->
<!--We need to support both Boot 3.0.x and Boot 3.1.x with Spring Cloud K8s 3.0.x-->
<!--To maintain compatibility we manage the version ourselves-->
<!-- TODO Remove this and all references to mockito-inline in the next minor -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-bom</artifactId>
<version>${mockito-inline.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-kubernetes-client-autoconfig/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-kubernetes-client-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-kubernetes-client-loadbalancer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-kubernetes-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!-- in favor of mockito-inline -->
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -49,7 +42,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!-- In favor of mockito-inline -->
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
Expand All @@ -68,7 +61,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
9 changes: 1 addition & 8 deletions spring-cloud-kubernetes-fabric8-autoconfig/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!-- in favor of mockito-inline -->
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -122,7 +115,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mockito;
import org.mockito.internal.util.MockUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
Expand Down Expand Up @@ -56,8 +59,20 @@ static void setup() {
@BeforeEach
void beforeEach() {
psl = propertySourceLocator;
verifiablePsl = spy(propertySourceLocator.getConfigMapPropertySourceLocator());
propertySourceLocator.setConfigMapPropertySourceLocator(verifiablePsl);
// latest Mockito does not allow to do something like Mockito.spy(spy)
// so this works around that
if (!MockUtil.isSpy(propertySourceLocator.getConfigMapPropertySourceLocator())) {
verifiablePsl = spy(propertySourceLocator.getConfigMapPropertySourceLocator());
propertySourceLocator.setConfigMapPropertySourceLocator(verifiablePsl);
}
else {
verifiablePsl = propertySourceLocator.getConfigMapPropertySourceLocator();
}
}

@AfterEach
void afterEach() {
Mockito.reset(verifiablePsl);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static void setup() {
private Fabric8SecretsPropertySourceLocator propertySourceLocator;

@BeforeEach
public void beforeEach() {
void beforeEach() {
psl = propertySourceLocator;
verifiablePsl = propertySourceLocator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mockito;
import org.mockito.internal.util.MockUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.kubernetes.commons.config.ConfigDataRetryableSecretsPropertySourceLocator;
Expand Down Expand Up @@ -49,10 +52,22 @@ static void setup() {
}

@BeforeEach
public void beforeEach() {
void beforeEach() {
psl = configDataRetryableSecretsPropertySourceLocator;
verifiablePsl = spy(configDataRetryableSecretsPropertySourceLocator.getSecretsPropertySourceLocator());
configDataRetryableSecretsPropertySourceLocator.setSecretsPropertySourceLocator(verifiablePsl);
// latest Mockito does not allow to do something like Mockito.spy(spy)
// so this works around that
if (!MockUtil.isSpy(configDataRetryableSecretsPropertySourceLocator.getSecretsPropertySourceLocator())) {
verifiablePsl = spy(configDataRetryableSecretsPropertySourceLocator.getSecretsPropertySourceLocator());
configDataRetryableSecretsPropertySourceLocator.setSecretsPropertySourceLocator(verifiablePsl);
}
else {
verifiablePsl = configDataRetryableSecretsPropertySourceLocator.getSecretsPropertySourceLocator();
}
}

@AfterEach
void afterEach() {
Mockito.reset(verifiablePsl);
}

}
9 changes: 1 addition & 8 deletions spring-cloud-kubernetes-fabric8-discovery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!-- in favor of mockito-inline -->
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-kubernetes-fabric8-loadbalancer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

Expand Down

0 comments on commit 80974a0

Please sign in to comment.