View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd;
5   
6   import java.io.ByteArrayOutputStream;
7   
8   import org.junit.Assert;
9   import org.junit.Test;
10  
11  /**
12   * Unit test for {@link RuleSetWriter}.
13   *
14   */
15  public class RuleSetWriterTest {
16  
17      /**
18       * Tests the exclude rule behavior.
19       * See bug #945.
20       * @throws Exception any error
21       */
22      @Test
23      public void testWrite() throws Exception {
24          ByteArrayOutputStream out = new ByteArrayOutputStream();
25          RuleSetWriter writer = null;
26          try {
27              writer = new RuleSetWriter(out);
28  
29              RuleSet ruleSet = new RuleSet();
30              RuleSet braces = new RuleSetFactory().createRuleSet("java-braces");
31              ruleSet.addRuleSetByReference(braces, true, "WhileLoopsMustUseBraces");
32  
33              writer.write(ruleSet);
34          } finally {
35              if (writer != null) {
36                  writer.close();
37              }
38          }
39  
40          String written = out.toString("UTF-8");
41          Assert.assertTrue(written.contains("<exclude name=\"WhileLoopsMustUseBraces\""));
42      }
43  }