|
17 | 17 | package com.ctrip.framework.apollo.audit.aop;
|
18 | 18 |
|
19 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 20 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
20 | 21 | import static org.mockito.ArgumentMatchers.any;
|
21 | 22 | import static org.mockito.Mockito.doNothing;
|
22 | 23 | import static org.mockito.Mockito.doReturn;
|
|
37 | 38 | import java.util.Arrays;
|
38 | 39 | import java.util.List;
|
39 | 40 | import org.aspectj.lang.ProceedingJoinPoint;
|
40 |
| -import org.aspectj.lang.Signature; |
| 41 | +import org.aspectj.lang.reflect.MethodSignature; |
41 | 42 | import org.junit.jupiter.api.Test;
|
42 | 43 | import org.springframework.boot.test.context.SpringBootTest;
|
43 | 44 | import org.springframework.boot.test.mock.mockito.MockBean;
|
@@ -95,20 +96,36 @@ public void testAuditDataInfluenceArg() throws NoSuchMethodException {
|
95 | 96 | .parseArgAndAppend(eq("App"), eq("Name"), eq(args[0]));
|
96 | 97 | }
|
97 | 98 |
|
| 99 | + @Test |
| 100 | + public void testAuditDataInfluenceArgCaseFindMethodReturnNull() throws NoSuchMethodException { |
| 101 | + ProceedingJoinPoint mockPJP = mock(ProceedingJoinPoint.class); |
| 102 | + Object[] args = new Object[]{new Object(), new Object()}; |
| 103 | + { |
| 104 | + doReturn(null).when(aspect).findMethod(any()); |
| 105 | + when(mockPJP.getArgs()).thenReturn(args); |
| 106 | + } |
| 107 | + aspect.auditDataInfluenceArg(mockPJP); |
| 108 | + verify(aspect, times(0)) |
| 109 | + .parseArgAndAppend(eq("App"), eq("Name"), eq(args[0])); |
| 110 | + } |
| 111 | + |
98 | 112 | @Test
|
99 | 113 | public void testFindMethod() throws NoSuchMethodException {
|
100 | 114 | ProceedingJoinPoint mockPJP = mock(ProceedingJoinPoint.class);
|
101 | 115 | MockAuditClass mockAuditClass = new MockAuditClass();
|
102 |
| - Signature signature = mock(Signature.class); |
| 116 | + MethodSignature signature = mock(MethodSignature.class); |
103 | 117 | Method method = MockAuditClass.class.getMethod("mockAuditMethod", Object.class, Object.class);
|
| 118 | + Method sameNameMethod = MockAuditClass.class.getMethod("mockAuditMethod", Object.class); |
104 | 119 | {
|
105 | 120 | when(mockPJP.getTarget()).thenReturn(mockAuditClass);
|
106 | 121 | when(mockPJP.getSignature()).thenReturn(signature);
|
107 | 122 | when(signature.getName()).thenReturn("mockAuditMethod");
|
| 123 | + when(signature.getParameterTypes()).thenReturn(new Class[]{Object.class, Object.class}); |
108 | 124 | }
|
109 | 125 | Method methodFounded = aspect.findMethod(mockPJP);
|
110 | 126 |
|
111 | 127 | assertEquals(method, methodFounded);
|
| 128 | + assertNotEquals(sameNameMethod, methodFounded); |
112 | 129 | }
|
113 | 130 |
|
114 | 131 | @Test
|
@@ -155,5 +172,10 @@ public void mockAuditMethod(
|
155 | 172 | @ApolloAuditLogDataInfluenceTableField(fieldName = "Name") Object val1,
|
156 | 173 | Object val2) {
|
157 | 174 | }
|
| 175 | + |
| 176 | + // same name method test |
| 177 | + public void mockAuditMethod( |
| 178 | + Object val2) { |
| 179 | + } |
158 | 180 | }
|
159 | 181 | }
|
0 commit comments