当前位置: 首页>>代码示例>>Java>>正文


Java ForwardingObject类代码示例

本文整理汇总了Java中com.google.common.collect.ForwardingObject的典型用法代码示例。如果您正苦于以下问题:Java ForwardingObject类的具体用法?Java ForwardingObject怎么用?Java ForwardingObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ForwardingObject类属于com.google.common.collect包,在下文中一共展示了ForwardingObject类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testForwardingObject

import com.google.common.collect.ForwardingObject; //导入依赖的package包/类
/**
 * Ensures that all interface methods of {@code forwarderClass} are forwarded to the
 * {@link ForwardingObject#delegate}. {@code forwarderClass} is assumed to only implement one
 * interface.
 */
static <T extends ForwardingObject> void testForwardingObject(final Class<T> forwarderClass) {
  @SuppressWarnings("unchecked") // super interface type of T
  Class<? super T> interfaceType = (Class<? super T>)
      Iterables.getOnlyElement(Arrays.asList(forwarderClass.getInterfaces()));
  new ForwardingWrapperTester()
      .testForwarding(
          interfaceType,
          new Function<Object, T>() {
            @Override
            public T apply(Object delegate) {
              T mock = mock(forwarderClass, CALLS_REAL_METHODS.get());
              try {
                T stubber = doReturn(delegate).when(mock);
                DELEGATE_METHOD.invoke(stubber);
              } catch (Exception e) {
                throw new RuntimeException(e);
              }
              return mock;
            }
          });
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:27,代码来源:ForwardingObjectTester.java

示例2: apply

import com.google.common.collect.ForwardingObject; //导入依赖的package包/类
@Override public Object apply(final Object input) {
    return new ForwardingObject() {
        
        @Override protected Object delegate() {
            return input;
        }
        
        @Override public int hashCode() {
            return Objects2.hashCodes(this.delegate());
        }

        @Override public boolean equals(Object obj) {
            return Objects2.isEqual(this.delegate(), obj);
        }
    };
}
 
开发者ID:jronrun,项目名称:benayn,代码行数:17,代码来源:Funcs.java

示例3: testForwardingObject

import com.google.common.collect.ForwardingObject; //导入依赖的package包/类
/**
 * Ensures that all interface methods of {@code forwarderClass} are forwarded to the
 * {@link ForwardingObject#delegate}. {@code forwarderClass} is assumed to only implement one
 * interface.
 */
static <T extends ForwardingObject> void testForwardingObject(final Class<T> forwarderClass) {
  @SuppressWarnings("unchecked") // super interface type of T
  Class<? super T> interfaceType = (Class<? super T>)
      Iterables.getOnlyElement(Arrays.asList(forwarderClass.getInterfaces()));
  new ForwardingWrapperTester().testForwarding(interfaceType, new Function<Object, T>() {
    @Override public T apply(Object delegate) {
      T mock = EasyMock.createMockBuilder(forwarderClass)
          .addMockedMethod(DELEGATE_METHOD)
          .createMock();
      try {
        DELEGATE_METHOD.invoke(mock);
      } catch (Exception e) {
        throw Throwables.propagate(e);
      }
      EasyMock.expectLastCall().andStubReturn(delegate);
      EasyMock.replay(mock);
      return mock;
    }
  });
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:26,代码来源:ForwardingObjectTester.java

示例4: testForwardingObject

import com.google.common.collect.ForwardingObject; //导入依赖的package包/类
/**
 * Ensures that all interface methods of {@code forwarderClass} are forwarded to the {@link
 * ForwardingObject#delegate}. {@code forwarderClass} is assumed to only implement one interface.
 */
static <T extends ForwardingObject> void testForwardingObject(final Class<T> forwarderClass) {
  @SuppressWarnings("unchecked") // super interface type of T
  Class<? super T> interfaceType =
      (Class<? super T>) Iterables.getOnlyElement(Arrays.asList(forwarderClass.getInterfaces()));
  new ForwardingWrapperTester()
      .testForwarding(
          interfaceType,
          new Function<Object, T>() {
            @Override
            public T apply(Object delegate) {
              T mock = mock(forwarderClass, CALLS_REAL_METHODS.get());
              try {
                T stubber = doReturn(delegate).when(mock);
                DELEGATE_METHOD.invoke(stubber);
              } catch (Exception e) {
                throw new RuntimeException(e);
              }
              return mock;
            }
          });
}
 
开发者ID:google,项目名称:guava,代码行数:26,代码来源:ForwardingObjectTester.java


注:本文中的com.google.common.collect.ForwardingObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。