1 package org.apache.maven.doxia.index; 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 junit.framework.TestCase; 23 24 /** 25 * @author <a href="mailto:trygve.laugstol@objectware.no">Trygve Laugstøl</a> 26 * @version $Id: IndexEntryTest.java 1172204 2011-09-18 06:46:17Z hboutemy $ 27 */ 28 public class IndexEntryTest 29 extends TestCase 30 { 31 /** 32 * Test IndexEntry. 33 */ 34 public void testIndexEntry() 35 { 36 IndexEntry root = new IndexEntry( null ); 37 38 assertIndexEntry( root, null, 0, null, null ); 39 40 // ----------------------------------------------------------------------- 41 // Chapter 1 42 // ----------------------------------------------------------------------- 43 44 IndexEntry chapter1 = new IndexEntry( root, "chapter-1" ); 45 46 assertIndexEntry( root, null, 1, null, null ); 47 48 assertIndexEntry( chapter1, root, 0, null, null ); 49 50 // ----------------------------------------------------------------------- 51 // Chapter 2 52 // ----------------------------------------------------------------------- 53 54 IndexEntry chapter2 = new IndexEntry( root, "chapter-2" ); 55 56 assertIndexEntry( root, null, 2, null, null ); 57 58 assertIndexEntry( chapter1, root, 0, null, chapter2 ); 59 assertIndexEntry( chapter2, root, 0, chapter1, null ); 60 61 chapter2.setTitle( "Title 2" ); 62 assertTrue( chapter2.toString().contains( "Title 2" ) ); 63 } 64 65 private void assertIndexEntry( IndexEntry entry, IndexEntry parent, int childCount, 66 IndexEntry prevEntry, IndexEntry nextEntry ) 67 { 68 assertEquals( parent, entry.getParent() ); 69 70 assertEquals( childCount, entry.getChildEntries().size() ); 71 72 assertEquals( prevEntry, entry.getPrevEntry() ); 73 74 assertEquals( nextEntry, entry.getNextEntry() ); 75 } 76 }