Class ForwardingWrapperTester


  • @Beta
    @GwtIncompatible
    public final class ForwardingWrapperTester
    extends java.lang.Object
    Tester to ensure forwarding wrapper works by delegating calls to the corresponding method with the same parameters forwarded and return value forwarded back or exception propagated as is.

    For example:

       
       new ForwardingWrapperTester().testForwarding(Foo.class, new Function<Foo, Foo>() {
         public Foo apply(Foo foo) {
           return new ForwardingFoo(foo);
         }
       });
    Since:
    14.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean testsEquals  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.reflect.Method[] getMostConcreteMethods​(java.lang.Class<?> type)
      Returns the most concrete public methods from type.
      private static java.lang.Object[] getParameterValues​(java.lang.reflect.Method method)  
      ForwardingWrapperTester includingEquals()
      Asks for Object.equals(java.lang.Object) and Object.hashCode() to be tested.
      private static <T> void testEquals​(java.lang.Class<T> interfaceType, Function<? super T,​? extends T> wrapperFunction)  
      private static <T> void testExceptionPropagation​(java.lang.Class<T> interfaceType, java.lang.reflect.Method method, Function<? super T,​? extends T> wrapperFunction)  
      <T> void testForwarding​(java.lang.Class<T> interfaceType, Function<? super T,​? extends T> wrapperFunction)
      Tests that the forwarding wrapper returned by wrapperFunction properly forwards method calls with parameters passed as is, return value returned as is, and exceptions propagated as is.
      private static <T> void testSuccessfulForwarding​(java.lang.Class<T> interfaceType, java.lang.reflect.Method method, Function<? super T,​? extends T> wrapperFunction)  
      private static <T> void testToString​(java.lang.Class<T> interfaceType, Function<? super T,​? extends T> wrapperFunction)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • testsEquals

        private boolean testsEquals
    • Constructor Detail

      • ForwardingWrapperTester

        public ForwardingWrapperTester()
    • Method Detail

      • includingEquals

        public ForwardingWrapperTester includingEquals()
        Asks for Object.equals(java.lang.Object) and Object.hashCode() to be tested. That is, forwarding wrappers of equal instances should be equal.
      • testForwarding

        public <T> void testForwarding​(java.lang.Class<T> interfaceType,
                                       Function<? super T,​? extends T> wrapperFunction)
        Tests that the forwarding wrapper returned by wrapperFunction properly forwards method calls with parameters passed as is, return value returned as is, and exceptions propagated as is.
      • getMostConcreteMethods

        private static java.lang.reflect.Method[] getMostConcreteMethods​(java.lang.Class<?> type)
        Returns the most concrete public methods from type.
      • testSuccessfulForwarding

        private static <T> void testSuccessfulForwarding​(java.lang.Class<T> interfaceType,
                                                         java.lang.reflect.Method method,
                                                         Function<? super T,​? extends T> wrapperFunction)
      • testExceptionPropagation

        private static <T> void testExceptionPropagation​(java.lang.Class<T> interfaceType,
                                                         java.lang.reflect.Method method,
                                                         Function<? super T,​? extends T> wrapperFunction)
      • testEquals

        private static <T> void testEquals​(java.lang.Class<T> interfaceType,
                                           Function<? super T,​? extends T> wrapperFunction)
      • testToString

        private static <T> void testToString​(java.lang.Class<T> interfaceType,
                                             Function<? super T,​? extends T> wrapperFunction)
      • getParameterValues

        private static java.lang.Object[] getParameterValues​(java.lang.reflect.Method method)