This is an automated email from the ASF dual-hosted git repository.

shoothzj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new 870dbdc41 migrate generator-core to mockito (#3424)
870dbdc41 is described below

commit 870dbdc415ea0a9d2fc404defe27af08128ebfcb
Author: Tian Luo <[email protected]>
AuthorDate: Sun Oct 23 18:47:32 2022 +0800

    migrate generator-core to mockito (#3424)
---
 swagger/swagger-generator/generator-core/pom.xml   |  6 +--
 .../servicecomb/swagger/TestSwaggerUtils.java      | 52 +++++++++-------------
 .../swagger/generator/core/TestSwaggerUtils.java   | 10 +----
 3 files changed, 26 insertions(+), 42 deletions(-)

diff --git a/swagger/swagger-generator/generator-core/pom.xml 
b/swagger/swagger-generator/generator-core/pom.xml
index ea8c3b93f..872090c0b 100644
--- a/swagger/swagger-generator/generator-core/pom.xml
+++ b/swagger/swagger-generator/generator-core/pom.xml
@@ -50,9 +50,9 @@
     </dependency>
 
     <dependency>
-      <groupId>org.jmockit</groupId>
-      <artifactId>jmockit</artifactId>
-      <scope>provided</scope>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-inline</artifactId>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.junit.jupiter</groupId>
diff --git 
a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/TestSwaggerUtils.java
 
b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/TestSwaggerUtils.java
index a4a639662..3080c09c2 100644
--- 
a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/TestSwaggerUtils.java
+++ 
b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/TestSwaggerUtils.java
@@ -32,8 +32,8 @@ import io.swagger.models.Path;
 import io.swagger.models.Response;
 import io.swagger.models.Swagger;
 import io.swagger.util.Yaml;
-import mockit.Expectations;
-import mockit.Mocked;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
 
 public class TestSwaggerUtils {
 
@@ -47,45 +47,35 @@ public class TestSwaggerUtils {
   }
 
   @Test
-  public void swaggerToStringException(@Mocked Swagger swagger) {
-    new Expectations() {
-      {
-        swagger.getBasePath();
-        result = new RuntimeExceptionWithoutStackTrace();
-      }
-    };
+  public void swaggerToStringException() {
+    Swagger swagger = Mockito.mock(Swagger.class);
+    Mockito.when(swagger.getBasePath()).thenThrow(new 
RuntimeExceptionWithoutStackTrace());
     ServiceCombException exception = 
Assertions.assertThrows(ServiceCombException.class,
             () -> SwaggerUtils.swaggerToString(swagger));
     Assertions.assertEquals("Convert swagger to string failed, ", 
exception.getMessage());
   }
 
   @Test
-  public void parseSwaggerUrlNormal(@Mocked URL url) throws IOException {
+  public void parseSwaggerUrlNormal() throws IOException {
     String content = "swagger: \"2.0\"";
-    new Expectations(IOUtils.class) {
-      {
-        IOUtils.toString(url, StandardCharsets.UTF_8);
-        result = content;
-      }
-    };
-
-    Swagger swagger = Yaml.mapper().readValue(content, Swagger.class);
-    Swagger result = SwaggerUtils.parseSwagger(url);
-    Assertions.assertEquals(swagger, result);
+    URL url = Mockito.mock(URL.class);
+    try (MockedStatic<IOUtils> ioUtilsMockedStatic = 
Mockito.mockStatic(IOUtils.class)) {
+      ioUtilsMockedStatic.when(() -> IOUtils.toString(url, 
StandardCharsets.UTF_8)).thenReturn(content);
+      Swagger swagger = Yaml.mapper().readValue(content, Swagger.class);
+      Swagger result = SwaggerUtils.parseSwagger(url);
+      Assertions.assertEquals(swagger, result);
+    }
   }
 
   @Test
-  public void parseSwaggerUrlException(@Mocked URL url) throws IOException {
-    new Expectations(IOUtils.class) {
-      {
-        IOUtils.toString(url, StandardCharsets.UTF_8);
-        result = new RuntimeExceptionWithoutStackTrace("failed");
-      }
-    };
-
-    ServiceCombException exception = 
Assertions.assertThrows(ServiceCombException.class,
-            () -> SwaggerUtils.parseSwagger(url));
-    Assertions.assertTrue(exception.getMessage().contains("Parse swagger from 
url failed, "));
+  public void parseSwaggerUrlException() throws IOException {
+    URL url = Mockito.mock(URL.class);
+    try (MockedStatic<IOUtils> ioUtilsMockedStatic = 
Mockito.mockStatic(IOUtils.class)) {
+      ioUtilsMockedStatic.when(() -> IOUtils.toString(url, 
StandardCharsets.UTF_8)).thenThrow(new 
RuntimeExceptionWithoutStackTrace("failed"));
+      ServiceCombException exception = 
Assertions.assertThrows(ServiceCombException.class,
+              () -> SwaggerUtils.parseSwagger(url));
+      Assertions.assertTrue(exception.getMessage().contains("Parse swagger 
from url failed, "));
+    }
   }
 
   @Test
diff --git 
a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java
 
b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java
index 0be165b3d..4d3d10497 100644
--- 
a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java
+++ 
b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java
@@ -51,7 +51,6 @@ import io.swagger.models.properties.ObjectProperty;
 import io.swagger.models.properties.Property;
 import io.swagger.models.properties.RefProperty;
 import io.swagger.models.properties.StringProperty;
-import mockit.Expectations;
 
 public class TestSwaggerUtils {
 
@@ -259,13 +258,8 @@ public class TestSwaggerUtils {
   @Test
   public void noParameterName() {
     Method method = ReflectUtils.findMethod(Schema.class, "testint");
-    Parameter parameter = method.getParameters()[0];
-    new Expectations(parameter) {
-      {
-        parameter.isNamePresent();
-        result = false;
-      }
-    };
+    Parameter parameter = Mockito.spy(method.getParameters()[0]);
+    Mockito.when(parameter.isNamePresent()).thenReturn(false);
 
     IllegalStateException exception = 
Assertions.assertThrows(IllegalStateException.class,
             () -> SwaggerGeneratorUtils.collectParameterName(parameter));

Reply via email to