001package org.apache.maven.doxia.sink.impl; 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 org.apache.maven.doxia.sink.SinkEventAttributes; 026import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet; 027import org.apache.maven.doxia.sink.impl.SinkUtils; 028 029import junit.framework.TestCase; 030 031/** 032 * 033 * @author ltheussl 034 */ 035public class SinkUtilsTest 036 extends TestCase 037{ 038 039 /** 040 * Test of getAttributeString method, of class SinkUtils. 041 */ 042 public void testGetAttributeString() 043 { 044 assertEquals( "", SinkUtils.getAttributeString( null ) ); 045 046 AttributeSet att = new SinkEventAttributeSet( SinkEventAttributeSet.BOXED ); 047 String expResult = " decoration=\"boxed\""; 048 String result = SinkUtils.getAttributeString( att ); 049 assertEquals( expResult, result ); 050 051 SinkEventAttributes at = new SinkEventAttributeSet( SinkEventAttributeSet.BOLD ); 052 at.addAttributes( att ); 053 expResult = " style=\"bold\" decoration=\"boxed\""; 054 result = SinkUtils.getAttributeString( at ); 055 assertEquals( expResult, result ); 056 057 att = new SinkEventAttributeSet( new String[] {"color", "red", "margin-left", "20px"} ); 058 059 at = new SinkEventAttributeSet(); 060 at.addAttribute( SinkEventAttributeSet.STYLE, att ); 061 expResult = " style=\"color: red; margin-left: 20px\""; 062 result = SinkUtils.getAttributeString( at ); 063 assertEquals( expResult, result ); 064 } 065 066 /** 067 * Test of filterAttributes method, of class SinkUtils. 068 */ 069 public void testFilterAttributes() 070 { 071 assertNull( SinkUtils.filterAttributes( null, null ) ); 072 073 AttributeSet attributes = new SinkEventAttributeSet( 1 ); 074 String[] valids = null; 075 076 MutableAttributeSet result = SinkUtils.filterAttributes( attributes, valids ); 077 assertEquals( 0, result.getAttributeCount() ); 078 079 valids = new String[] {}; 080 result = SinkUtils.filterAttributes( attributes, valids ); 081 assertEquals( 0, result.getAttributeCount() ); 082 083 result = SinkUtils.filterAttributes( SinkEventAttributeSet.BOLD, SinkUtils.SINK_BASE_ATTRIBUTES ); 084 assertEquals( 1, result.getAttributeCount() ); 085 086 result = SinkUtils.filterAttributes( SinkEventAttributeSet.CENTER, SinkUtils.SINK_BASE_ATTRIBUTES ); 087 assertEquals( 0, result.getAttributeCount() ); 088 } 089}