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.
Added a bunch of bogus init methods to the PaymentImpl, to better test the guessing of the initializer for the factory method. (appsquickly#102)
- Loading branch information
1 parent
a2253dd
commit 8a893c7
Showing
4 changed files
with
168 additions
and
0 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
117 changes: 117 additions & 0 deletions
117
Tests/Component/FactoryProvider/TyphoonAssistedFactoryCreatorImplicitTest.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,117 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2013, 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 "TyphoonAssistedFactoryCreatorImplicit.h" | ||
|
||
#import <SenTestingKit/SenTestingKit.h> | ||
#include <objc/runtime.h> | ||
|
||
#import "TyphoonFactoryProviderTestHelper.h" | ||
|
||
#import "AuthService.h" | ||
#import "CreditService.h" | ||
#import "PaymentFactory.h" | ||
#import "PaymentImpl.h" | ||
#import "TyphoonAssistedFactoryBase.h" | ||
#import "TyphoonDefinition.h" | ||
|
||
|
||
@interface TyphoonAssistedFactoryCreatorImplicitTest : SenTestCase | ||
@end | ||
|
||
@implementation TyphoonAssistedFactoryCreatorImplicitTest | ||
{ | ||
Protocol *_paymentFactoryProtocol; | ||
Class _paymentFactoryClass; | ||
|
||
id<CreditService> _creditService; | ||
id<AuthService> _authService; | ||
} | ||
|
||
- (void)setUp | ||
{ | ||
_creditService = (id<CreditService>)[[NSObject alloc] init]; | ||
_authService = (id<AuthService>)[[NSObject alloc] init]; | ||
} | ||
|
||
- (Protocol *)paymentFactoryProtocol | ||
{ | ||
if (!_paymentFactoryProtocol) | ||
{ | ||
_paymentFactoryProtocol = protocol_clone(@protocol(PaymentFactory)); | ||
} | ||
|
||
return _paymentFactoryProtocol; | ||
} | ||
|
||
- (Class)paymentFactoryClass | ||
{ | ||
if (!_paymentFactoryClass) | ||
{ | ||
_paymentFactoryClass = [[[TyphoonAssistedFactoryCreatorImplicit alloc] | ||
initWithProtocol:[self paymentFactoryProtocol] | ||
returns:[PaymentImpl class]] | ||
factoryClass]; | ||
} | ||
|
||
return _paymentFactoryClass; | ||
} | ||
|
||
- (void)test_factory_class_should_implement_protocol | ||
{ | ||
Class klass = [self paymentFactoryClass]; | ||
|
||
assertThatBool(class_conformsToProtocol(klass, [self paymentFactoryProtocol]), is(equalToBool(YES))); | ||
|
||
Class superklass = class_getSuperclass(klass); | ||
assertThat(superklass, is([TyphoonAssistedFactoryBase class])); | ||
} | ||
|
||
- (void)test_factory_should_respond_to_properties | ||
{ | ||
Class klass = [self paymentFactoryClass]; | ||
id<PaymentFactory> factory = [[klass alloc] init]; | ||
|
||
assertThatBool([factory respondsToSelector:@selector(creditService)], is(equalToBool(YES))); | ||
assertThatBool([factory respondsToSelector:@selector(setCreditService:)], is(equalToBool(YES))); | ||
assertThatBool([factory respondsToSelector:@selector(authService)], is(equalToBool(YES))); | ||
assertThatBool([factory respondsToSelector:@selector(setAuthService:)], is(equalToBool(YES))); | ||
} | ||
|
||
- (void)test_factory_should_implement_properties | ||
{ | ||
Class klass = [self paymentFactoryClass]; | ||
id<PaymentFactory> factory = [[klass alloc] init]; | ||
|
||
[(NSObject *)factory setValue:_creditService forKey:@"creditService"]; | ||
[(NSObject *)factory setValue:_authService forKey:@"authService"]; | ||
assertThat(factory.creditService, is(_creditService)); | ||
assertThat(factory.authService, is(_authService)); | ||
} | ||
|
||
- (void)test_factory_should_invoke_correct_method_blocks | ||
{ | ||
Class klass = [self paymentFactoryClass]; | ||
id<PaymentFactory> factory = [[klass alloc] init]; | ||
|
||
[(NSObject *)factory setValue:_creditService forKey:@"creditService"]; | ||
[(NSObject *)factory setValue:_authService forKey:@"authService"]; | ||
|
||
NSDate *now = [NSDate date]; | ||
id<Payment> payment = [factory paymentWithStartDate:now amount:456]; | ||
|
||
assertThat(payment.creditService, is(_creditService)); | ||
assertThat(payment.authService, is(_authService)); | ||
assertThat(payment.startDate, is(now)); | ||
assertThatInteger(payment.amount, is(equalToInteger(456))); | ||
} | ||
|
||
@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