Java 类com.google.common.collect.ForwardingObject 实例源码

项目:guava-mock    文件:ForwardingObjectTester.java   
/**
 * 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;
            }
          });
}
项目:googles-monorepo-demo    文件:ForwardingObjectTester.java   
/**
 * 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;
            }
          });
}
项目:benayn    文件:Funcs.java   
@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);
        }
    };
}
项目:guava-libraries    文件:ForwardingObjectTester.java   
/**
 * 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;
    }
  });
}
项目:guava    文件:ForwardingObjectTester.java   
/**
 * 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;
            }
          });
}
项目:guava    文件:ForwardingObjectTester.java   
/**
 * 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;
            }
          });
}
项目:benayn    文件:Funcs.java   
@Override public Object apply(final Object input) {
    return new ForwardingObject() {

        @Override protected Object delegate() {
            return input;
        }

        @Override public String toString() {
            return Objects2.toString(this.delegate());
        }
    };
}