View Javadoc
1   package org.apache.maven.doxia.sink;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import javax.swing.text.AttributeSet;
23  import javax.swing.text.MutableAttributeSet;
24  
25  import junit.framework.TestCase;
26  
27  /**
28   *
29   * @author ltheussl
30   */
31  public class SinkUtilsTest
32          extends TestCase
33  {
34  
35      /**
36       * Test of getAttributeString method, of class SinkUtils.
37       */
38      public void testGetAttributeString()
39      {
40          assertEquals( "", SinkUtils.getAttributeString( null ) );
41  
42          AttributeSet att = new SinkEventAttributeSet( SinkEventAttributeSet.BOXED );
43          String expResult = " decoration=\"boxed\"";
44          String result = SinkUtils.getAttributeString( att );
45          assertEquals( expResult, result );
46  
47          SinkEventAttributes at = new SinkEventAttributeSet( SinkEventAttributeSet.BOLD );
48          at.addAttributes( att );
49          expResult = " style=\"bold\" decoration=\"boxed\"";
50          result = SinkUtils.getAttributeString( at );
51          assertEquals( expResult, result );
52  
53          att = new SinkEventAttributeSet( new String[] {"color", "red", "margin-left", "20px"} );
54  
55          at = new SinkEventAttributeSet();
56          at.addAttribute( SinkEventAttributeSet.STYLE, att );
57          expResult = " style=\"color: red; margin-left: 20px\"";
58          result = SinkUtils.getAttributeString( at );
59          assertEquals( expResult, result );
60      }
61  
62      /**
63       * Test of filterAttributes method, of class SinkUtils.
64       */
65      public void testFilterAttributes()
66      {
67          assertNull( SinkUtils.filterAttributes( null, null ) );
68  
69          AttributeSet attributes = new SinkEventAttributeSet( 1 );
70          String[] valids = null;
71  
72          MutableAttributeSet result = SinkUtils.filterAttributes( attributes, valids );
73          assertEquals( 0, result.getAttributeCount() );
74  
75          valids = new String[] {};
76          result = SinkUtils.filterAttributes( attributes, valids );
77          assertEquals( 0, result.getAttributeCount() );
78  
79          result = SinkUtils.filterAttributes( SinkEventAttributeSet.BOLD, SinkUtils.SINK_BASE_ATTRIBUTES );
80          assertEquals( 1, result.getAttributeCount() );
81  
82          result = SinkUtils.filterAttributes( SinkEventAttributeSet.CENTER, SinkUtils.SINK_BASE_ATTRIBUTES );
83          assertEquals( 0, result.getAttributeCount() );
84      }
85  }