This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 18b5478 Add verify for test cases of #13958 (#14179)
18b5478 is described below
commit 18b5478c223d21c1d6de062f067b2ffdce178375
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Dec 20 23:36:28 2021 +0800
Add verify for test cases of #13958 (#14179)
---
.../ComposeClassStaticMethodAroundAdviceTest.java | 54 +++++++++++++---------
.../advice/ComposeConstructorAdviceTest.java | 31 ++++++++-----
2 files changed, 51 insertions(+), 34 deletions(-)
diff --git
a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeClassStaticMethodAroundAdviceTest.java
b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeClassStaticMethodAroundAdviceTest.java
index 30c13f8..9adfc02 100644
---
a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeClassStaticMethodAroundAdviceTest.java
+++
b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeClassStaticMethodAroundAdviceTest.java
@@ -19,48 +19,56 @@ package
org.apache.shardingsphere.agent.core.bytebuddy.transformer.advice;
import
org.apache.shardingsphere.agent.api.advice.ClassStaticMethodAroundAdvice;
import org.apache.shardingsphere.agent.api.result.MethodInvocationResult;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.Collections;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
-public class ComposeClassStaticMethodAroundAdviceTest {
-
- private ComposeClassStaticMethodAroundAdvice
composeClassStaticMethodAroundAdvice;
-
+public final class ComposeClassStaticMethodAroundAdviceTest {
+
+ @Mock
+ private ClassStaticMethodAroundAdvice classStaticMethodAroundAdvice;
+
+ private ComposeClassStaticMethodAroundAdvice actual;
+
+ @Before
+ public void setUp() {
+ actual = new ComposeClassStaticMethodAroundAdvice(new
ArrayList<>(Collections.singletonList(classStaticMethodAroundAdvice)));
+ }
+
@Test
- public void beforeMethodTest() {
- ClassStaticMethodAroundAdvice advice =
mock(ClassStaticMethodAroundAdvice.class);
+ public void assertBeforeMethod() {
Method method = mock(Method.class);
+ Object[] args = new Object[2];
MethodInvocationResult methodInvocationResult =
mock(MethodInvocationResult.class);
- List<ClassStaticMethodAroundAdvice> adviceList = new
ArrayList<>(Arrays.asList(advice));
- composeClassStaticMethodAroundAdvice = new
ComposeClassStaticMethodAroundAdvice(adviceList);
- composeClassStaticMethodAroundAdvice.beforeMethod(String.class,
method, new Object[2], methodInvocationResult);
+ actual.beforeMethod(String.class, method, args,
methodInvocationResult);
+ verify(classStaticMethodAroundAdvice).beforeMethod(String.class,
method, args, methodInvocationResult);
}
-
+
@Test
- public void afterMethodTest() {
- ClassStaticMethodAroundAdvice advice =
mock(ClassStaticMethodAroundAdvice.class);
+ public void assertAfterMethod() {
Method method = mock(Method.class);
+ Object[] args = new Object[2];
MethodInvocationResult methodInvocationResult =
mock(MethodInvocationResult.class);
- List<ClassStaticMethodAroundAdvice> adviceList = new
ArrayList<>(Arrays.asList(advice));
- composeClassStaticMethodAroundAdvice = new
ComposeClassStaticMethodAroundAdvice(adviceList);
- composeClassStaticMethodAroundAdvice.afterMethod(String.class, method,
new Object[2], methodInvocationResult);
+ actual.afterMethod(String.class, method, args, methodInvocationResult);
+ verify(classStaticMethodAroundAdvice).afterMethod(String.class,
method, args, methodInvocationResult);
}
-
+
@Test
- public void onThrowingTest() {
- ClassStaticMethodAroundAdvice advice =
mock(ClassStaticMethodAroundAdvice.class);
+ public void assertOnThrowing() {
Method method = mock(Method.class);
- List<ClassStaticMethodAroundAdvice> adviceList = new
ArrayList<>(Arrays.asList(advice));
- composeClassStaticMethodAroundAdvice = new
ComposeClassStaticMethodAroundAdvice(adviceList);
- composeClassStaticMethodAroundAdvice.onThrowing(String.class, method,
new Object[2], new NullPointerException("Null Pointer"));
+ Object[] args = new Object[2];
+ NullPointerException exception = new NullPointerException("");
+ actual.onThrowing(String.class, method, args, exception);
+ verify(classStaticMethodAroundAdvice).onThrowing(String.class, method,
args, exception);
}
}
diff --git
a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdviceTest.java
b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdviceTest.java
index 0fca644..333b49a 100644
---
a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdviceTest.java
+++
b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdviceTest.java
@@ -19,27 +19,36 @@ package
org.apache.shardingsphere.agent.core.bytebuddy.transformer.advice;
import org.apache.shardingsphere.agent.api.advice.AdviceTargetObject;
import org.apache.shardingsphere.agent.api.advice.ConstructorAdvice;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.Collections;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
-public class ComposeConstructorAdviceTest {
-
- private ComposeConstructorAdvice composeConstructorAdvice;
-
+public final class ComposeConstructorAdviceTest {
+
+ @Mock
+ private ConstructorAdvice constructorAdvice;
+
+ private ComposeConstructorAdvice actual;
+
+ @Before
+ public void setUp() {
+ actual = new ComposeConstructorAdvice(new
ArrayList<>(Collections.singletonList(constructorAdvice)));
+ }
+
@Test
- public void onConstructorTest() {
- ConstructorAdvice advice = mock(ConstructorAdvice.class);
+ public void assertOnConstructor() {
AdviceTargetObject adviceTargetObject = mock(AdviceTargetObject.class);
- List<ConstructorAdvice> adviceList = new
ArrayList<>(Arrays.asList(advice));
- composeConstructorAdvice = new ComposeConstructorAdvice(adviceList);
- composeConstructorAdvice.onConstructor(adviceTargetObject, new
Object[2]);
+ Object[] args = new Object[2];
+ actual.onConstructor(adviceTargetObject, args);
+ verify(constructorAdvice).onConstructor(adviceTargetObject, args);
}
}