001package org.apache.maven.doxia.sink; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import javax.swing.text.AttributeSet; 023import javax.swing.text.MutableAttributeSet; 024 025import junit.framework.TestCase; 026 027/** 028 * 029 * @author ltheussl 030 */ 031public class SinkUtilsTest 032 extends TestCase 033{ 034 035 /** 036 * Test of getAttributeString method, of class SinkUtils. 037 */ 038 public void testGetAttributeString() 039 { 040 assertEquals( "", SinkUtils.getAttributeString( null ) ); 041 042 AttributeSet att = new SinkEventAttributeSet( SinkEventAttributeSet.BOXED ); 043 String expResult = " decoration=\"boxed\""; 044 String result = SinkUtils.getAttributeString( att ); 045 assertEquals( expResult, result ); 046 047 SinkEventAttributes at = new SinkEventAttributeSet( SinkEventAttributeSet.BOLD ); 048 at.addAttributes( att ); 049 expResult = " style=\"bold\" decoration=\"boxed\""; 050 result = SinkUtils.getAttributeString( at ); 051 assertEquals( expResult, result ); 052 053 att = new SinkEventAttributeSet( new String[] {"color", "red", "margin-left", "20px"} ); 054 055 at = new SinkEventAttributeSet(); 056 at.addAttribute( SinkEventAttributeSet.STYLE, att ); 057 expResult = " style=\"color: red; margin-left: 20px\""; 058 result = SinkUtils.getAttributeString( at ); 059 assertEquals( expResult, result ); 060 } 061 062 /** 063 * Test of filterAttributes method, of class SinkUtils. 064 */ 065 public void testFilterAttributes() 066 { 067 assertNull( SinkUtils.filterAttributes( null, null ) ); 068 069 AttributeSet attributes = new SinkEventAttributeSet( 1 ); 070 String[] valids = null; 071 072 MutableAttributeSet result = SinkUtils.filterAttributes( attributes, valids ); 073 assertEquals( 0, result.getAttributeCount() ); 074 075 valids = new String[] {}; 076 result = SinkUtils.filterAttributes( attributes, valids ); 077 assertEquals( 0, result.getAttributeCount() ); 078 079 result = SinkUtils.filterAttributes( SinkEventAttributeSet.BOLD, SinkUtils.SINK_BASE_ATTRIBUTES ); 080 assertEquals( 1, result.getAttributeCount() ); 081 082 result = SinkUtils.filterAttributes( SinkEventAttributeSet.CENTER, SinkUtils.SINK_BASE_ATTRIBUTES ); 083 assertEquals( 0, result.getAttributeCount() ); 084 } 085}