001 /*
002 * Copyright 2009 - 2010 JEuclid, http://jeuclid.sf.net
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 /* $Id: MultiAttributedCharacterIteratorTest.java,v 92b6a7c39d7f 2010/08/11 20:23:17 max $ */
018
019 package net.sourceforge.jeuclid.test;
020
021 import java.text.AttributedCharacterIterator;
022 import java.text.AttributedString;
023
024 import net.sourceforge.jeuclid.elements.support.text.MultiAttributedCharacterIterator;
025
026 import org.junit.Assert;
027 import org.junit.Test;
028
029 /**
030 * Tests {@link MultiAttributedCharacterIterator}.
031 *
032 * @version $Revision: 92b6a7c39d7f $
033 */
034 public class MultiAttributedCharacterIteratorTest {
035
036 /**
037 * test without attributes.
038 *
039 * @throws Exception
040 * if the tests fail.
041 */
042 @Test
043 public void testNoAttribs() throws Exception {
044 final AttributedString as1 = new AttributedString("Test");
045 final AttributedString as2 = new AttributedString("Cont");
046 final MultiAttributedCharacterIterator maci = new MultiAttributedCharacterIterator();
047 maci.appendAttributedCharacterIterator(as1.getIterator());
048 maci.appendAttributedCharacterIterator(as2.getIterator());
049
050 Assert.assertTrue(maci.getAllAttributeKeys().isEmpty());
051 Assert.assertTrue(maci.getAttributes().isEmpty());
052 Assert.assertEquals(maci.getEndIndex(), 8);
053
054 final AttributedCharacterIterator nac1 = new AttributedString(maci)
055 .getIterator();
056 final AttributedCharacterIterator nac2 = new AttributedString(
057 "TestCont").getIterator();
058
059 for (int i = nac1.getBeginIndex(); i < nac1.getEndIndex(); i++) {
060 nac1.setIndex(i);
061 nac2.setIndex(i);
062 Assert.assertEquals(nac1.current(), nac2.current());
063 }
064
065 }
066 }