Skip to content

Commit

Permalink
Add test to try to reproduce appsquickly#77. Not luck for the moment,…
Browse files Browse the repository at this point in the history
… hard to reproduce. Valid test anyway
  • Loading branch information
Cesar Estebanez committed Sep 12, 2013
1 parent e39487c commit f83daa9
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Tests/Factory/Block/CircularDependenciesAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#import "UnsatisfiableClassFDependsOnGInInitializer.h"
#import "UnsatisfiableClassGDependsOnFInInitializer.h"

// Currently Resolving Overwrite
#import "CROSingletonA.h"
#import "CROPrototypeA.h"
#import "CROPrototypeB.h"

@interface CircularDependenciesAssembly : TyphoonAssembly

- (id)classA;
Expand All @@ -34,4 +39,9 @@
- (id)prototypeInitInjected;
- (id)prototypePropertyInjected;

- (id)croSingletonA;
- (id)croSingletonB;
- (id)croPrototypeA;
- (id)croPrototypeB;

@end
40 changes: 40 additions & 0 deletions Tests/Factory/Block/CircularDependenciesAssembly.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#import "PrototypeInitInjected.h"
#import "PrototypePropertyInjected.h"

#import "CROSingletonA.h"
#import "CROSingletonB.h"
#import "CROPrototypeA.h"
#import "CROPrototypeB.h"

@implementation CircularDependenciesAssembly


Expand Down Expand Up @@ -96,4 +101,39 @@ - (id)prototypePropertyInjected
}];
}

// Currently Resolving Overwrite

- (id)croSingletonA
{
return [TyphoonDefinition withClass:[CROSingletonA class] properties:^(TyphoonDefinition *definition) {
[definition injectProperty:@selector(prototypeB) withDefinition:[self croPrototypeB]];
[definition injectProperty:@selector(prototypeA) withDefinition:[self croPrototypeA]];
[definition setScope:TyphoonScopeSingleton];
}];
}

- (id)croSingletonB
{
return [TyphoonDefinition withClass:[CROSingletonB class] initialization:^(TyphoonInitializer *initializer) {
initializer.selector = @selector(initWithPrototypeB:);
[initializer injectWithDefinition:[self croPrototypeB]];
}];
}

- (id)croPrototypeA
{
return [TyphoonDefinition withClass:[CROPrototypeA class] initialization:^(TyphoonInitializer *initializer) {
initializer.selector = @selector(initWithCROPrototypeB:);
[initializer injectWithDefinition:[self croPrototypeB]];
}];
}

- (id)croPrototypeB
{
return [TyphoonDefinition withClass:[CROPrototypeB class] initialization:^(TyphoonInitializer *initializer) {
initializer.selector = @selector(initWithCROSingletonA:);
[initializer injectWithDefinition:[self croSingletonA]];
}];
}

@end
13 changes: 13 additions & 0 deletions Tests/Factory/Shared/TyphoonSharedComponentFactoryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#import "PrototypeInitInjected.h"
#import "PrototypePropertyInjected.h"

#import "CROSingletonA.h"
#import "CROPrototypeA.h"
#import "CROPrototypeB.h"

@implementation TyphoonSharedComponentFactoryTests


Expand Down Expand Up @@ -260,4 +264,13 @@ - (void)test_initializer_injected_component_is_correctly_resolved_in_circular_de
assertThat(propertyInjected.prototypeInitInjected, isNot(initializerInjected));
}

/* ====================================================================================================================================== */
#pragma mark - Currently Resolving Overwriting Problem
- (void)test_currently_resolving_references_dictionary_is_not_overwritten_when_initializing_two_instances_of_prototype_in_the_same_chain
{
CROSingletonA *singletonA = [_circularDependenciesFactory componentForType:[CROSingletonA class]];
assertThat(singletonA.prototypeB, isNot(nilValue()));
}


@end
19 changes: 19 additions & 0 deletions Tests/Model/CROPrototypeA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CROPrototypeA.h
// Tests
//
// Created by Cesar Estebanez Tascon on 11/09/13.
//
//

#import <Foundation/Foundation.h>

@class CROPrototypeB;

@interface CROPrototypeA : NSObject

