package tests.com.ericfeminella.commons.collections
{
import com.ericfeminella.commons.collections.Iterator;
import com.ericfeminella.commons.collections.VectorIterator;
import org.flexunit.Assert;
public final class VectorIteratorTest
{
private var _vector:Vector.<PersonalName> = null;
private var _iterator:Iterator = null;
private static const JOHN:PersonalName = new PersonalName( "John", "Doe" );
private static const JANE:PersonalName = new PersonalName( "Jane", "Doe" );
[Before]
public function setUp() : void
{
_vector = new Vector.<PersonalName>();
_vector.push( JOHN );
_vector.push( JANE );
_iterator = new VectorIterator( _vector );
}
[Test]
public function testHasNext() : void
{
Assert.assertTrue( _iterator.hasNext() );
Assert.assertTrue( _iterator.hasNext() );
Assert.assertFalse( _iterator.hasNext() );
}
[Test]
public function testNext() : void
{
Assert.assertEquals( JOHN.toString(), _iterator.next().toString() );
Assert.assertEquals( JANE.toString(), _iterator.next().toString() );
}
[Test]
public function testReset() : void
{
while ( _iterator.hasNext() )
{
_iterator.next();
}
_iterator.reset();
Assert.assertEquals( JOHN.toString(), _iterator.next().toString() );
}
[Test]
public function testPosition() : void
{
Assert.assertEquals( 0, _iterator.position() );
_iterator.next();
Assert.assertEquals( 1, _iterator.position() );
}
[After]
public function tearDown() : void
{
_vector = null;
_iterator = null;
}
}
}
final class PersonalName
{
private var _givenname:String = null;
private var _surname:String = null;
public function PersonalName(givenname:String, surname:String)
{
_givenname = givenname;
_surname = surname;
}
public function toString() : String
{
return _surname + ", " + _givenname;
}
}