mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fixing line endings in the new file introduced in PR #762 merged through commit e8979c0e658b3e3d3c8553f865411d4ececa5f4f
This commit is contained in:
parent
e8979c0e65
commit
22c78ede32
@ -1,85 +1,85 @@
|
|||||||
//
|
//
|
||||||
// Licensed to the Apache Software Foundation (ASF) under one
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
// or more contributor license agreements. See the NOTICE file
|
// or more contributor license agreements. See the NOTICE file
|
||||||
// distributed with this work for additional information
|
// distributed with this work for additional information
|
||||||
// regarding copyright ownership. The ASF licenses this file
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
// to you under the Apache License, Version 2.0 (the
|
// to you under the Apache License, Version 2.0 (the
|
||||||
// "License"); you may not use this file except in compliance
|
// "License"); you may not use this file except in compliance
|
||||||
// with the License. You may obtain a copy of the License at
|
// with the License. You may obtain a copy of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing,
|
// Unless required by applicable law or agreed to in writing,
|
||||||
// software distributed under the License is distributed on an
|
// software distributed under the License is distributed on an
|
||||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
// KIND, either express or implied. See the License for the
|
// KIND, either express or implied. See the License for the
|
||||||
// specific language governing permissions and limitations
|
// specific language governing permissions and limitations
|
||||||
// under the License.
|
// under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
package com.cloud.utils.log;
|
package com.cloud.utils.log;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.sf.cglib.proxy.Enhancer;
|
import net.sf.cglib.proxy.Enhancer;
|
||||||
import net.sf.cglib.proxy.MethodInterceptor;
|
import net.sf.cglib.proxy.MethodInterceptor;
|
||||||
import net.sf.cglib.proxy.MethodProxy;
|
import net.sf.cglib.proxy.MethodProxy;
|
||||||
|
|
||||||
public class CglibThrowableRendererTest {
|
public class CglibThrowableRendererTest {
|
||||||
|
|
||||||
CglibThrowableRenderer cglibThrowableRenderer = new CglibThrowableRenderer();
|
CglibThrowableRenderer cglibThrowableRenderer = new CglibThrowableRenderer();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoRendere() {
|
public void testDoRendere() {
|
||||||
SampleClass sampleClass = (SampleClass)Enhancer.create(SampleClass.class, new MyInvocationHandler());
|
SampleClass sampleClass = (SampleClass)Enhancer.create(SampleClass.class, new MyInvocationHandler());
|
||||||
try {
|
try {
|
||||||
sampleClass.theFirstMethodThatCapturesAnException();
|
sampleClass.theFirstMethodThatCapturesAnException();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String[] exceptions = cglibThrowableRenderer.doRender(e);
|
String[] exceptions = cglibThrowableRenderer.doRender(e);
|
||||||
assertThatTheTraceListDoesNotContainsCgLibLogs(exceptions);
|
assertThatTheTraceListDoesNotContainsCgLibLogs(exceptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertThatTheTraceListDoesNotContainsCgLibLogs(String[] exceptions) {
|
private void assertThatTheTraceListDoesNotContainsCgLibLogs(String[] exceptions) {
|
||||||
for (String s : exceptions) {
|
for (String s : exceptions) {
|
||||||
Assert.assertEquals(false, isCgLibLogTrace(s));
|
Assert.assertEquals(false, isCgLibLogTrace(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCgLibLogTrace(String s) {
|
private boolean isCgLibLogTrace(String s) {
|
||||||
return StringUtils.contains(s, "net.sf.cglib.proxy");
|
return StringUtils.contains(s, "net.sf.cglib.proxy");
|
||||||
}
|
}
|
||||||
|
|
||||||
static class SampleClass {
|
static class SampleClass {
|
||||||
public void theFirstMethodThatCapturesAnException() {
|
public void theFirstMethodThatCapturesAnException() {
|
||||||
try {
|
try {
|
||||||
methodThatCapturesAndThrowsException();
|
methodThatCapturesAndThrowsException();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void methodThatCapturesAndThrowsException() throws Exception {
|
private void methodThatCapturesAndThrowsException() throws Exception {
|
||||||
try {
|
try {
|
||||||
methodThatThrowsAnError();
|
methodThatThrowsAnError();
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
throw new Exception("Throws an exception", e);
|
throw new Exception("Throws an exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void methodThatThrowsAnError() {
|
private void methodThatThrowsAnError() {
|
||||||
throw new Error("Exception to test the CglibThrowableRenderer.");
|
throw new Error("Exception to test the CglibThrowableRenderer.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class MyInvocationHandler implements MethodInterceptor {
|
static class MyInvocationHandler implements MethodInterceptor {
|
||||||
@Override
|
@Override
|
||||||
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
|
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
|
||||||
return proxy.invoke(new SampleClass(), args);
|
return proxy.invoke(new SampleClass(), args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user