Example #1
0
 /**
  * MarkdownTxtmark can format bullets to HTML.
  *
  * @throws Exception If there is some problem inside
  */
 @Test
 public void formatsBulletsToHtml() throws Exception {
   final String meta =
       new MarkdownTxtmark()
           .html(
               Joiner.on(MarkdownTxtmarkTest.EOL)
                   .join("my list:", "", "* line one", "* line two", "", "normal text now"));
   MatcherAssert.assertThat(
       String.format("<r>%s</r>", meta),
       Matchers.describedAs(
           meta,
           XhtmlMatchers.hasXPaths(
               "/r/p[text()='my list:']",
               "/r/ul[count(li) = 2]",
               "/r/ul/li[text()='line one']",
               "/r/ul/li[text()='line two']",
               "/r/p[.='normal text now']")));
 }
Example #2
0
 /**
  * CodeNarcValidator can report full names of files that contain violations.
  *
  * @throws Exception If error message does not include filename.
  */
 @Test(expected = ValidationException.class)
 public void reportsFullFileNamesOfGroovyScripts() throws Exception {
   final Environment env =
       new Environment.Mock().withFile("src/main/Foo.groovy", "System.out.println('foo')");
   final Validator validator = new CodeNarcValidator();
   final CodeNarcAppender appender = new CodeNarcAppender();
   org.apache.log4j.Logger.getRootLogger().addAppender(appender);
   try {
     validator.validate(env);
   } catch (final ValidationException ex) {
     final List<String> messages = appender.getMessages();
     final Pattern pattern = Pattern.compile("[a-zA-Z0-9_/\\\\:~.]+\\.groovy\\[\\d+\\]: .*");
     for (final String message : messages) {
       if (message.startsWith("CodeNarc validated ")) {
         continue;
       }
       MatcherAssert.assertThat(
           pattern.matcher(message).matches(), Matchers.describedAs(message, Matchers.is(true)));
     }
     throw ex;
   } finally {
     org.apache.log4j.Logger.getRootLogger().removeAppender(appender);
   }
 }
Example #3
0
 /**
  * MarkdownTxtmark can format a text to HTML.
  *
  * @throws Exception If there is some problem inside
  */
 @Test
 public void formatsTextToHtml() throws Exception {
   final String meta =
       new MarkdownTxtmark()
           .html(
               Joiner.on(MarkdownTxtmarkTest.EOL)
                   .join(
                       "**hi**, _dude_!\r",
                       "",
                       "     b**o",
                       "       ",
                       "        ",
                       "    o**m",
                       ""));
   MatcherAssert.assertThat(
       String.format("<x>%s</x>", meta),
       Matchers.describedAs(
           meta,
           XhtmlMatchers.hasXPaths(
               "/x/p/strong[.='hi']",
               "/x/p/em[.='dude']",
               Joiner.on(MarkdownTxtmarkTest.EOL)
                   .join("/x/pre/code[.=' b**o", "", "", "o**m", "']"))));
 }
Example #4
0
 /**
  * Test checkstyle for true positive.
  *
  * @throws Exception If something goes wrong
  */
 @Test
 public void testCheckstyleTruePositive() throws Exception {
   final AuditListener listener = Mockito.mock(AuditListener.class);
   final Collector collector = new ChecksTest.Collector();
   Mockito.doAnswer(collector).when(listener).addError(Mockito.any(AuditEvent.class));
   this.check("/Invalid.java", listener);
   final String[] violations =
       StringUtils.split(
           IOUtils.toString(
               this.getClass().getResourceAsStream(String.format("%s/violations.txt", this.dir))),
           "\n");
   for (final String line : violations) {
     final String[] sectors = StringUtils.split(line, ":");
     final Integer pos = Integer.valueOf(sectors[0]);
     final String needle = sectors[1].trim();
     MatcherAssert.assertThat(
         collector.has(pos, needle),
         Matchers.describedAs(
             String.format(
                 "Line no.%d ('%s') not reported by %s: '%s'",
                 pos, needle, this.dir, collector.summary()),
             Matchers.is(true)));
   }
 }