Skip to content

Commit

Permalink
Minor changes for clarity and few tests added
Browse files Browse the repository at this point in the history
renamed injector to sandboxedInjector in DirectCommandMap for clarity

tests payload leakage in commands

moves NullCommandTrigger to command center
  • Loading branch information
creynders committed Apr 11, 2013
1 parent 0d686c3 commit 44b074e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// in accordance with the terms of the license agreement accompanying it.
//------------------------------------------------------------------------------

package robotlegs.bender.extensions.directCommandMap.impl
package robotlegs.bender.extensions.commandCenter.impl
{
import robotlegs.bender.extensions.commandCenter.api.ICommandTrigger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package robotlegs.bender.extensions.directCommandMap.impl
import robotlegs.bender.extensions.directCommandMap.api.IDirectCommandMap;
import robotlegs.bender.extensions.directCommandMap.dsl.IDirectCommandConfigurator;
import robotlegs.bender.framework.api.IContext;
import robotlegs.bender.extensions.commandCenter.impl.NullCommandTrigger;

public class DirectCommandMap implements IDirectCommandMap
{
Expand All @@ -40,10 +41,10 @@ package robotlegs.bender.extensions.directCommandMap.impl
public function DirectCommandMap(context:IContext)
{
_context = context;
var injector:Injector = context.injector.createChildInjector();
injector.map(IDirectCommandMap).toValue(this);
var sandboxedInjector:Injector = context.injector.createChildInjector();
sandboxedInjector.map(IDirectCommandMap).toValue(this);
_mappings = new CommandMappingList(new NullCommandTrigger(), context.getLogger(this));
_executor = new CommandExecutor(injector.createChildInjector(), _mappings.removeMapping);
_executor = new CommandExecutor(sandboxedInjector.createChildInjector(), _mappings.removeMapping);
}

/*============================================================================*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ package robotlegs.bender.extensions.commandCenter.impl
assertThat(reported, array(null, 0));
}

[Test]
public function payload_doesnt_leak_into_class_instantiated_by_command():void
{
injector.map(Injector).toValue(injector);
addMapping(OptionalInjectionPointsCommandInstantiatingCommand);

const payload:CommandPayload = new CommandPayload(['message', 1], [String, int]);
executeCommands(payload);
assertThat(reported, array(null, 0));
}

[Test]
public function result_is_handled():void
{
Expand Down Expand Up @@ -293,6 +304,8 @@ package robotlegs.bender.extensions.commandCenter.impl
}
}

import org.swiftsuspenders.Injector;

class ExecutelessCommand
{

Expand Down Expand Up @@ -536,3 +549,24 @@ class PayloadInjectionPointsGuard
return true;
}
}

class OptionalInjectionPointsCommandInstantiatingCommand
{

/*============================================================================*/
/* Public Properties */
/*============================================================================*/

[Inject]
public var injector:Injector;

/*============================================================================*/
/* Public Functions */
/*============================================================================*/

public function execute():void
{
var command:OptionalInjectionPointsCommand = injector.instantiateUnmapped(OptionalInjectionPointsCommand);
command.execute();
}
}

0 comments on commit 44b074e

Please sign in to comment.