Skip to content

Commit

Permalink
Add verify for test cases of #13958 (#14179)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Dec 20, 2021
1 parent d08a80a commit 18b5478
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,56 @@

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,36 @@

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);
}
}

0 comments on commit 18b5478

Please sign in to comment.