You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by la...@apache.org on 2012/04/10 05:07:54 UTC
svn commit: r1311563 - in
/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections:
./ tests/ tests/arrayCollection/ tests/arrayList/ tests/vectorList/
Author: labriola
Date: Tue Apr 10 03:07:54 2012
New Revision: 1311563
URL: http://svn.apache.org/viewvc?rev=1311563&view=rev
Log:
Added a series of tests for ArrayCollection and ArrayList
Added:
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayCollection/
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayCollection/BasicFunctionsTest.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/AddRemoveItemAtTest.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/AddRemoveItemTest.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ArrayListSuite.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/BasicFunctionsTest.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ConversionTest.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/EventsTest.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ItemRetrievalTest.as
Modified:
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/ArrayList.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/VectorList.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/CollectionTests.as
incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/vectorList/AddRemoveItemAtTest.as
Modified: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/ArrayList.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/ArrayList.as?rev=1311563&r1=1311562&r2=1311563&view=diff
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/ArrayList.as (original)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/ArrayList.as Tue Apr 10 03:07:54 2012
@@ -92,7 +92,7 @@ import mx.utils.UIDUtil;
public class ArrayList extends EventDispatcher
implements IList, IExternalizable, IPropertyChangeNotifier
{
- include "../core/Version.as";
+ //include "../core/Version.as";
//--------------------------------------------------------------------------
//
Modified: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/VectorList.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/VectorList.as?rev=1311563&r1=1311562&r2=1311563&view=diff
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/VectorList.as (original)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/VectorList.as Tue Apr 10 03:07:54 2012
@@ -397,7 +397,12 @@ public class VectorList extends EventDis
*/
public function removeItemAt(index:int):Object
{
- if (index < 0 || index >= length)
+ if ( fixedLengthVector ) {
+ //Make a message in manager
+ throw new RangeError( "Fixed Length Vector");
+ }
+
+ if (index < 0 || index >= length)
{
var message:String = resourceManager.getString(
"collections", "outOfBounds", [ index ]);
Modified: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/CollectionTests.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/CollectionTests.as?rev=1311563&r1=1311562&r2=1311563&view=diff
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/CollectionTests.as (original)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/CollectionTests.as Tue Apr 10 03:07:54 2012
@@ -2,6 +2,8 @@ package mx.collections.tests
{
import mx.collections.tests.vectorCollection.BasicFunctionsTest;
import mx.collections.tests.vectorList.VectorListSuite;
+ import mx.collections.tests.arrayCollection.BasicFunctionsTest;
+ import mx.collections.tests.arrayList.ArrayListSuite;
[Suite]
[RunWith("org.flexunit.runners.Suite")]
@@ -9,6 +11,8 @@ package mx.collections.tests
{
public var test1:mx.collections.tests.vectorCollection.BasicFunctionsTest;
public var test2:mx.collections.tests.vectorList.VectorListSuite;
+ public var test3:mx.collections.tests.arrayCollection.BasicFunctionsTest;
+ public var test4:mx.collections.tests.arrayList.ArrayListSuite;
}
}
\ No newline at end of file
Added: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayCollection/BasicFunctionsTest.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayCollection/BasicFunctionsTest.as?rev=1311563&view=auto
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayCollection/BasicFunctionsTest.as (added)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayCollection/BasicFunctionsTest.as Tue Apr 10 03:07:54 2012
@@ -0,0 +1,54 @@
+package mx.collections.tests.arrayCollection {
+ import mx.collections.ICollectionView;
+ import mx.collections.IList;
+ import mx.collections.ArrayCollection;
+ import mx.collections.ArrayList;
+
+ import org.flexunit.assertThat;
+ import org.flexunit.asserts.assertNull;
+ import org.hamcrest.object.instanceOf;
+ import org.hamcrest.object.sameInstance;
+
+ public class BasicFunctionsTest {
+
+ [Test]
+ public function shouldImplementICollectionView():void {
+ var collection:ArrayCollection = new ArrayCollection();
+ assertThat( collection, instanceOf( ICollectionView ) );
+ }
+
+ [Test]
+ public function instantiatingWithoutSourceShouldBuildOwnArrayList():void {
+ var collection:ArrayCollection = new ArrayCollection();
+
+ assertThat( collection.list, instanceOf( ArrayList ) );
+ }
+
+ [Test]
+ public function instantiatingWithArrayShouldYieldListWithArray():void {
+ var array:Array = [];
+ var collection:ArrayCollection = new ArrayCollection( array );
+
+ assertThat( array, sameInstance( ArrayList( collection.list ).source ) );
+ }
+
+ [Test]
+ public function sourceShouldReturnArrayListSourceWhenListViable():void {
+ var array:Array = [];
+ var collection:ArrayCollection = new ArrayCollection( array );
+
+ assertThat( array, sameInstance( collection.source ) );
+ }
+
+ [Test]
+ public function sourceShouldReturnNullWhenListIsNull():void {
+ var collection:ArrayCollection = new ArrayCollection();
+ collection.list = null;
+
+ assertNull( collection.source );
+ }
+
+ public function BasicFunctionsTest() {
+ }
+ }
+}
\ No newline at end of file
Added: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/AddRemoveItemAtTest.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/AddRemoveItemAtTest.as?rev=1311563&view=auto
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/AddRemoveItemAtTest.as (added)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/AddRemoveItemAtTest.as Tue Apr 10 03:07:54 2012
@@ -0,0 +1,124 @@
+package mx.collections.tests.arrayList {
+ import flash.events.EventDispatcher;
+
+ import mx.collections.ArrayList;
+ import mx.events.PropertyChangeEvent;
+
+ import org.flexunit.assertThat;
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertTrue;
+ import org.hamcrest.collection.hasItem;
+ import org.hamcrest.core.not;
+
+ public class AddRemoveItemAtTest {
+
+ [Test]
+ public function addItemAtShouldInsertElementIntoArray():void {
+ var array:Array = [ 7, 8, 9 ];
+ var arrayList:ArrayList = new ArrayList( array );
+ const value:int = 5;
+
+ arrayList.addItemAt( value, 2 );
+ assertEquals( 4, arrayList.length );
+ assertEquals( value, array[ 2 ] );
+ }
+
+ public function addItemAtShouldAddEventListenerForEventDispatchers():void {
+ const value:EventDispatcher = new EventDispatcher();
+ var array:Array = [value];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertFalse( value.hasEventListener( PropertyChangeEvent.PROPERTY_CHANGE ) );
+ arrayList.addItemAt( value, 0 );
+ assertTrue( value.hasEventListener( PropertyChangeEvent.PROPERTY_CHANGE ) );
+ }
+
+ [Test(expects="RangeError")]
+ public function shouldReceiveRangeErrorAttemptingToAddItemAtNegativeIndex():void {
+ var array:Array = [];
+ var arrayList:ArrayList = new ArrayList( array );
+ const value:int = 5;
+
+ arrayList.addItemAt( value, -1 );
+ }
+
+ [Test(expects="RangeError")]
+ public function shouldReceiveRangeErrorAttemptingToAddItemAtPastEndOfArray():void {
+ var array:Array = [];
+ var arrayList:ArrayList = new ArrayList( array );
+ const value:int = 5;
+
+ arrayList.addItemAt( value, 2 );
+ }
+
+ [Test]
+ public function removeItemAtShouldRemoveItemFromArray():void {
+ const value:int = 5;
+ var array:Array = [ value ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertThat( array, hasItem( value ) );
+
+ arrayList.removeItemAt( 0 );
+ assertThat( array, not( hasItem( value ) ) );
+ }
+
+ public function removeItemAtShouldRemoveEventListenerForEventDispatchers():void {
+ const value:EventDispatcher = new EventDispatcher();
+ var array:Array = [value];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertTrue( value.hasEventListener( PropertyChangeEvent.PROPERTY_CHANGE ) );
+ arrayList.removeItemAt( 0 );
+ assertFalse( value.hasEventListener( PropertyChangeEvent.PROPERTY_CHANGE ) );
+ }
+
+ [Test]
+ public function removeItemAtShouldRemoveReturnRemovedItem():void {
+ const value:int = 5;
+ var array:Array = [ value ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertEquals( value, arrayList.removeItemAt( 0 ) );
+ }
+
+ [Test]
+ public function removeItemAtShouldRemoveArbitraryNode():void {
+ const value:int = 5;
+ var array:Array = [ 3, 7, 9, value, 11, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertThat( array, hasItem( value ) );
+
+ arrayList.removeItemAt( 3 );
+
+ assertThat( array, not( hasItem( value ) ) );
+ }
+
+ [Test]
+ public function removeItemAtShouldRemoveLastNode():void {
+ const value:int = 5;
+ var array:Array = [ 3, 7, 9, 11, 13, value ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertThat( array, hasItem( value ) );
+
+ arrayList.removeItemAt( 5 );
+
+ assertThat( array, not( hasItem( value ) ) );
+ }
+
+ [Test(expects="RangeError")]
+ public function removeItemAtShouldThrowRangeErrorIfOutOfRangeIndexSupplied():void {
+ const value:int = 5;
+ var array:Array = [ value ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ arrayList.removeItemAt( 3 );
+ }
+
+ public function AddRemoveItemAtTest() {
+ }
+ }
+}
\ No newline at end of file
Added: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/AddRemoveItemTest.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/AddRemoveItemTest.as?rev=1311563&view=auto
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/AddRemoveItemTest.as (added)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/AddRemoveItemTest.as Tue Apr 10 03:07:54 2012
@@ -0,0 +1,121 @@
+package mx.collections.tests.arrayList {
+ import flash.display.Sprite;
+ import flash.events.EventDispatcher;
+
+ import mx.collections.ArrayList;
+
+ import org.flexunit.assertThat;
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertStrictlyEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.hamcrest.collection.hasItem;
+ import org.hamcrest.core.not;
+ import org.hamcrest.object.sameInstance;
+
+ public class AddRemoveItemTest {
+
+ private static const EMPTY:int = 0;
+
+ [Test]
+ public function addItemShouldAddFirstItemToEmptyArray():void {
+ var array:Array = [];
+ var arrayList:ArrayList = new ArrayList( array );
+ const value:int = 5;
+
+ assertThat( array, not( hasItem( value ) ) );
+
+ arrayList.addItem( value );
+ assertEquals( 1, arrayList.length );
+ assertThat( array, hasItem( value ) );
+ }
+
+ [Test]
+ public function addItemShouldAddLastItemToPopulatedArray():void {
+ var array:Array = [ 7, 8, 9 ];
+ var arrayList:ArrayList = new ArrayList( array );
+ const value:int = 5;
+
+ assertEquals( 3, arrayList.length );
+
+ arrayList.addItem( value );
+ assertEquals( 4, arrayList.length );
+ assertEquals( value, array[ 3 ] );
+ }
+
+ [Test]
+ public function removeItemShouldRemoveSimpleItemFromArray():void {
+ var array:Array = [];
+ var arrayList:ArrayList = new ArrayList( array );
+ const value:int = 5;
+
+ arrayList.addItem( value );
+ assertThat( array, hasItem( value ) );
+
+ arrayList.removeItem( value );
+ assertThat( array, not( hasItem( value ) ) );
+ }
+
+ [Test]
+ public function removeItemShouldRemoveSingleSimpleItemFromArray():void {
+ var array:Array = [];
+ var arrayList:ArrayList = new ArrayList( array );
+ const value:int = 5;
+
+ arrayList.addItem( value );
+ arrayList.addItem( value );
+ assertThat( array, hasItem( value ) );
+
+ arrayList.removeItem( value );
+ assertThat( array, hasItem( value ) );
+ assertEquals( 1, array.length );
+ }
+
+ [Test]
+ public function removeItemShouldRemoveComplexItemFromArray():void {
+ var array:Array = [];
+ var arrayList:ArrayList = new ArrayList( array );
+ const value:EventDispatcher = new EventDispatcher();
+
+ arrayList.addItem( value );
+ assertThat( array, hasItem( value ) );
+
+ arrayList.removeItem( value );
+ assertThat( array, not( hasItem( value ) ) );
+ }
+
+ [Test]
+ public function removeItemShouldRemoveReturnTrueIfItemFound():void {
+ var array:Array = [];
+ var arrayList:ArrayList = new ArrayList( array );
+ const value:EventDispatcher = new EventDispatcher();
+
+ arrayList.addItem( value );
+ assertTrue( arrayList.removeItem( value ) );
+ }
+
+ [Test]
+ public function removeItemShouldRemoveReturnFalseIfItemNotFound():void {
+ var array:Array = [];
+ var arrayList:ArrayList = new ArrayList( array );
+ const value:EventDispatcher = new EventDispatcher();
+
+ assertFalse( arrayList.removeItem( value ) );
+ }
+
+ [Test]
+ public function removeAllShouldEmptyArray():void {
+ var array:Array = [ 5, 7, 9, 11, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertEquals( 5, array.length );
+
+ arrayList.removeAll();
+
+ assertEquals( EMPTY, array.length );
+ }
+
+ public function AddRemoveItemTest() {
+ }
+ }
+}
\ No newline at end of file
Added: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ArrayListSuite.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ArrayListSuite.as?rev=1311563&view=auto
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ArrayListSuite.as (added)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ArrayListSuite.as Tue Apr 10 03:07:54 2012
@@ -0,0 +1,15 @@
+package mx.collections.tests.arrayList
+{
+
+ [Suite]
+ [RunWith("org.flexunit.runners.Suite")]
+ public class ArrayListSuite
+ {
+ public var test1:mx.collections.tests.arrayList.BasicFunctionsTest;
+ public var test2:mx.collections.tests.arrayList.AddRemoveItemTest;
+ public var test3:mx.collections.tests.arrayList.AddRemoveItemAtTest;
+ public var test4:mx.collections.tests.arrayList.ConversionTest;
+ public var test5:mx.collections.tests.arrayList.EventsTest;
+ public var test6:mx.collections.tests.arrayList.ItemRetrievalTest;
+ }
+}
\ No newline at end of file
Added: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/BasicFunctionsTest.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/BasicFunctionsTest.as?rev=1311563&view=auto
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/BasicFunctionsTest.as (added)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/BasicFunctionsTest.as Tue Apr 10 03:07:54 2012
@@ -0,0 +1,121 @@
+package mx.collections.tests.arrayList {
+ import mx.collections.ArrayList;
+ import mx.collections.IList;
+ import mx.core.IPropertyChangeNotifier;
+
+ import org.flexunit.assertThat;
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertFalse;
+ import org.flexunit.asserts.assertNotNull;
+ import org.flexunit.asserts.assertStrictlyEquals;
+ import org.flexunit.asserts.assertTrue;
+ import org.hamcrest.collection.hasItem;
+ import org.hamcrest.core.not;
+ import org.hamcrest.object.instanceOf;
+
+ public class BasicFunctionsTest {
+
+ private static const EMPTY:int = 0;
+
+ [Test]
+ public function shouldImplementIList():void {
+ var arrayList:ArrayList = new ArrayList( null );
+ assertThat( arrayList, instanceOf( IList ) );
+ }
+
+ [Test]
+ public function shouldImplementIPropertyChangeNotifier():void {
+ var arrayList:ArrayList = new ArrayList( null );
+ assertThat( arrayList, instanceOf( IPropertyChangeNotifier ) );
+ }
+
+ [Test]
+ public function lengthShouldBeEmptyWithNullSource():void {
+ var arrayList:ArrayList = new ArrayList( null );
+ assertEquals( EMPTY, arrayList.length );
+ }
+
+ [Test]
+ public function lengthShouldBeEmptyWhenEmptyVectorProvided():void {
+ var arrayList:ArrayList = new ArrayList( [] );
+ assertEquals( EMPTY, arrayList.length );
+ }
+
+ [Test]
+ public function lengthShouldBe1WhenVectorLength1Provided():void {
+ var arrayList:ArrayList = new ArrayList( [1] );
+ assertEquals( 1, arrayList.length );
+ }
+
+ [Test]
+ public function sourcePropertyShouldBeStrictlyEqualToProvidedVector():void {
+ var array:Array = [];
+ var arrayList:ArrayList = new ArrayList( array );
+ assertStrictlyEquals( array, arrayList.source );
+ }
+
+ [Test]
+ public function shouldSetUIDAtConstruction():void {
+ var arrayList:ArrayList = new ArrayList( [] );
+
+ assertNotNull( arrayList.uid );
+ assertTrue( arrayList.uid.length > 0 );
+ }
+
+ [Test]
+ public function multipleArrayListsShouldNotShareAUID():void {
+ var arrayList1:ArrayList = new ArrayList();
+ var arrayList2:ArrayList = new ArrayList();
+ var arrayList3:ArrayList = new ArrayList();
+
+ assertTrue( arrayList1.uid != arrayList2.uid );
+ assertTrue( arrayList2.uid != arrayList3.uid );
+ assertTrue( arrayList1.uid != arrayList3.uid );
+ }
+
+ [Test]
+ public function shouldBeAbleToSetUID():void {
+ const newUID:String = "3.14159265358";
+ var arrayList:ArrayList = new ArrayList();
+
+ assertFalse( arrayList.uid == newUID );
+
+ arrayList.uid = newUID;
+ assertTrue( arrayList.uid == newUID );
+ }
+
+ [Test]
+ public function setItemAtShouldUpdateValueAtPosition():void {
+ const value:int = 5;
+ const position:int = 2;
+ var array:Array = [ 3, 7, 9, 11, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertThat( array, not( hasItem( value ) ) );
+ arrayList.setItemAt( value, position );
+ assertThat( array, hasItem( value ) );
+ assertEquals( value, array[ position ] );
+ }
+
+ [Test]
+ public function setItemAtShouldReturnOldValueWhenSettingNewValue():void {
+ const newValue:int = 5;
+ const oldValue:int = 9;
+ const position:int = 2;
+ var array:Array = [ 3, 7, oldValue, 11, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertEquals( oldValue, arrayList.setItemAt( newValue, position ) );
+ }
+
+ [Test(expects="RangeError")]
+ public function setItemAtShouldThrowRangeErrorForOutOfBoundsIndex():void {
+ const value:int = 100;
+ const position:int = 2;
+ var array:Array = [ 3 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ arrayList.setItemAt( value, position );
+ }
+ }
+}
\ No newline at end of file
Added: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ConversionTest.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ConversionTest.as?rev=1311563&view=auto
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ConversionTest.as (added)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ConversionTest.as Tue Apr 10 03:07:54 2012
@@ -0,0 +1,34 @@
+package mx.collections.tests.arrayList {
+
+ import mx.collections.ArrayList;
+
+ import org.flexunit.assertThat;
+ import org.flexunit.asserts.assertEquals;
+ import org.hamcrest.object.equalTo;
+
+ public class ConversionTest {
+ [Test]
+ public function toStringMethodShouldBeArrayToStringWhenProvidedArray():void {
+ var array:Array = [ 5, 4, 3, 1, 2, 5 ];
+ var arrayList:ArrayList = new ArrayList( array );
+ assertEquals( array.toString(), arrayList.toString() );
+ }
+
+ [Test]
+ public function toStringShouldBeEmptyStringWithNullSource():void {
+ var arrayList:ArrayList = new ArrayList( null );
+ assertEquals( "", arrayList.toString() );
+ }
+
+ [Test]
+ public function toArrayShouldReturnArrayWithSameElementsAsArray():void {
+ var array:Array = [ 5, 4, "3", 1, "Bob", 5 ];
+ var arrayList:ArrayList = new ArrayList( array );
+ assertThat( arrayList.toArray(), equalTo( array ) );
+ }
+
+ public function ConversionTest() {
+ }
+ }
+
+}
\ No newline at end of file
Added: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/EventsTest.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/EventsTest.as?rev=1311563&view=auto
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/EventsTest.as (added)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/EventsTest.as Tue Apr 10 03:07:54 2012
@@ -0,0 +1,396 @@
+package mx.collections.tests.arrayList {
+ import flash.events.EventDispatcher;
+
+ import mx.collections.ArrayList;
+ import mx.events.CollectionEvent;
+ import mx.events.CollectionEventKind;
+ import mx.events.PropertyChangeEvent;
+ import mx.events.PropertyChangeEventKind;
+
+ import org.flexunit.events.rule.EventRule;
+ import org.hamcrest.collection.arrayWithSize;
+ import org.hamcrest.collection.hasItem;
+ import org.hamcrest.core.allOf;
+ import org.hamcrest.object.hasPropertyWithValue;
+ import org.hamcrest.object.instanceOf;
+
+ public class EventsTest {
+
+ [Rule]
+ public var expectEvent:EventRule = new EventRule();
+
+ [Test]
+ public function shouldReceiveCollectionResetWhenSettingSourceToValidValue():void {
+ var arrayList:ArrayList = new ArrayList();
+
+ expectEvent.from( arrayList ).
+ hasType( CollectionEvent.COLLECTION_CHANGE ).
+ instanceOf( CollectionEvent ).
+ hasPropertyWithValue( "kind", CollectionEventKind.RESET ).
+ once();
+
+ arrayList.source = [ 1, 2, 3, 4 ];
+ }
+
+ [Test]
+ public function shouldReceiveCollectionResetWhenSettingSourceToNull():void {
+ var arrayList:ArrayList = new ArrayList();
+
+ expectEvent.from( arrayList ).
+ hasType( CollectionEvent.COLLECTION_CHANGE ).
+ instanceOf( CollectionEvent ).
+ hasPropertyWithValue( "kind", CollectionEventKind.RESET ).
+ once();
+
+ arrayList.source = null;
+ }
+
+ [Test]
+ public function shouldReceiveCollectionEventWhenAddingItem():void {
+ const value:int = 5;
+ var arrayList:ArrayList = new ArrayList( [ 1, 2, 3, 4 ] );
+
+ expectEvent.from( arrayList ).
+ hasType( CollectionEvent.COLLECTION_CHANGE ).
+ instanceOf( CollectionEvent ).
+ hasPropertyWithValue( "kind", CollectionEventKind.ADD ).
+ hasPropertyWithValue( "items", allOf( arrayWithSize( 1 ), hasItem( value ) ) ).
+ once();
+
+ arrayList.addItem( value );
+ }
+
+ [Test]
+ public function shouldReceivePropertyChangeEventWhenAddingItem():void {
+ const value:int = 5;
+ var index:int = 0;
+ var arrayList:ArrayList = new ArrayList( [ 1, 2, 3, 4 ] );
+
+ index = arrayList.length;
+
+ expectEvent.from( arrayList ).
+ hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
+ instanceOf( PropertyChangeEvent ).
+ hasPropertyWithValue( "property", index ).
+ hasPropertyWithValue( "newValue", value ).
+ once();
+
+ arrayList.addItem( value );
+ }
+
+ [Test]
+ public function shouldReceiveCollectionEventWhenAddingItemAtIndex():void {
+ const value:int = 5;
+ const index:int = 2;
+ var arrayList:ArrayList = new ArrayList( [ 1, 2, 3, 4 ] );
+
+ expectEvent.from( arrayList ).
+ hasType( CollectionEvent.COLLECTION_CHANGE ).
+ instanceOf( CollectionEvent ).
+ hasPropertyWithValue( "kind", CollectionEventKind.ADD ).
+ hasPropertyWithValue( "items", allOf( arrayWithSize( 1 ), hasItem( value ) ) ).
+ once();
+
+ arrayList.addItemAt( value, index );
+ }
+
+ [Test]
+ public function shouldReceivePropertyChangeEventWhenAddingItemAtIndex():void {
+ const value:int = 5;
+ const index:int = 2;
+ var arrayList:ArrayList = new ArrayList( [ 1, 2, 3, 4 ] );
+
+ expectEvent.from( arrayList ).
+ hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
+ instanceOf( PropertyChangeEvent ).
+ hasPropertyWithValue( "property", index ).
+ hasPropertyWithValue( "newValue", value ).
+ once();
+
+ arrayList.addItemAt( value, index );
+ }
+
+ [Test]
+ public function childPropertyChangeEventsShouldPropagateWhenAddedToArrayList():void {
+ const index:uint = 1;
+ const propertyName:String = "dummy";
+ const propertyOldVal:String = "dummyOldVal";
+ const propertyNewVal:String = "dummyNewVal";
+
+ var array:Array = [];
+ var eventDispatcher:EventDispatcher = new EventDispatcher();
+ var arrayList:ArrayList = new ArrayList( array );
+
+ arrayList.addItem( new EventDispatcher() );
+ arrayList.addItemAt( eventDispatcher, index );
+
+ expectEvent.from( arrayList ).
+ hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
+ instanceOf( PropertyChangeEvent ).
+ hasPropertyWithValue( "kind", PropertyChangeEventKind.UPDATE ).
+ hasPropertyWithValue( "newValue", propertyNewVal ).
+ hasPropertyWithValue( "oldValue", propertyOldVal ).
+ hasPropertyWithValue( "property", index + '.' + propertyName ).
+ hasPropertyWithValue( "source", eventDispatcher ).
+ once();
+
+ eventDispatcher.dispatchEvent( PropertyChangeEvent.createUpdateEvent( eventDispatcher, propertyName , propertyOldVal, propertyNewVal ) );
+ }
+
+ [Test]
+ public function childPropertyChangeEventsShouldStopPropagatingWhenRemovedFromArrayList():void {
+ const index:uint = 1;
+ const propertyName:String = "dummy";
+ const propertyOldVal:String = "dummyOldVal";
+ const propertyNewVal:String = "dummyNewVal";
+
+ var array:Array = [];
+ var eventDispatcher:EventDispatcher = new EventDispatcher();
+ var arrayList:ArrayList = new ArrayList( array );
+
+ arrayList.addItem( new EventDispatcher() );
+ arrayList.addItemAt( eventDispatcher, index );
+ arrayList.removeItemAt( index );
+
+ expectEvent.from( arrayList ).
+ hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
+ never();
+
+ eventDispatcher.dispatchEvent( PropertyChangeEvent.createUpdateEvent( eventDispatcher, propertyName , propertyOldVal, propertyNewVal ) );
+ }
+
+ [Test(description="This is an example of a test that codifies existing behavior, but it may be WRONG behavior")]
+ public function collectChangeEventsShouldBeReceivedWhenChildPropertyChangeEventOccurs():void {
+ const propertyName:String = "dummy";
+ const propertyOldVal:String = "dummyOldVal";
+ const propertyNewVal:String = "dummyNewVal";
+
+ var array:Array = [];
+ var eventDispatcher:EventDispatcher = new EventDispatcher();
+ var arrayList:ArrayList = new ArrayList( array );
+
+ arrayList.addItem( eventDispatcher );
+
+ expectEvent.from( arrayList ).
+ hasType( CollectionEvent.COLLECTION_CHANGE ).
+ instanceOf( CollectionEvent ).
+ hasPropertyWithValue( "kind", CollectionEventKind.UPDATE ).
+ hasPropertyWithValue( "location", -1 ).
+ hasPropertyWithValue( "oldLocation", -1 ).
+ once();
+
+ eventDispatcher.dispatchEvent( PropertyChangeEvent.createUpdateEvent( eventDispatcher, propertyName , propertyOldVal, propertyNewVal ) );
+ }
+
+ [Test]
+ public function childPropertyChangeEventsShouldPropagateWhenAddedViaSourceToArrayList():void {
+ const index:uint = 1;
+ const propertyName:String = "dummy";
+ const propertyOldVal:String = "dummyOldVal";
+ const propertyNewVal:String = "dummyNewVal";
+
+ var array:Array = [];
+ var eventDispatcher:EventDispatcher = new EventDispatcher();
+ array.push( new EventDispatcher() );
+ array.push( eventDispatcher );
+
+ var arrayList:ArrayList = new ArrayList( array );
+
+ expectEvent.from( arrayList ).
+ hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
+ instanceOf( PropertyChangeEvent ).
+ hasPropertyWithValue( "kind", PropertyChangeEventKind.UPDATE ).
+ hasPropertyWithValue( "newValue", propertyNewVal ).
+ hasPropertyWithValue( "oldValue", propertyOldVal ).
+ hasPropertyWithValue( "property", index + '.' + propertyName ).
+ hasPropertyWithValue( "source", eventDispatcher ).
+ once();
+
+ eventDispatcher.dispatchEvent( PropertyChangeEvent.createUpdateEvent( eventDispatcher, propertyName , propertyOldVal, propertyNewVal ) );
+ }
+
+ [Test]
+ public function childPropertyChangeEventsShouldStopPropagatingWhenRemovedViaSourceFromArrayList():void {
+ const index:uint = 1;
+ const propertyName:String = "dummy";
+ const propertyOldVal:String = "dummyOldVal";
+ const propertyNewVal:String = "dummyNewVal";
+
+ var array:Array = [];
+ var eventDispatcher:EventDispatcher = new EventDispatcher();
+ array.push( new EventDispatcher() );
+ array.push( eventDispatcher );
+
+ var arrayList:ArrayList = new ArrayList( array );
+ arrayList.source = new Array();
+
+ expectEvent.from( arrayList ).
+ hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
+ never();
+
+ eventDispatcher.dispatchEvent( PropertyChangeEvent.createUpdateEvent( eventDispatcher, propertyName , propertyOldVal, propertyNewVal ) );
+ }
+
+ [Test(description="This test relies upon the patched version of ArrayList in my whiteboard")]
+ public function itemUpdatedShouldDispatchPropertyChangeEvent():void {
+ const propertyName:String = "dummy";
+ const propertyOldVal:String = "dummyOldVal";
+ const propertyNewVal:String = "dummyNewVal";
+
+ var array:Array = [];
+ var eventDispatcher:EventDispatcher = new EventDispatcher();
+ var arrayList:ArrayList = new ArrayList( array );
+
+ arrayList.addItem( eventDispatcher );
+
+ expectEvent.from( arrayList ).
+ hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
+ instanceOf( PropertyChangeEvent ).
+ hasPropertyWithValue( "kind", PropertyChangeEventKind.UPDATE ).
+ hasPropertyWithValue( "newValue", propertyNewVal ).
+ hasPropertyWithValue( "oldValue", propertyOldVal ).
+ hasPropertyWithValue( "property", "-1" + '.' + propertyName ).
+ hasPropertyWithValue( "source", eventDispatcher ).
+ once();
+
+ arrayList.itemUpdated( eventDispatcher, propertyName, propertyOldVal, propertyNewVal );
+ }
+
+ [Test(description="We should really consider if this is the behavior we want here.")]
+ public function itemUpdatedShouldDispatchCollectionChangeEvent():void {
+ const propertyName:String = "dummy";
+ const propertyOldVal:String = "dummyOldVal";
+ const propertyNewVal:String = "dummyNewVal";
+
+ var array:Array = [];
+ var eventDispatcher:EventDispatcher = new EventDispatcher();
+ var arrayList:ArrayList = new ArrayList( array );
+
+ arrayList.addItem( eventDispatcher );
+
+ expectEvent.from( arrayList ).
+ hasType( CollectionEvent.COLLECTION_CHANGE ).
+ instanceOf( CollectionEvent ).
+ hasPropertyWithValue( "kind", CollectionEventKind.UPDATE ).
+ hasPropertyWithValue( "location", -1 ).
+ hasPropertyWithValue( "oldLocation", -1 ).
+ once();
+
+ arrayList.itemUpdated( eventDispatcher, propertyName, propertyOldVal, propertyNewVal );
+ }
+
+ [Test]
+ public function removeAllShouldDispatchResetEvent():void {
+ var array:Array = [ 5, 7, 9, 11, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ expectEvent.from( arrayList ).
+ hasType( CollectionEvent.COLLECTION_CHANGE ).
+ instanceOf( CollectionEvent ).
+ hasPropertyWithValue( "kind", CollectionEventKind.RESET ).
+ hasPropertyWithValue( "location", -1 ).
+ hasPropertyWithValue( "oldLocation", -1 ).
+ once();
+
+ arrayList.removeAll();
+ }
+
+ [Test]
+ public function removeItemAtShouldDispatchCollectionRemoveEvent():void {
+ const position:int = 3;
+ const value:int = 11;
+ var array:Array = [ 5, 7, 9, value, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ expectEvent.from( arrayList ).
+ hasType( CollectionEvent.COLLECTION_CHANGE ).
+ instanceOf( CollectionEvent ).
+ hasPropertyWithValue( "kind", CollectionEventKind.REMOVE ).
+ hasPropertyWithValue( "location", position ).
+ hasPropertyWithValue( "items", allOf( arrayWithSize( 1 ), hasItem( value ) ) ).
+ once();
+
+ arrayList.removeItemAt( position );
+ }
+
+ [Test]
+ public function removeItemAtShouldDispatchPropertyChangeEvent():void {
+ const position:int = 3;
+ const value:int = 11;
+ var array:Array = [ 5, 7, 9, value, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ expectEvent.from( arrayList ).
+ hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
+ instanceOf( PropertyChangeEvent ).
+ hasPropertyWithValue( "oldValue", value ).
+ hasPropertyWithValue( "property", position ).
+ once();
+
+ arrayList.removeItemAt( position );
+ }
+
+ [Test]
+ public function addItemAtShouldDispatchPropertyChangeEvent():void {
+ const position:int = 3;
+ const value:int = 11;
+ var array:Array = [ 5, 7, 9, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ expectEvent.from( arrayList ).
+ hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
+ instanceOf( PropertyChangeEvent ).
+ hasPropertyWithValue( "newValue", value ).
+ hasPropertyWithValue( "property", position ).
+ once();
+
+ arrayList.addItemAt( value, position );
+ }
+
+ [Test]
+ public function setItemAtShouldDispatchPropertyChangeEvent():void {
+ const position:int = 2;
+ const oldValue:int = 11;
+ const newValue:int = 11;
+ var array:Array = [ 5, 7, oldValue, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ expectEvent.from( arrayList ).
+ hasType( PropertyChangeEvent.PROPERTY_CHANGE ).
+ instanceOf( PropertyChangeEvent ).
+ hasPropertyWithValue( "oldValue", oldValue ).
+ hasPropertyWithValue( "newValue", newValue ).
+ hasPropertyWithValue( "property", position ).
+ once();
+
+ arrayList.setItemAt( newValue, position );
+ }
+
+ [Test]
+ public function setItemAtShouldDispatchCollectionRemoveEvent():void {
+ const position:int = 2;
+ const oldValue:int = 11;
+ const newValue:int = 11;
+ var array:Array = [ 5, 7, oldValue, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ expectEvent.from( arrayList ).
+ hasType( CollectionEvent.COLLECTION_CHANGE ).
+ instanceOf( CollectionEvent ).
+ hasPropertyWithValue( "kind", CollectionEventKind.REPLACE ).
+ hasPropertyWithValue( "location", position ).
+ hasPropertyWithValue( "items", allOf( arrayWithSize( 1 ),
+ hasItem( allOf( instanceOf( PropertyChangeEvent ),
+ hasPropertyWithValue( "oldValue", oldValue ),
+ hasPropertyWithValue( "newValue", newValue ),
+ hasPropertyWithValue( "property", position ) ) ) ) ).
+ once();
+
+ arrayList.setItemAt( newValue, position );
+ }
+
+
+ public function EventsTest() {
+ }
+ }
+}
\ No newline at end of file
Added: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ItemRetrievalTest.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ItemRetrievalTest.as?rev=1311563&view=auto
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ItemRetrievalTest.as (added)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/arrayList/ItemRetrievalTest.as Tue Apr 10 03:07:54 2012
@@ -0,0 +1,103 @@
+package mx.collections.tests.arrayList {
+ import flash.events.EventDispatcher;
+
+ import mx.collections.ArrayList;
+
+ import org.flexunit.asserts.assertEquals;
+
+ public class ItemRetrievalTest {
+
+ [Test]
+ public function getItemAtShouldReturnValueFirstIndex():void {
+ const position:int = 0;
+ const value:int = 11;
+ var array:Array = [ value, 5, 7, 9, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertEquals( value, arrayList.getItemAt( position ) );
+ }
+
+ [Test]
+ public function getItemAtShouldReturnValueFromArbitraryIndex():void {
+ const position:int = 3;
+ const value:int = 11;
+ var array:Array = [ 5, 7, 9, value, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertEquals( value, arrayList.getItemAt( position ) );
+ }
+
+ [Test]
+ public function getItemAtShouldReturnValueLastIndex():void {
+ const position:int = 3;
+ const value:int = 11;
+ var array:Array = [ 5, 7, 9, value ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertEquals( value, arrayList.getItemAt( position ) );
+ }
+
+ [Test(expects="RangeError")]
+ public function shouldThrowRangeErrorForInvalidIndex():void {
+ const position:int = 3;
+ const value:int = 11;
+ var array:Array = [ value ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ arrayList.getItemAt( position );
+ }
+
+ [Test]
+ public function getItemIndexSimpleValueAtFirstPosition():void {
+ const position:int = 0;
+ const value:int = 11;
+ var array:Array = [ value, 5, 7, 9, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertEquals( position, arrayList.getItemIndex( value ) );
+ }
+
+ [Test]
+ public function getItemIndexSimpleValueAtArbitraryPosition():void {
+ const position:int = 3;
+ const value:int = 11;
+ var array:Array = [ 5, 7, 9, value, 13 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertEquals( position, arrayList.getItemIndex( value ) );
+ }
+
+ [Test]
+ public function getItemIndexSimpleValueAtLastPosition():void {
+ const position:int = 3;
+ const value:int = 11;
+ var array:Array = [ 5, 7, 9, value ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertEquals( position, arrayList.getItemIndex( value ) );
+ }
+
+ [Test]
+ public function getItemIndexNotFound():void {
+ const position:int = -1;
+ const value:int = 11;
+ var array:Array = [ 5, 7, 9 ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertEquals( position, arrayList.getItemIndex( value ) );
+ }
+
+ [Test]
+ public function getItemIndexComplexValue():void {
+ const position:int = 1;
+ const value:EventDispatcher = new EventDispatcher();
+ var array:Array = [ new EventDispatcher(), value, new EventDispatcher() ];
+ var arrayList:ArrayList = new ArrayList( array );
+
+ assertEquals( position, arrayList.getItemIndex( value ) );
+ }
+
+ public function ItemRetrievalTest() {
+ }
+ }
+}
\ No newline at end of file
Modified: incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/vectorList/AddRemoveItemAtTest.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/vectorList/AddRemoveItemAtTest.as?rev=1311563&r1=1311562&r2=1311563&view=diff
==============================================================================
--- incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/vectorList/AddRemoveItemAtTest.as (original)
+++ incubator/flex/whiteboard/labriola/frameworks/projects/framework/src/mx/collections/tests/vectorList/AddRemoveItemAtTest.as Tue Apr 10 03:07:54 2012
@@ -60,7 +60,15 @@ package mx.collections.tests.vectorList
vectorList.addItemAt( value, 0 );
}
-
+
+ [Test(expects="RangeError")]
+ public function shouldReceiveErrorAttemptingToRemoveItemAtToFixedLengthVector():void {
+ var vector:Vector.<int> = new Vector.<int>( 1, true );
+ var vectorList:VectorList = new VectorList( vector );
+
+ vectorList.removeItemAt( 0 );
+ }
+
[Test]
public function removeItemAtShouldRemoveItemFromVector():void {
const value:int = 5;