Package org.apache.aries.blueprint.proxy.AbstractProxyTest

Examples of org.apache.aries.blueprint.proxy.AbstractProxyTest.TestListener


   */
  @Test
  public void testDelegationAndInterception() throws Exception
  {
    Collection<Class<?>> classes = new ArrayList<Class<?>>(Arrays.asList(Callable.class));
    TestListener tl = new TestListener();
    TestCallable tc = new TestCallable();
   
    Callable o = (Callable) InterfaceProxyGenerator.getProxyInstance(testBundle,
        null, classes, tc, tl);
   
    assertCalled(tl, false, false, false);
   
    assertNull(null, o.call());
   
    assertCalled(tl, true, true, false);
   
    assertEquals(Callable.class.getMethod("call"),
        tl.getLastMethod());

    tl.clear();
    assertCalled(tl, false, false, false);
   
    tc.setReturn(new Callable<Object>() {

      public Object call() throws Exception {
        throw new RuntimeException();
      }
    });
    try {
      o.call();
      fail("Should throw an exception");
    } catch (RuntimeException re) {
      assertCalled(tl, true, false, true);
      assertSame(re, tl.getLastThrowable());
    }
   
    tl.clear();
    assertCalled(tl, false, false, false);
   
    tc.setReturn(new Callable<Object>() {

    
View Full Code Here


    assertEquals(5, ((Callable)o).call());
  }
 
  @Test
  public void testHandlesObjectMethods() throws Exception {
      TestListener listener = new TestListener();
      List<String> list = Arrays.asList("one", "two", "three");
      Object proxied = InterfaceProxyGenerator.getProxyInstance(testBundle, null, Arrays.<Class<?>>asList(List.class), constantly(list), listener);
     
      // obeys hashCode and equals, they *are* on the interface (actually they're
      // on several interfaces, we process them in alphabetical order, so Collection
      // comes ahead of List.
      assertTrue(proxied.equals(Arrays.asList("one", "two", "three")));
      assertEquals(Collection.class.getMethod("equals", Object.class), listener.getLastMethod());
      listener.clear();
      assertEquals(Arrays.asList("one", "two", "three").hashCode(), proxied.hashCode());
      assertEquals(Collection.class.getMethod("hashCode"), listener.getLastMethod());
      listener.clear();
      // and toString
      assertEquals(list.toString(), proxied.toString());
      assertEquals(Object.class.getMethod("toString"), listener.getLastMethod());
      listener.clear();
     
      Runnable runnable = new Runnable() {
        public void run() {}
      };
      proxied = InterfaceProxyGenerator.getProxyInstance(testBundle, null, Arrays.<Class<?>>asList(Runnable.class), constantly(runnable), listener);
     
      // obeys hashCode and equals, they *are not* on the interface
      assertTrue(proxied.equals(runnable));
      assertEquals(Object.class.getMethod("equals", Object.class), listener.getLastMethod());
      listener.clear();
      assertEquals(runnable.hashCode(), proxied.hashCode());
      assertEquals(Object.class.getMethod("hashCode"), listener.getLastMethod());
      listener.clear();
  }
View Full Code Here

   */
  @Test
  public void testDelegationAndInterception() throws Exception
  {
    Collection<Class<?>> classes = new ArrayList<Class<?>>(Arrays.asList(Callable.class));
    TestListener tl = new TestListener();
    TestCallable tc = new TestCallable();
   
    Callable o = (Callable) InterfaceProxyGenerator.getProxyInstance(testBundle,
        classes, tc, tl);
   
    assertCalled(tl, false, false, false);
   
    assertNull(null, o.call());
   
    assertCalled(tl, true, true, false);
   
    assertEquals(Callable.class.getMethod("call"),
        tl.getLastMethod());

    tl.clear();
    assertCalled(tl, false, false, false);
   
    tc.setReturn(new Callable<Object>() {

      @Override
      public Object call() throws Exception {
        throw new RuntimeException();
      }
    });
    try {
      o.call();
      fail("Should throw an exception");
    } catch (RuntimeException re) {
      assertCalled(tl, true, false, true);
      assertSame(re, tl.getLastThrowable());
    }
   
    tl.clear();
    assertCalled(tl, false, false, false);
   
    tc.setReturn(new Callable<Object>() {

      @Override
View Full Code Here

    assertEquals(5, ((Callable)o).call());
  }
 
  @Test
  public void testHandlesObjectMethods() throws Exception {
      TestListener listener = new TestListener();
      List<String> list = Arrays.asList("one", "two", "three");
      Object proxied = InterfaceProxyGenerator.getProxyInstance(testBundle, Arrays.<Class<?>>asList(List.class), constantly(list), listener);
     
      // obeys hashCode and equals, they *are* on the interface
      assertTrue(proxied.equals(Arrays.asList("one", "two", "three")));
      assertEquals(List.class.getMethod("equals", Object.class), listener.getLastMethod());
      listener.clear();
      assertEquals(Arrays.asList("one", "two", "three").hashCode(), proxied.hashCode());
      assertEquals(List.class.getMethod("hashCode"), listener.getLastMethod());
      listener.clear();
      // and toString
      assertEquals(list.toString(), proxied.toString());
      assertEquals(Object.class.getMethod("toString"), listener.getLastMethod());
      listener.clear();
     
      Runnable runnable = new Runnable() {
        public void run() {}
      };
      proxied = InterfaceProxyGenerator.getProxyInstance(testBundle, Arrays.<Class<?>>asList(Runnable.class), constantly(runnable), listener);
     
      // obeys hashCode and equals, they *are not* on the interface
      assertTrue(proxied.equals(runnable));
      assertEquals(Object.class.getMethod("equals", Object.class), listener.getLastMethod());
      listener.clear();
      assertEquals(runnable.hashCode(), proxied.hashCode());
      assertEquals(Object.class.getMethod("hashCode"), listener.getLastMethod());
      listener.clear();
  }
View Full Code Here

TOP

Related Classes of org.apache.aries.blueprint.proxy.AbstractProxyTest.TestListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.