Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 2b73728

Browse files
committed
代码整理
1 parent a8cc65b commit 2b73728

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

src/main/java/org/suren/autotest/web/framework/settings/AutoModuleProxy.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818

1919
package org.suren.autotest.web.framework.settings;
2020

21-
import net.sf.cglib.core.GeneratorStrategy;
22-
import net.sf.cglib.core.NamingPolicy;
2321
import net.sf.cglib.proxy.Enhancer;
2422
import net.sf.cglib.proxy.MethodInterceptor;
2523
import net.sf.cglib.proxy.MethodProxy;
26-
import org.springframework.cglib.core.SpringNamingPolicy;
24+
import org.suren.autotest.web.framework.annotation.AutoExpect;
2725
import org.suren.autotest.web.framework.annotation.AutoModule;
2826
import org.suren.autotest.web.framework.report.RecordReportWriter;
2927
import org.suren.autotest.web.framework.report.record.ExceptionRecord;
@@ -65,6 +63,7 @@ public Object intercept(Object obj, Method method, Object[] args,
6563
Object result = null;
6664
Class<?> superCls = obj.getClass().getSuperclass();
6765
AutoModule autoModule = superCls.getAnnotation(AutoModule.class);
66+
AutoExpect autoExpect = method.getAnnotation(AutoExpect.class);
6867

6968
NormalRecord normalRecord = new NormalRecord();
7069
normalRecord.setBeginTime(beginTime);
@@ -84,17 +83,51 @@ public Object intercept(Object obj, Method method, Object[] args,
8483
write(normalRecord);
8584
}
8685
}
87-
catch(Exception e)
86+
catch(Exception | AssertionError e)
8887
{
88+
boolean acceptException = exceptionHandle(autoExpect, e);
89+
8990
normalRecord.setEndTime(System.currentTimeMillis());
9091
write(new ExceptionRecord(e, normalRecord));
9192

92-
throw e;
93+
if(acceptException)
94+
{
95+
e.printStackTrace();
96+
}
97+
else
98+
{
99+
throw e;
100+
}
93101
}
94102

95103
return result;
96104
}
97105

106+
/**
107+
* 根据注解配置,是否要对异常进行处理
108+
* @param autoExpect
109+
* @return
110+
*/
111+
private boolean exceptionHandle(AutoExpect autoExpect, Throwable e)
112+
{
113+
if(autoExpect != null)
114+
{
115+
Class<?>[] acceptArray = autoExpect.accept();
116+
if(acceptArray != null && acceptArray.length > 0)
117+
{
118+
for(Class<?> clz : acceptArray)
119+
{
120+
if(clz.equals(e.getClass()))
121+
{
122+
return true;
123+
}
124+
}
125+
}
126+
}
127+
128+
return false;
129+
}
130+
98131
private boolean isNotExcludeMethod(Method method)
99132
{
100133
String name = method.getName();

src/test/java/org/suren/autotest/web/framework/mail/MailTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121
import org.junit.Test;
2222
import org.junit.runner.RunWith;
2323
import org.springframework.beans.factory.annotation.Autowired;
24-
import org.springframework.context.annotation.Configuration;
2524
import org.springframework.mail.MailSender;
2625
import org.springframework.mail.SimpleMailMessage;
2726
import org.springframework.test.context.ContextConfiguration;
2827
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2928
import org.suren.autotest.web.framework.AutoApplicationConfig;
3029
import org.suren.autotest.web.framework.AutoTestConfig;
31-
import org.suren.autotest.web.framework.util.EncryptorUtil;
3230

3331
/**
3432
* @author suren
@@ -44,8 +42,8 @@ public class MailTest
4442
public void mailSend()
4543
{
4644
SimpleMailMessage msg = new SimpleMailMessage();
47-
msg.setFrom("361981269@qq.com");
48-
msg.setTo("361981269@qq.com");
45+
msg.setFrom("123456@qq.com");
46+
msg.setTo("123456@qq.com");
4947
msg.setText("context");
5048
msg.setSubject("subject");
5149
mailSender.send(msg);

0 commit comments

Comments
 (0)