@property (nonatomic, strong, readonly) CROPrototypeB *prototypeB;

- (id)initWithCROPrototypeB:(CROPrototypeB *)prototypeB;

@end
22 changes: 22 additions & 0 deletions Tests/Model/CROPrototypeA.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// CROPrototypeA.m
// Tests
//
// Created by Cesar Estebanez Tascon on 11/09/13.
//
//

#import "CROPrototypeA.h"

@implementation CROPrototypeA

- (id)initWithCROPrototypeB:(CROPrototypeB *)prototypeB
{
self = [super init];
if (self) {
_prototypeB = prototypeB;
}
return self;
}

@end
19 changes: 19 additions & 0 deletions Tests/Model/CROPrototypeB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CROPrototypeB.h
// Tests
//
// Created by Cesar Estebanez Tascon on 11/09/13.
//
//

#import <Foundation/Foundation.h>

@class CROSingletonA;

@interface CROPrototypeB : NSObject

@property (nonatomic, strong, readonly) CROSingletonA *singletonA;

- (id)initWithCROSingletonA:(CROSingletonA *)singletonA;

@end
22 changes: 22 additions & 0 deletions Tests/Model/CROPrototypeB.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// CROPrototypeB.m
// Tests
//
// Created by Cesar Estebanez Tascon on 11/09/13.
//
//

#import "CROPrototypeB.h"

@implementation CROPrototypeB

- (id)initWithCROSingletonA:(CROSingletonA *)singletonA
{
self = [super init];
if (self) {
_singletonA = singletonA;
}
return self;
}

@end
20 changes: 20 additions & 0 deletions Tests/Model/CROSingletonA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// SingletonA.h
// Tests
//
// Created by Cesar Estebanez Tascon on 11/09/13.
//
//

#import <Foundation/Foundation.h>

@class CROPrototypeA;
@class CROPrototypeB;

@interface CROSingletonA : NSObject

// property injection here to break circular CROSingletonA -> CROPrototypeB -> CROSingletonA
@property (nonatomic, strong) CROPrototypeA *prototypeA;
@property (nonatomic, strong) CROPrototypeB *prototypeB;

@end
13 changes: 13 additions & 0 deletions Tests/Model/CROSingletonA.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// SingletonA.m
// Tests
//
// Created by Cesar Estebanez Tascon on 11/09/13.
//
//

#import "CROSingletonA.h"

@implementation CROSingletonA

@end
19 changes: 19 additions & 0 deletions Tests/Model/CROSingletonB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CROSingletonB.h
// Tests
//
// Created by Cesar Estebanez Tascon on 11/09/13.
//
//

#import <Foundation/Foundation.h>

@class CROPrototypeB;

@interface CROSingletonB : NSObject

@property (nonatomic, strong, readonly) CROPrototypeB *prototypeB;

- (id)initWithPrototypeB:(CROPrototypeB *)prototypeB;

@end
21 changes: 21 additions & 0 deletions Tests/Model/CROSingletonB.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// CROSingletonB.m
// Tests
//
// Created by Cesar Estebanez Tascon on 11/09/13.
//
//

#import "CROSingletonB.h"

@implementation CROSingletonB

- (id)initWithPrototypeB:(CROPrototypeB *)prototypeB
{
self = [super init];
if (self) {
_prototypeB = prototypeB;
}
return self;
}
@end
17 changes: 17 additions & 0 deletions Tests/Resources/CircularDependenciesAssembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,22 @@
</component>


<component class="CROSingletonA" key="croSingletonA" scope="singleton">
<property name="prototypeA" ref="croPrototypeA"/>
<property name="prototypeB" ref="croPrototypeB"/>
</component>

<component class="CROPrototypeA" key="croPrototypeA" scope="prototype">
<initializer selector="initWithCROPrototypeB:">
<argument parameterName="croPrototypeB" ref="croPrototypeB"/>
</initializer>
</component>

<component class="CROPrototypeB" key="croPrototypeB" scope="prototype">
<initializer selector="initWithCROSingletonA:">
<argument parameterName="croSingletonA" ref="croSingletonA"/>
</initializer>
</component>

</assembly>

Loading

0 comments on commit f83daa9

Please sign in to comment.