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

Add ability to easily capture log outputs in unit tests

    XMLWordPrintable

Details

    • N/A

    Description

      Usage:

      public class RestrictParseLocationEventHandlerTest
      {
      ...
          /**
           * Capture logs with WARN or higher severity to assert them.
           */
          @Rule public LogRule logRule = new LogRule() {{
              record(LogLevel.WARN);
              recordLoggingForType(RestrictParseLocationEventHandler.class);
          }};
      
          @Test
          public void includeEventWhenIllegalPath()
          {
      ...
              Assert.assertEquals(1, this.logRule.size());
              Assert.assertTrue(this.logRule.contains(
                  "Direct access to template file [/WEB-INF/xwiki.cfg] refused. Possible break-in attempt!"));
          }
      }
      

      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: