Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-1895

Allow individual tests to provide fixture code that is called before components are initialized

    XMLWordPrintable

Details

    • Unknown
    • N/A

    Description

      When we have components that implement Initializable, we may need to write tests that provide different fixtures for the code inside the initialize() method. So far we had a @BeforeComponent but that's common to all tests and doesn't allow varying the fixture per test.

      The proposal here is to introduce the following:

        @BeforeComponent("normalizeFromRootServletContextAndServletMapping")
          public void beforeNormalizeFromRootServletContextAndServletMapping()
          {
              when(this.servletContext.getServletRegistration("action").getMappings())
                  .thenReturn(Arrays.asList("/*", "/bin/*", "/wiki/*", "/testbin/*"));
          }
      
          @Test
          public void normalizeFromRootServletContextAndServletMapping()
          {
              when(this.servletContext.getContextPath()).thenReturn("/");
      
              HttpServletRequest req = createMockRequest();
              when(req.getServletPath()).thenReturn("/");
      
              assertEquals("/one/two", this.normalizer.normalize(this.testURL).serialize());
          }
      

      Attachments

        Activity

          People

            vmassol Vincent Massol
            vmassol Vincent Massol
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: