Wicket
  1. Wicket
  2. WICKET-4318

BaseWicketTester#startComponentInPage swallows useful exceptions

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.3
    • Fix Version/s: 1.5.4, 6.0.0-beta1
    • Component/s: wicket
    • Labels:
      None
    • Environment:
      JUnit 4.8.2

      Description

      The method BaseWicketTester#startComponentInPage (final Class<C> componentClass, final IMarkupFragment pageMarkup) starts a panel inside of page markup through reflection, and captures all of the exceptions (InvocationTargetException, NoSuchMethodException, etc...) in one big try /catch:

      C comp = null;
      try

      { Constructor<C> c = componentClass.getConstructor(String.class); comp = c.newInstance(ComponentInPage.ID); componentInPage = new ComponentInPage(); componentInPage.component = comp; componentInPage.isInstantiated = true; }

      catch (Exception e)

      { fail(e.getMessage()); }

      There are two issues with this:

      1) This fail() will often not print out anything helpful about the exception that caused the error. For a NullPointerException (along with many other exceptions) you'll simply get back: "junit.framework.AssertionFailedError: null"

      2) You cannot write tests that expect an exception in the constructor, for example if you were using auth-roles and expect to see an UnauthorizedInstantiationException if you provide the wrong role, you cannot test this. You could test this scenario if it were a page, however, because these Exceptions will not be swallowed.

        Activity

        Dan Alvizu created issue -
        Dan Alvizu made changes -
        Field Original Value New Value
        Description The method BaseWicketTester#startComponentInPage (final Class<C> componentClass, final IMarkupFragment pageMarkup) starts a panel inside of page markup through exception, and captures all of the exceptions (InvocationTargetException, NoSuchMethodException, etc...) in one big try /catch:

        C comp = null;
        try
        {
        Constructor<C> c = componentClass.getConstructor(String.class);
        comp = c.newInstance(ComponentInPage.ID);
        componentInPage = new ComponentInPage();
        componentInPage.component = comp;
        componentInPage.isInstantiated = true;
        }
        catch (Exception e)
        {
        fail(e.getMessage());
        }

        There are two issues with this:

        1) This fail() will often not print out anything helpful about the exception that caused the error. For a NullPointerException (along with many other exceptions) you'll simply get back: "junit.framework.AssertionFailedError: null"

        2) You cannot write tests that expect an exception in the constructor, for example if you were using auth-roles and expect to see an UnauthorizedInstantiationException if you provide the wrong role, you cannot test this. You could test this scenario if it were a page, however, because these Exceptions will not be swallowed.
        The method BaseWicketTester#startComponentInPage (final Class<C> componentClass, final IMarkupFragment pageMarkup) starts a panel inside of page markup through reflection, and captures all of the exceptions (InvocationTargetException, NoSuchMethodException, etc...) in one big try /catch:

        C comp = null;
        try
        {
        Constructor<C> c = componentClass.getConstructor(String.class);
        comp = c.newInstance(ComponentInPage.ID);
        componentInPage = new ComponentInPage();
        componentInPage.component = comp;
        componentInPage.isInstantiated = true;
        }
        catch (Exception e)
        {
        fail(e.getMessage());
        }

        There are two issues with this:

        1) This fail() will often not print out anything helpful about the exception that caused the error. For a NullPointerException (along with many other exceptions) you'll simply get back: "junit.framework.AssertionFailedError: null"

        2) You cannot write tests that expect an exception in the constructor, for example if you were using auth-roles and expect to see an UnauthorizedInstantiationException if you provide the wrong role, you cannot test this. You could test this scenario if it were a page, however, because these Exceptions will not be swallowed.
        Hide
        Dan Alvizu added a comment -

        Uploading wicket-4318.patch for the 1.5.x branch

        Show
        Dan Alvizu added a comment - Uploading wicket-4318.patch for the 1.5.x branch
        Dan Alvizu made changes -
        Attachment wicket-4318.patch [ 12508894 ]
        Martin Grigorov made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Martin Grigorov [ mgrigorov ]
        Fix Version/s 1.5.4 [ 12319051 ]
        Fix Version/s 6.0.0 [ 12315431 ]
        Resolution Fixed [ 1 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        8d 10h 54m 1 Martin Grigorov 07/Jan/12 09:41

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Dan Alvizu
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development