Package org.jostraca.section.test

Source Code of org.jostraca.section.test.SectionSetTest

/*
* Name:    SectionSetTest
* Authors: Richard Rodger
* Release: 0.3
*
* Copyright (c) 2001-2002 Richard Rodger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/


// package
package org.jostraca.section.test;


/* Import << */
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

import org.jostraca.section.Section;
import org.jostraca.section.SectionSet;
import org.jostraca.section.BasicSection;
/* Import >> */


/** <b>Description:</b><br>
*  Test cases for SectionSet
*/
public class SectionSetTest extends TestCase {

  public SectionSetTest( String pName ) {
    super( pName );
  }

  public static TestSuite suite() {
    return new TestSuite( SectionSetTest.class );
  }

  public static void main( String[] pArgs ) {
    TestRunner.run( suite() );
  }


  public void testBasic() {

    String  s1_name  = "s1_name";
    String  s1_text1 = "s1_text1 ";
    Section s1       = (Section)( new BasicSection( s1_name ) );
    String  s2_name  = "s2_name";
    Section s2       = (Section)( new BasicSection( s2_name ) );

    assertEquals( s1, s1 );

    SectionSet ss = new SectionSet();
    ss.addSection( s1 );
    assertTrue( ss.hasSection(s1_name) );
    assertTrue( !ss.hasSection(s2_name) );
    assertTrue( !ss.hasSection(null) );
    assertTrue( s1_name.equals( ss.getSection(s1_name).getName() ) );

    assertTrue( ss.isEmptySection(s1_name) );

    ss.appendToSection( s1_name, s1_text1 );
    assertTrue( !ss.isEmptySection( s1_name ) );

    ss.addSection( s2 );
    assertTrue( ss.hasSection(s2_name) );

    assertEquals( ss, ss );
  }


  public void testAddSection() {
    Section    s1  = new BasicSection( "s1" );
    SectionSet ss1 = new SectionSet();
    ss1.addSection( s1 );
    assertTrue( ss1.hasSection( "s1" ) );
    assertTrue( !ss1.hasSection( "s2" ) );
  }


  public void testHasSection() {
    Section    s1  = new BasicSection( "s1" );
    SectionSet ss1 = new SectionSet();
    ss1.addSection( s1 );
    assertTrue( ss1.hasSection( "s1" ) );
    assertTrue( !ss1.hasSection( "s2" ) );
    assertTrue( !ss1.hasSection( null ) );
  }


  public void appendToSection() {
    Section    s1  = new BasicSection( "s1" );
    SectionSet ss1 = new SectionSet();
    ss1.addSection( s1 );
    ss1.appendToSection( "s1", "a" );
    assertTrue( ss1.hasSection( "s1" ) );
    assertEquals( "a", ss1.getSection( "s1").getContent() );
    ss1.appendToSection( "s1", "b" );
    assertEquals( "ab", ss1.getSection( "s1").getContent() );
  }


  public void testClearSection() {
    Section    s1  = new BasicSection( "s1" );
    SectionSet ss1 = new SectionSet();
    ss1.addSection( s1 );
    ss1.appendToSection( "s1", "a" );
    assertTrue( ss1.hasSection( "s1" ) );
    assertEquals( "a", ss1.getSection( "s1").getContent() );
    ss1.clearSection( "s1" );
    assertEquals( "", ss1.getSection( "s1").getContent() );
  }


  public void testClearAllSections() {
    Section    s1  = new BasicSection( "s1" );
    Section    s2  = new BasicSection( "s2" );
    SectionSet ss1 = new SectionSet();
    ss1.addSection( s1 );
    ss1.appendToSection( "s1", "1" );
    ss1.appendToSection( "s2", "2" );
    assertTrue( ss1.hasSection( "s1" ) );
    assertTrue( ss1.hasSection( "s2" ) );
    assertEquals( "1", ss1.getSection( "s1").getContent() );
    assertEquals( "2", ss1.getSection( "s2").getContent() );
    ss1.clearAllSections();
    assertEquals( "", ss1.getSection( "s1").getContent() );
    assertEquals( "", ss1.getSection( "s2").getContent() );
  }


  public void testGetSection() {
    Section    s1  = new BasicSection( "s1" );
    SectionSet ss1 = new SectionSet();
    ss1.addSection( s1 );
    assertTrue( ss1.hasSection( "s1" ) );
    assertEquals( s1, ss1.getSection( "s1" ) );
    assertEquals( "", ss1.getSection( "s2" ).getContent() );
  }


  public void isEmptySection() {
    Section    s1  = new BasicSection( "s1" );
    SectionSet ss1 = new SectionSet();
    ss1.addSection( s1 );
    assertTrue( ss1.isEmptySection( "s1" ) );
    ss1.appendToSection( "s1", "a" );
    assertTrue( !ss1.isEmptySection( "s1" ) );
    ss1.clearSection( "s1" );
    assertTrue( ss1.isEmptySection( "s1" ) );
    assertTrue( ss1.isEmptySection( "s2" ) );
  }


  public void testEquality() {
    Section s1a = new BasicSection( "s1" ); s1a.setContent( "s1" );
    Section s1b = new BasicSection( "s1" ); s1b.setContent( "s1" );
    assertEquals( s1a, s1b );

    Section s2a = new BasicSection( "s2" ); s2a.setContent( "s2" );
    Section s2b = new BasicSection( "s2" ); s2b.setContent( "s2" );
    assertEquals( s2a, s2b );

    assertTrue( !s1a.equals(s2a) );
    assertTrue( !s1b.equals(s2b) );

    SectionSet ss1 = new SectionSet();
    ss1.addSection( s1a );
    ss1.addSection( s1b );

    SectionSet ss2 = new SectionSet();

    assertTrue( !ss1.equals(ss2) );

    ss2.addSection( s1a );
    ss2.addSection( s1b );

    assertEquals( ss1, ss2 );
  }

}




TOP

Related Classes of org.jostraca.section.test.SectionSetTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.