Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
Merged additional unit tests from the old SwiftSuspendersTests project
Browse files Browse the repository at this point in the history
  • Loading branch information
tschneidereit committed Nov 4, 2009
1 parent c7313fa commit 4f96838
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 5 deletions.
12 changes: 7 additions & 5 deletions .gitignore
Expand Up @@ -9,11 +9,13 @@
/report/*
/dist/*

.actionScriptProperties
.flexProperties
.flexLibProperties
.project
/.actionScriptProperties
/.flexProperties
/.flexLibProperties
/.project
/com.adobe.flexbuilder.project.prefs
/org.eclipse.core.resources.prefs

Icon
Thumbs.db
.DS_Store
.DS_Store
38 changes: 38 additions & 0 deletions test/org/swiftsuspenders/InjectorTests.as
Expand Up @@ -30,6 +30,8 @@ package org.swiftsuspenders
import org.swiftsuspenders.support.injectees.InterfaceInjectee;
import org.swiftsuspenders.support.injectees.MixedParametersConstructorInjectee;
import org.swiftsuspenders.support.injectees.MixedParametersMethodInjectee;
import org.swiftsuspenders.support.injectees.MultipleNamedSingletonsOfSameClassInjectee;
import org.swiftsuspenders.support.injectees.MultipleSingletonsOfSameClassInjectee;
import org.swiftsuspenders.support.injectees.MultipleSingletonsOfSameClassInjectee;
import org.swiftsuspenders.support.injectees.NamedArrayCollectionInjectee;
import org.swiftsuspenders.support.injectees.NamedClassInjectee;
Expand All @@ -39,11 +41,13 @@ package org.swiftsuspenders
import org.swiftsuspenders.support.injectees.OneParameterConstructorInjectee;
import org.swiftsuspenders.support.injectees.OneParameterMethodInjectee;
import org.swiftsuspenders.support.injectees.SetterInjectee;
import org.swiftsuspenders.support.injectees.TwoNamedInterfaceFieldsInjectee;
import org.swiftsuspenders.support.injectees.TwoNamedParametersConstructorInjectee;
import org.swiftsuspenders.support.injectees.TwoNamedParametersMethodInjectee;
import org.swiftsuspenders.support.injectees.TwoParametersConstructorInjectee;
import org.swiftsuspenders.support.injectees.TwoParametersMethodInjectee;
import org.swiftsuspenders.support.types.Clazz;
import org.swiftsuspenders.support.types.Clazz2;
import org.swiftsuspenders.support.types.ComplexClazz;
import org.swiftsuspenders.support.types.Interface;
import org.swiftsuspenders.support.types.Interface2;
Expand Down Expand Up @@ -206,6 +210,18 @@ package org.swiftsuspenders
Assert.assertStrictlyEquals("Injected values should be equal", injectee.property, injectee2.property );
}

[Test]
public function bindDifferentlyNamedSingletonsBySameInterface():void
{
var injectee:TwoNamedInterfaceFieldsInjectee = new TwoNamedInterfaceFieldsInjectee();
injector.mapSingletonOf(Interface, Clazz, 'Name1');
injector.mapSingletonOf(Interface, Clazz2, 'Name2');
injector.injectInto(injectee);
Assert.assertTrue('Property "property1" should be of type "Clazz"', injectee.property1 is Clazz);
Assert.assertTrue('Property "property2" should be of type "Clazz2"', injectee.property2 is Clazz2);
Assert.assertFalse('Properties "property1" and "property2" should have received different singletons', injectee.property1 == injectee.property2);
}

[Test]
public function performSetterInjection():void
{
Expand Down Expand Up @@ -348,6 +364,28 @@ package org.swiftsuspenders
Assert.assertEquals("Instance field 'ac' should be identical to local variable 'ac'", ac, injectee.ac);
}

[Test]
public function performMappedRuleInjection():void
{
var rule : InjectionConfig = injector.mapSingletonOf(Interface, Clazz);
injector.mapRule(Interface2, rule);
var injectee:MultipleSingletonsOfSameClassInjectee = injector.instantiate(MultipleSingletonsOfSameClassInjectee);
Assert.assertEquals("Instance field 'property1' should be identical to Instance field 'property2'", injectee.property1, injectee.property2);
}

[Test]
public function performMappedNamedRuleInjection():void
{
var rule : InjectionConfig = injector.mapSingletonOf(Interface, Clazz);
injector.mapRule(Interface2, rule);
injector.mapRule(Interface, rule, 'name1');
injector.mapRule(Interface2, rule, 'name2');
var injectee:MultipleNamedSingletonsOfSameClassInjectee = injector.instantiate(MultipleNamedSingletonsOfSameClassInjectee);
Assert.assertEquals("Instance field 'property1' should be identical to Instance field 'property2'", injectee.property1, injectee.property2);
Assert.assertEquals("Instance field 'property1' should be identical to Instance field 'namedProperty1'", injectee.property1, injectee.namedProperty1);
Assert.assertEquals("Instance field 'property1' should be identical to Instance field 'namedProperty2'", injectee.property1, injectee.namedProperty2);
}

[Test(expects="org.swiftsuspenders.InjectorError")]
public function haltOnMissingDependency():void
{
Expand Down
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2009 the original author or authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.swiftsuspenders.support.injectees
{
import org.swiftsuspenders.support.types.Interface;
import org.swiftsuspenders.support.types.Interface2;

public class MultipleNamedSingletonsOfSameClassInjectee
{
[Inject]
public var property1:Interface;
[Inject]
public var property2:Interface2;
[Inject(name='name1')]
public var namedProperty1:Interface;
[Inject(name='name2')]
public var namedProperty2:Interface2;

public function MultipleNamedSingletonsOfSameClassInjectee()
{
}
}
}
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2009 the original author or authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.swiftsuspenders.support.injectees
{
import org.swiftsuspenders.support.types.Interface;

public class TwoNamedInterfaceFieldsInjectee
{
[Inject(named="Name1")]
public var property1:Interface;
[Inject(named="Name2")]
public var property2:Interface;

public function TwoNamedInterfaceFieldsInjectee()
{
}
}
}
31 changes: 31 additions & 0 deletions test/org/swiftsuspenders/support/types/Clazz2.as
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2009 the original author or authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.swiftsuspenders.support.types
{
public class Clazz2 implements Interface, Interface2
{
public function Clazz2()
{
}
}
}

0 comments on commit 4f96838

Please sign in to comment.