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

        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

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development