forked from richardlord/Ash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds withMethod to StateComponentMapping adds tests
- Loading branch information
1 parent
85d62f7
commit a0cb7b9
Showing
5 changed files
with
147 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* User: revisual.co.uk | ||
* Date: 16/04/13 | ||
* Time: 22:04 | ||
*/ | ||
package ash.fsm | ||
{ | ||
public class DynamicComponentProvider implements IComponentProvider | ||
{ | ||
private var _closure:Function; | ||
|
||
public function DynamicComponentProvider( closure:Function) | ||
{ | ||
_closure = closure; | ||
} | ||
|
||
public function getComponent():* | ||
{ | ||
return _closure(); | ||
} | ||
|
||
public function get identifier():* | ||
{ | ||
return _closure; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ash.fsm | ||
{ | ||
import org.hamcrest.assertThat; | ||
import org.hamcrest.core.not; | ||
import org.hamcrest.object.equalTo; | ||
import org.hamcrest.object.sameInstance; | ||
|
||
public class DynamicComponentProviderTests | ||
{ | ||
[Test] | ||
public function providerReturnsTheInstance():void | ||
{ | ||
var instance:MockComponent = new MockComponent(); | ||
var providerMethod:Function = function ():* | ||
{ | ||
return instance; | ||
} | ||
var provider:DynamicComponentProvider = new DynamicComponentProvider( providerMethod ); | ||
assertThat( provider.getComponent(), sameInstance( instance ) ); | ||
} | ||
|
||
[Test] | ||
public function providersWithSameMethodHaveSameIdentifier():void | ||
{ | ||
var instance:MockComponent = new MockComponent(); | ||
var providerMethod:Function = function ():* | ||
{ | ||
return instance; | ||
} | ||
|
||
var provider1:DynamicComponentProvider = new DynamicComponentProvider( providerMethod ); | ||
var provider2:DynamicComponentProvider = new DynamicComponentProvider( providerMethod ); | ||
assertThat( provider1.identifier, equalTo( provider2.identifier ) ); | ||
} | ||
|
||
[Test] | ||
public function providersWithDifferentMethodsHaveDifferentIdentifier():void | ||
{ | ||
var instance:MockComponent = new MockComponent(); | ||
var providerMethod1:Function = function ():* | ||
{ | ||
return instance; | ||
} | ||
|
||
var providerMethod2:Function = function ():* | ||
{ | ||
return instance; | ||
} | ||
|
||
var provider1:ComponentInstanceProvider = new ComponentInstanceProvider( providerMethod1 ); | ||
var provider2:ComponentInstanceProvider = new ComponentInstanceProvider( providerMethod2 ); | ||
assertThat( provider1.identifier, not( provider2.identifier ) ); | ||
} | ||
} | ||
} | ||
|
||
class MockComponent | ||
{ | ||
public var value:int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters