/src/test/java/com/atlassian/util/profiling/object/ObjectProfilerTest.java
Java | 92 lines | 67 code | 20 blank | 5 comment | 0 complexity | 36dd2d788746b66b6b0e621cead0ab61 MD5 | raw file
- package com.atlassian.util.profiling.object;
- import java.lang.reflect.Proxy;
- import java.util.HashMap;
- import java.util.Map;
- import com.atlassian.util.profiling.UtilTimerStack;
- import junit.framework.TestCase;
- import static com.atlassian.util.profiling.UtilTimerStack.getDefaultStrategy;
- /**
- * Tests for ObjectProfiler.
- */
- public class ObjectProfilerTest extends TestCase
- {
- private boolean wasActive;
- public void testProfileMethodThatReturnsInterface() throws Exception
- {
- ServiceImpl svcImpl = new ServiceImpl();
- Service svc = (Service) ObjectProfiler.getProfiledObject(Service.class, svcImpl);
- B b1 = (B) svcImpl.foo(new BImpl()); // works with Impl
- B b2 = (B) svc.foo(new BImpl()); // proxy shouldn't break the above behaviour
- assertTrue(Proxy.isProxyClass(b2.getClass()));
- }
- public void testClassThatImplementsAnInterfaceDoublyShouldBeProxiable() throws Exception
- {
- Service svc = (Service) ObjectProfiler.getProfiledObject(Service.class, new ServiceImpl());
- Map map = svc.getMap(); // JRA-23098: shouldn't throw IllegalArgumentException
- assertTrue(Proxy.isProxyClass(map.getClass()));
- }
- protected void setUp() throws Exception
- {
- super.setUp();
- wasActive = UtilTimerStack.isActive();
- getDefaultStrategy().setEnabled(true);
- }
- protected void tearDown() throws Exception
- {
- getDefaultStrategy().setEnabled(wasActive);
- super.tearDown();
- }
- interface A
- {
- }
- interface B extends A
- {
- }
- interface Service
- {
- // returns A
- A foo(A a);
- Map getMap();
- }
- static class AImpl implements A
- {
- }
- static class BImpl implements B
- {
- }
- static class ServiceImpl implements Service
- {
- public A foo(A a)
- {
- return a;
- }
- public Map getMap()
- {
- return new M();
- }
- }
- static class M extends HashMap implements Map
- {
- // M doubly-implements java.util.Map
- }
- }