本文整理汇总了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;
}
});
}
示例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);
}
};
}
示例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;
}
});
}
示例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;
}
});
}