Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-4318

BaseWicketTester#startComponentInPage swallows useful exceptions

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.5.3
    • 1.5.4, 6.0.0-beta1
    • wicket
    • None
    • 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.

      Attachments

        1. wicket-4318.patch
          3 kB
          Dan Alvizu

        Activity

          People

            mgrigorov Martin Tzvetanov Grigorov
            dalvizu Dan Alvizu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: