forked from appsquickly/typhoon
-
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.
Returned instances are injected the component factory.
Types conforming TyphoonComponentFactoryAware passed as the return type for a factory generated from TyphoonFactoryProvider, will be now correctly injected with the component factory. This commit only works when using withProtocol:dependencies:returns:. Others will come in later commits. See appsquickly#144
- Loading branch information
1 parent
9cee525
commit 2704341
Showing
10 changed files
with
109 additions
and
24 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
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
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
71 changes: 71 additions & 0 deletions
71
Tests/Factory/Provider/TyphoonFactoryProviderIntegrationTest.m
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,71 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2014, Jasper Blues & Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#import "TyphoonFactoryProvider.h" | ||
|
||
#import <SenTestingKit/SenTestingKit.h> | ||
|
||
#import "AuthServiceImpl.h" | ||
#import "CreditServiceImpl.h" | ||
#import "PaymentFactory.h" | ||
#import "PaymentFactoryAssembly.h" | ||
#import "PaymentImpl.h" | ||
|
||
@interface TyphoonFactoryProviderIntegrationTest : SenTestCase | ||
@end | ||
|
||
@implementation TyphoonFactoryProviderIntegrationTest | ||
{ | ||
TyphoonBlockComponentFactory* componentFactory; | ||
PaymentFactoryAssembly* assembly; | ||
} | ||
|
||
- (void)setUp | ||
{ | ||
componentFactory = [[TyphoonBlockComponentFactory alloc] initWithAssembly:[PaymentFactoryAssembly assembly]]; | ||
assembly = (PaymentFactoryAssembly*) componentFactory; | ||
} | ||
|
||
- (void)test_dependencies_are_built_lazily | ||
{ | ||
NSUInteger authServiceInstanceCounter = [AuthServiceImpl instanceCounter]; | ||
NSUInteger creditServiceInstanceCounter = [CreditServiceImpl instanceCounter]; | ||
|
||
id<PaymentFactory> factory = [assembly paymentFactory]; | ||
|
||
assertThatUnsignedInteger([AuthServiceImpl instanceCounter], is(equalToUnsignedInteger(authServiceInstanceCounter))); | ||
assertThatUnsignedInteger([CreditServiceImpl instanceCounter], is(equalToUnsignedInteger(creditServiceInstanceCounter))); | ||
|
||
// No need for the return value. | ||
[factory paymentWithStartDate:[NSDate date] amount:123]; | ||
|
||
assertThatUnsignedInteger([AuthServiceImpl instanceCounter], is(equalToUnsignedInteger(authServiceInstanceCounter + 1))); | ||
assertThatUnsignedInteger([CreditServiceImpl instanceCounter], is(equalToUnsignedInteger(creditServiceInstanceCounter + 1))); | ||
} | ||
|
||
- (void)test_assisted_factory_is_TyphoonComponentFactoryAware | ||
{ | ||
NSObject<PaymentFactory>* factory = [assembly paymentFactory]; | ||
|
||
id cf = [factory valueForKey:@"componentFactory"]; | ||
assertThat(cf, is(equalTo(componentFactory))); | ||
} | ||
|
||
- (void)test_assisted_factory_injects_component_factory_in_object_instances | ||
{ | ||
id<PaymentFactory> factory = [assembly paymentFactory]; | ||
|
||
PaymentImpl* payment = [factory paymentWithStartDate:[NSDate date] amount:456]; | ||
|
||
assertThat(payment.factory, is(equalTo(componentFactory))); | ||
} | ||
|
||
@end |
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