From f059dfa02252c0de46b4ed472fb9826666a48aea Mon Sep 17 00:00:00 2001 From: Ceri Hughes Date: Fri, 7 Apr 2017 17:38:32 +0200 Subject: [PATCH 1/5] Move component registry and layout manager into the cv factory --- sources/HUBCollectionViewFactory.h | 15 +++++++++- sources/HUBCollectionViewFactory.m | 28 ++++++++++++++++++- sources/HUBConfigViewControllerFactory.m | 5 ++-- ...ViewControllerExperimentalImplementation.h | 6 ---- ...ViewControllerExperimentalImplementation.m | 14 ---------- .../HUBViewControllerFactoryImplementation.m | 10 +++---- sources/HUBViewControllerImplementation.h | 6 ---- sources/HUBViewControllerImplementation.m | 14 ---------- 8 files changed, 47 insertions(+), 51 deletions(-) diff --git a/sources/HUBCollectionViewFactory.h b/sources/HUBCollectionViewFactory.h index 1798c604..dac0f3a2 100644 --- a/sources/HUBCollectionViewFactory.h +++ b/sources/HUBCollectionViewFactory.h @@ -19,7 +19,11 @@ * under the License. */ -#import +#import +#import "HUBHeaderMacros.h" + +@protocol HUBComponentLayoutManager; +@protocol HUBComponentRegistry; @class HUBCollectionView; @@ -28,6 +32,15 @@ NS_ASSUME_NONNULL_BEGIN /// Factory used to create collection views for use in a `HUBViewController` @interface HUBCollectionViewFactory : NSObject +/** + Designated initializer. + + @param componentRegistry The registry to use to lookup component information + @param componentLayoutManager The object that manages layout for components in the view controller + */ +- (instancetype)initWithComponentRegistry:(id)componentRegistry + componentLayoutManager:(id)componentLayoutManager HUB_DESIGNATED_INITIALIZER; + /// Create a collection view. It will be setup with a default layout. - (HUBCollectionView *)createCollectionView; diff --git a/sources/HUBCollectionViewFactory.m b/sources/HUBCollectionViewFactory.m index b4489eb0..4017a223 100644 --- a/sources/HUBCollectionViewFactory.m +++ b/sources/HUBCollectionViewFactory.m @@ -20,16 +20,42 @@ */ #import "HUBCollectionViewFactory.h" + #import "HUBCollectionView.h" +#import "HUBCollectionViewLayout.h" NS_ASSUME_NONNULL_BEGIN +@interface HUBCollectionViewFactory () + +@property (nonatomic, strong, readonly) id componentRegistry; +@property (nonatomic, strong, readonly) id componentLayoutManager; + +@end + @implementation HUBCollectionViewFactory +- (instancetype)initWithComponentRegistry:(id)componentRegistry + componentLayoutManager:(id)componentLayoutManager +{ + NSParameterAssert(componentRegistry != nil); + NSParameterAssert(componentLayoutManager != nil); + + self = [super init]; + if (self) { + _componentRegistry = componentRegistry; + _componentLayoutManager = componentLayoutManager; + } + return self; +} + - (HUBCollectionView *)createCollectionView { + HUBCollectionViewLayout *collectionViewLayout = [[HUBCollectionViewLayout alloc] initWithComponentRegistry:self.componentRegistry + componentLayoutManager:self.componentLayoutManager]; + HUBCollectionView *collectionView = [[HUBCollectionView alloc] initWithFrame:CGRectZero - collectionViewLayout:[UICollectionViewLayout new]]; + collectionViewLayout:collectionViewLayout]; collectionView.accessibilityIdentifier = @"collectionView"; return collectionView; diff --git a/sources/HUBConfigViewControllerFactory.m b/sources/HUBConfigViewControllerFactory.m index eb4d908b..26413856 100644 --- a/sources/HUBConfigViewControllerFactory.m +++ b/sources/HUBConfigViewControllerFactory.m @@ -58,7 +58,8 @@ - (HUBViewController *)createViewControllerWithConfig:(HUBConfig *)config HUBViewModelRenderer * const viewModelRenderer = [HUBViewModelRenderer new]; - HUBCollectionViewFactory * const collectionViewFactory = [HUBCollectionViewFactory new]; + HUBCollectionViewFactory * const collectionViewFactory = [[HUBCollectionViewFactory alloc] initWithComponentRegistry:config.componentRegistry + componentLayoutManager:config.componentLayoutManager]; HUBComponentReusePool * const componentReusePool = [[HUBComponentReusePool alloc] initWithComponentRegistry:config.componentRegistry]; id const actionHandlerWrapper = [[HUBActionHandlerWrapper alloc] initWithActionHandler:actionHandler @@ -74,9 +75,7 @@ - (HUBViewController *)createViewControllerWithConfig:(HUBConfig *)config viewModelLoader:viewModelLoader viewModelRenderer:viewModelRenderer collectionViewFactory:collectionViewFactory - componentRegistry:config.componentRegistry componentReusePool:componentReusePool - componentLayoutManager:config.componentLayoutManager actionHandler:actionHandlerWrapper scrollHandler:scrollHandlerToUse imageLoader:imageLoader]; diff --git a/sources/HUBViewControllerExperimentalImplementation.h b/sources/HUBViewControllerExperimentalImplementation.h index 1ee96b6d..15119866 100644 --- a/sources/HUBViewControllerExperimentalImplementation.h +++ b/sources/HUBViewControllerExperimentalImplementation.h @@ -22,8 +22,6 @@ #import "HUBViewController.h" @protocol HUBFeatureInfo; -@protocol HUBComponentRegistry; -@protocol HUBComponentLayoutManager; @protocol HUBActionHandler; @protocol HUBViewControllerScrollHandler; @protocol HUBImageLoader; @@ -43,9 +41,7 @@ NS_ASSUME_NONNULL_BEGIN * @param featureInfo Information about the feature that the view controller is for * @param viewModelLoader The object to use to load view models for the view controller * @param collectionViewFactory The factory to use to create collection views - * @param componentRegistry The registry to use to lookup component information * @param componentReusePool The reuse pool to use to manage component wrappers - * @param componentLayoutManager The object that manages layout for components in the view controller * @param actionHandler The object that will handle actions for this view controller * @param scrollHandler The object that will handle scrolling for the view controller * @param imageLoader The loader to use to load images for components @@ -54,9 +50,7 @@ NS_ASSUME_NONNULL_BEGIN featureInfo:(id)featureInfo viewModelLoader:(id)viewModelLoader collectionViewFactory:(HUBCollectionViewFactory *)collectionViewFactory - componentRegistry:(id)componentRegistry componentReusePool:(HUBComponentReusePool *)componentReusePool - componentLayoutManager:(id)componentLayoutManager actionHandler:(id)actionHandler scrollHandler:(id)scrollHandler imageLoader:(id)imageLoader NS_DESIGNATED_INITIALIZER; diff --git a/sources/HUBViewControllerExperimentalImplementation.m b/sources/HUBViewControllerExperimentalImplementation.m index 07620fc6..76fb15be 100644 --- a/sources/HUBViewControllerExperimentalImplementation.m +++ b/sources/HUBViewControllerExperimentalImplementation.m @@ -33,7 +33,6 @@ #import "HUBComponentViewObserver.h" #import "HUBComponentWrapper.h" #import "HUBComponentWrapperImageLoader.h" -#import "HUBComponentRegistry.h" #import "HUBComponentCollectionViewCell.h" #import "HUBUtilities.h" #import "HUBCollectionViewFactory.h" @@ -62,9 +61,7 @@ @interface HUBViewControllerExperimentalImplementation () < @property (nonatomic, strong, readonly) id featureInfo; @property (nonatomic, strong, readonly) id viewModelLoader; @property (nonatomic, strong, readonly) HUBCollectionViewFactory *collectionViewFactory; -@property (nonatomic, strong, readonly) id componentRegistry; @property (nonatomic, strong, readonly) HUBComponentReusePool *componentReusePool; -@property (nonatomic, strong, readonly) id componentLayoutManager; @property (nonatomic, strong, readonly) id actionHandler; @property (nonatomic, strong, readonly) id scrollHandler; @property (nonatomic, strong, nullable, readonly) id contentReloadPolicy; @@ -101,9 +98,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI featureInfo:(id)featureInfo viewModelLoader:(id)viewModelLoader collectionViewFactory:(HUBCollectionViewFactory *)collectionViewFactory - componentRegistry:(id)componentRegistry componentReusePool:(HUBComponentReusePool *)componentReusePool - componentLayoutManager:(id)componentLayoutManager actionHandler:(id)actionHandler scrollHandler:(id)scrollHandler imageLoader:(id)imageLoader @@ -112,9 +107,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI NSParameterAssert(featureInfo != nil); NSParameterAssert(viewModelLoader != nil); NSParameterAssert(collectionViewFactory != nil); - NSParameterAssert(componentRegistry != nil); NSParameterAssert(componentReusePool != nil); - NSParameterAssert(componentLayoutManager != nil); NSParameterAssert(actionHandler != nil); NSParameterAssert(scrollHandler != nil); NSParameterAssert(imageLoader != nil); @@ -127,9 +120,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI _featureInfo = featureInfo; _viewModelLoader = viewModelLoader; _collectionViewFactory = collectionViewFactory; - _componentRegistry = componentRegistry; _componentReusePool = componentReusePool; - _componentLayoutManager = componentLayoutManager; _actionHandler = actionHandler; _scrollHandler = scrollHandler; _componentWrapperImageLoader = [[HUBComponentWrapperImageLoader alloc] initWithImageLoader:imageLoader]; @@ -893,11 +884,6 @@ - (HUBOperation *)createReloadCollectionViewOperation return; } - if (![self.collectionView.collectionViewLayout isKindOfClass:[HUBCollectionViewLayout class]]) { - self.collectionView.collectionViewLayout = [[HUBCollectionViewLayout alloc] initWithComponentRegistry:self.componentRegistry - componentLayoutManager:self.componentLayoutManager]; - } - [self saveStatesForVisibleComponents]; [self configureHeaderComponent]; [self configureOverlayComponents]; diff --git a/sources/HUBViewControllerFactoryImplementation.m b/sources/HUBViewControllerFactoryImplementation.m index 37da9555..951d82cb 100644 --- a/sources/HUBViewControllerFactoryImplementation.m +++ b/sources/HUBViewControllerFactoryImplementation.m @@ -166,7 +166,8 @@ - (HUBViewController *)createStandardViewControllerForViewURI:(NSURL *)viewURI HUBViewModelRenderer * const viewModelRenderer = [HUBViewModelRenderer new]; id const imageLoader = [self.imageLoaderFactory createImageLoader]; - HUBCollectionViewFactory * const collectionViewFactory = [HUBCollectionViewFactory new]; + HUBCollectionViewFactory * const collectionViewFactory = [[HUBCollectionViewFactory alloc] initWithComponentRegistry:self.componentRegistry + componentLayoutManager:self.componentLayoutManager]; HUBComponentReusePool * const componentReusePool = [[HUBComponentReusePool alloc] initWithComponentRegistry:self.componentRegistry]; id const actionHandler = featureRegistration.actionHandler ?: self.defaultActionHandler; @@ -182,9 +183,7 @@ - (HUBViewController *)createStandardViewControllerForViewURI:(NSURL *)viewURI viewModelLoader:viewModelLoader viewModelRenderer:viewModelRenderer collectionViewFactory:collectionViewFactory - componentRegistry:self.componentRegistry componentReusePool:componentReusePool - componentLayoutManager:self.componentLayoutManager actionHandler:actionHandlerWrapper scrollHandler:scrollHandlerToUse imageLoader:imageLoader]; @@ -200,7 +199,8 @@ - (HUBViewController *)createExperimentalViewControllerForViewURI:(NSURL *)viewU featureRegistration:featureRegistration]; id const imageLoader = [self.imageLoaderFactory createImageLoader]; - HUBCollectionViewFactory * const collectionViewFactory = [HUBCollectionViewFactory new]; + HUBCollectionViewFactory * const collectionViewFactory = [[HUBCollectionViewFactory alloc] initWithComponentRegistry:self.componentRegistry + componentLayoutManager:self.componentLayoutManager]; HUBComponentReusePool * const componentReusePool = [[HUBComponentReusePool alloc] initWithComponentRegistry:self.componentRegistry]; id const actionHandler = featureRegistration.actionHandler ?: self.defaultActionHandler; @@ -215,9 +215,7 @@ - (HUBViewController *)createExperimentalViewControllerForViewURI:(NSURL *)viewU featureInfo:featureInfo viewModelLoader:viewModelLoader collectionViewFactory:collectionViewFactory - componentRegistry:self.componentRegistry componentReusePool:componentReusePool - componentLayoutManager:self.componentLayoutManager actionHandler:actionHandlerWrapper scrollHandler:scrollHandlerToUse imageLoader:imageLoader]; diff --git a/sources/HUBViewControllerImplementation.h b/sources/HUBViewControllerImplementation.h index effa15f3..ae5ed70a 100644 --- a/sources/HUBViewControllerImplementation.h +++ b/sources/HUBViewControllerImplementation.h @@ -22,8 +22,6 @@ #import "HUBViewController.h" @protocol HUBFeatureInfo; -@protocol HUBComponentRegistry; -@protocol HUBComponentLayoutManager; @protocol HUBActionHandler; @protocol HUBViewControllerScrollHandler; @protocol HUBImageLoader; @@ -45,9 +43,7 @@ NS_ASSUME_NONNULL_BEGIN * @param viewModelLoader The object to use to load view models for the view controller * @param viewModelRenderer The object used to render the view model * @param collectionViewFactory The factory to use to create collection views - * @param componentRegistry The registry to use to lookup component information * @param componentReusePool The reuse pool to use to manage component wrappers - * @param componentLayoutManager The object that manages layout for components in the view controller * @param actionHandler The object that will handle actions for this view controller * @param scrollHandler The object that will handle scrolling for the view controller * @param imageLoader The loader to use to load images for components @@ -57,9 +53,7 @@ NS_ASSUME_NONNULL_BEGIN viewModelLoader:(id)viewModelLoader viewModelRenderer:(HUBViewModelRenderer *)viewModelRenderer collectionViewFactory:(HUBCollectionViewFactory *)collectionViewFactory - componentRegistry:(id)componentRegistry componentReusePool:(HUBComponentReusePool *)componentReusePool - componentLayoutManager:(id)componentLayoutManager actionHandler:(id)actionHandler scrollHandler:(id)scrollHandler imageLoader:(id)imageLoader NS_DESIGNATED_INITIALIZER; diff --git a/sources/HUBViewControllerImplementation.m b/sources/HUBViewControllerImplementation.m index 64e30d79..adb10e37 100644 --- a/sources/HUBViewControllerImplementation.m +++ b/sources/HUBViewControllerImplementation.m @@ -33,7 +33,6 @@ #import "HUBComponentViewObserver.h" #import "HUBComponentWrapper.h" #import "HUBComponentWrapperImageLoader.h" -#import "HUBComponentRegistry.h" #import "HUBComponentCollectionViewCell.h" #import "HUBUtilities.h" #import "HUBCollectionViewFactory.h" @@ -62,9 +61,7 @@ @interface HUBViewControllerImplementation () < @property (nonatomic, strong, readonly) id featureInfo; @property (nonatomic, strong, readonly) id viewModelLoader; @property (nonatomic, strong, readonly) HUBCollectionViewFactory *collectionViewFactory; -@property (nonatomic, strong, readonly) id componentRegistry; @property (nonatomic, strong, readonly) HUBComponentReusePool *componentReusePool; -@property (nonatomic, strong, readonly) id componentLayoutManager; @property (nonatomic, strong, readonly) id actionHandler; @property (nonatomic, strong, readonly) id scrollHandler; @property (nonatomic, strong, nullable, readonly) id contentReloadPolicy; @@ -103,9 +100,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI viewModelLoader:(id)viewModelLoader viewModelRenderer:(HUBViewModelRenderer *)viewModelRenderer collectionViewFactory:(HUBCollectionViewFactory *)collectionViewFactory - componentRegistry:(id)componentRegistry componentReusePool:(HUBComponentReusePool *)componentReusePool - componentLayoutManager:(id)componentLayoutManager actionHandler:(id)actionHandler scrollHandler:(id)scrollHandler imageLoader:(id)imageLoader @@ -115,9 +110,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI NSParameterAssert(viewModelLoader != nil); NSParameterAssert(viewModelRenderer != nil); NSParameterAssert(collectionViewFactory != nil); - NSParameterAssert(componentRegistry != nil); NSParameterAssert(componentReusePool != nil); - NSParameterAssert(componentLayoutManager != nil); NSParameterAssert(actionHandler != nil); NSParameterAssert(scrollHandler != nil); NSParameterAssert(imageLoader != nil); @@ -131,9 +124,7 @@ - (instancetype)initWithViewURI:(NSURL *)viewURI _viewModelLoader = viewModelLoader; _viewModelRenderer = viewModelRenderer; _collectionViewFactory = collectionViewFactory; - _componentRegistry = componentRegistry; _componentReusePool = componentReusePool; - _componentLayoutManager = componentLayoutManager; _actionHandler = actionHandler; _scrollHandler = scrollHandler; _componentWrapperImageLoader = [[HUBComponentWrapperImageLoader alloc] initWithImageLoader:imageLoader]; @@ -855,11 +846,6 @@ - (HUBOperation *)createReloadCollectionViewOperation return; } - if (![self.collectionView.collectionViewLayout isKindOfClass:[HUBCollectionViewLayout class]]) { - self.collectionView.collectionViewLayout = [[HUBCollectionViewLayout alloc] initWithComponentRegistry:self.componentRegistry - componentLayoutManager:self.componentLayoutManager]; - } - [self saveStatesForVisibleComponents]; [self configureHeaderComponent]; [self configureOverlayComponents]; From 859ae26288f08d59ca357638568e78dfb3ac3439 Mon Sep 17 00:00:00 2001 From: Ceri Hughes Date: Sat, 8 Apr 2017 14:08:35 +0200 Subject: [PATCH 2/5] Make tests compile (still failing) --- tests/HUBCollectionViewFactoryTests.m | 31 +++++++++++++++----- tests/HUBViewControllerImplementationTests.m | 7 ++--- tests/mocks/HUBCollectionViewFactoryMock.h | 7 +++-- tests/mocks/HUBCollectionViewFactoryMock.m | 7 ++++- tests/mocks/HUBCollectionViewMock.m | 4 ++- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/tests/HUBCollectionViewFactoryTests.m b/tests/HUBCollectionViewFactoryTests.m index b7d40d36..93fe63bb 100644 --- a/tests/HUBCollectionViewFactoryTests.m +++ b/tests/HUBCollectionViewFactoryTests.m @@ -23,34 +23,51 @@ #import "HUBCollectionViewFactory.h" #import "HUBCollectionView.h" +#import "HUBComponentLayoutManagerMock.h" +#import "HUBComponentRegistryMock.h" @interface HUBCollectionViewFactoryTests : XCTestCase +@property (nonatomic, strong) HUBCollectionViewFactory *factory; + @end @implementation HUBCollectionViewFactoryTests +- (void)setUp +{ + [super setUp]; + + self.factory = [[HUBCollectionViewFactory alloc] initWithComponentRegistry:[HUBComponentRegistryMock new] + componentLayoutManager:[HUBComponentLayoutManagerMock new]]; + +} + +- (void)tearDown +{ + self.factory = nil; + + [super tearDown]; +} + - (void)testThatTheFactoryCreatesNonNilInstances { - HUBCollectionViewFactory *factory = [HUBCollectionViewFactory new]; - HUBCollectionView *collectionView = [factory createCollectionView]; + HUBCollectionView *collectionView = [self.factory createCollectionView]; XCTAssertNotNil(collectionView); } - (void)testThatTheCollectionViewHasAccessibilityId { - HUBCollectionViewFactory *factory = [HUBCollectionViewFactory new]; - HUBCollectionView *collectionView = [factory createCollectionView]; + HUBCollectionView *collectionView = [self.factory createCollectionView]; XCTAssertNotNil(collectionView.accessibilityIdentifier); } - (void)testThatTheFactoryCreatesNewCollectionViewInstances { - HUBCollectionViewFactory *factory = [HUBCollectionViewFactory new]; - HUBCollectionView *collectionView1 = [factory createCollectionView]; - HUBCollectionView *collectionView2 = [factory createCollectionView]; + HUBCollectionView *collectionView1 = [self.factory createCollectionView]; + HUBCollectionView *collectionView2 = [self.factory createCollectionView]; XCTAssertNotEqual(collectionView1, collectionView2); } diff --git a/tests/HUBViewControllerImplementationTests.m b/tests/HUBViewControllerImplementationTests.m index ec8fecbb..22c3f8d4 100644 --- a/tests/HUBViewControllerImplementationTests.m +++ b/tests/HUBViewControllerImplementationTests.m @@ -43,7 +43,6 @@ #import "HUBComponentWrapper.h" #import "HUBCollectionViewFactoryMock.h" #import "HUBCollectionViewMock.h" -#import "HUBComponentLayoutManagerMock.h" #import "HUBActionHandlerMock.h" #import "HUBInitialViewModelRegistry.h" #import "HUBActionRegistryImplementation.h" @@ -137,7 +136,8 @@ - (void)setUp [self.componentRegistry registerComponentFactory:self.componentFactory forNamespace:componentDefaults.componentNamespace]; self.collectionView = [HUBCollectionViewMock new]; - self.collectionViewFactory = [[HUBCollectionViewFactoryMock alloc] initWithCollectionView:self.collectionView]; + self.collectionViewFactory = [[HUBCollectionViewFactoryMock alloc] initWithCollectionView:self.collectionView + componentRegistry:self.componentRegistry]; self.viewURI = [NSURL URLWithString:@"spotify:hub:framework"]; self.featureInfo = [[HUBFeatureInfoImplementation alloc] initWithIdentifier:@"id" title:@"title"]; @@ -218,7 +218,6 @@ - (void)tearDown - (void)createViewControllerWithViewModelRenderer:(HUBViewModelRenderer *)viewModelRenderer { - id const componentLayoutManager = [HUBComponentLayoutManagerMock new]; id const actionHandler = [[HUBActionHandlerWrapper alloc] initWithActionHandler:self.actionHandler actionRegistry:self.actionRegistry initialViewModelRegistry:self.initialViewModelRegistry @@ -229,9 +228,7 @@ - (void)createViewControllerWithViewModelRenderer:(HUBViewModelRenderer *)viewMo viewModelLoader:self.viewModelLoader viewModelRenderer:viewModelRenderer collectionViewFactory:self.collectionViewFactory - componentRegistry:self.componentRegistry componentReusePool:self.componentReusePool - componentLayoutManager:componentLayoutManager actionHandler:actionHandler scrollHandler:self.scrollHandler imageLoader:self.imageLoader]; diff --git a/tests/mocks/HUBCollectionViewFactoryMock.h b/tests/mocks/HUBCollectionViewFactoryMock.h index 577f08ca..cd40a694 100644 --- a/tests/mocks/HUBCollectionViewFactoryMock.h +++ b/tests/mocks/HUBCollectionViewFactoryMock.h @@ -26,13 +26,16 @@ NS_ASSUME_NONNULL_BEGIN /// Mocked collection view factory, for use in tests only @interface HUBCollectionViewFactoryMock : HUBCollectionViewFactory - /** * Initialize an instance of this class with a collection view * * @param collectionView A collection view that this factory will always create */ -- (instancetype)initWithCollectionView:(HUBCollectionView *)collectionView HUB_DESIGNATED_INITIALIZER; +- (instancetype)initWithCollectionView:(HUBCollectionView *)collectionView + componentRegistry:(id)componentRegistry HUB_DESIGNATED_INITIALIZER; + +- (instancetype)initWithComponentRegistry:(id)componentRegistry + componentLayoutManager:(id)componentLayoutManager NS_UNAVAILABLE; @end diff --git a/tests/mocks/HUBCollectionViewFactoryMock.m b/tests/mocks/HUBCollectionViewFactoryMock.m index c4180f23..6a907dfb 100644 --- a/tests/mocks/HUBCollectionViewFactoryMock.m +++ b/tests/mocks/HUBCollectionViewFactoryMock.m @@ -21,6 +21,9 @@ #import "HUBCollectionViewFactoryMock.h" +#import "HUBComponentLayoutManagerMock.h" +#import "HUBComponentRegistryMock.h" + NS_ASSUME_NONNULL_BEGIN @interface HUBCollectionViewFactoryMock () @@ -32,8 +35,10 @@ @interface HUBCollectionViewFactoryMock () @implementation HUBCollectionViewFactoryMock - (instancetype)initWithCollectionView:(HUBCollectionView *)collectionView + componentRegistry:(id)componentRegistry { - self = [super init]; + self = [super initWithComponentRegistry:componentRegistry + componentLayoutManager:[HUBComponentLayoutManagerMock new]]; if (self) { _collectionView = collectionView; diff --git a/tests/mocks/HUBCollectionViewMock.m b/tests/mocks/HUBCollectionViewMock.m index 4e07cf56..51b4b428 100644 --- a/tests/mocks/HUBCollectionViewMock.m +++ b/tests/mocks/HUBCollectionViewMock.m @@ -21,6 +21,8 @@ #import "HUBCollectionViewMock.h" +#import "HUBCollectionViewLayoutMock.h" + NS_ASSUME_NONNULL_BEGIN @interface HUBCollectionViewMock () @@ -34,7 +36,7 @@ @implementation HUBCollectionViewMock - (instancetype)init { - UICollectionViewLayout * const layout = [UICollectionViewFlowLayout new]; + HUBCollectionViewLayoutMock * const layout = [[HUBCollectionViewLayoutMock alloc] init]; if (!(self = [super initWithFrame:CGRectZero collectionViewLayout:layout])) { return nil; From 1dc142e3d9ae48c742a9eaaec1bce65d05b0cda0 Mon Sep 17 00:00:00 2001 From: Ceri Hughes Date: Wed, 12 Apr 2017 10:19:27 +0200 Subject: [PATCH 3/5] Revert unnecessary whitespace changes --- tests/mocks/HUBCollectionViewFactoryMock.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/mocks/HUBCollectionViewFactoryMock.h b/tests/mocks/HUBCollectionViewFactoryMock.h index cd40a694..0547812f 100644 --- a/tests/mocks/HUBCollectionViewFactoryMock.h +++ b/tests/mocks/HUBCollectionViewFactoryMock.h @@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN /// Mocked collection view factory, for use in tests only @interface HUBCollectionViewFactoryMock : HUBCollectionViewFactory + /** * Initialize an instance of this class with a collection view * From 0e354cc16228dd9893835cb22f8eb6978df309d9 Mon Sep 17 00:00:00 2001 From: Ceri Hughes Date: Wed, 12 Apr 2017 15:05:50 +0200 Subject: [PATCH 4/5] Fix tests --- tests/HUBViewControllerImplementationTests.m | 7 +++++-- tests/HUBViewModelRendererTests.m | 5 +++-- tests/mocks/HUBCollectionViewLayoutMock.h | 3 +-- tests/mocks/HUBCollectionViewLayoutMock.m | 6 +++--- tests/mocks/HUBCollectionViewMock.h | 2 ++ tests/mocks/HUBCollectionViewMock.m | 4 +--- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/HUBViewControllerImplementationTests.m b/tests/HUBViewControllerImplementationTests.m index 22c3f8d4..9d9d0ae9 100644 --- a/tests/HUBViewControllerImplementationTests.m +++ b/tests/HUBViewControllerImplementationTests.m @@ -33,6 +33,7 @@ #import "HUBImageLoaderMock.h" #import "HUBViewModelBuilder.h" #import "HUBViewModelRendererMock.h" +#import "HUBCollectionViewLayoutMock.h" #import "HUBComponentModelBuilder.h" #import "HUBComponentModel.h" #import "HUBComponentImageDataBuilder.h" @@ -69,6 +70,7 @@ @interface HUBViewControllerImplementationTests : XCTestCase )componentRegistry; /** * Returns the number of times that computeForCollectionViewSize:viewModel:diff:addHeaderMargin: was called. diff --git a/tests/mocks/HUBCollectionViewLayoutMock.m b/tests/mocks/HUBCollectionViewLayoutMock.m index dcc4808a..78315f44 100644 --- a/tests/mocks/HUBCollectionViewLayoutMock.m +++ b/tests/mocks/HUBCollectionViewLayoutMock.m @@ -22,7 +22,6 @@ #import "HUBCollectionViewLayoutMock.h" #import "HUBComponentLayoutManagerMock.h" -#import "HUBComponentRegistryMock.h" NS_ASSUME_NONNULL_BEGIN @@ -35,9 +34,9 @@ @interface HUBCollectionViewLayoutMock () @implementation HUBCollectionViewLayoutMock -- (instancetype)init +- (instancetype)initWithComponentRegistry:(id)componentRegistry { - self = [super initWithComponentRegistry:[HUBComponentRegistryMock new] componentLayoutManager:[HUBComponentLayoutManagerMock new]]; + self = [super initWithComponentRegistry:componentRegistry componentLayoutManager:[HUBComponentLayoutManagerMock new]]; if (self) { _capturedViewModels = [NSMutableArray array]; _capturedViewModelDiffs = [NSMutableArray array]; @@ -50,6 +49,7 @@ - (void)computeForCollectionViewSize:(CGSize)collectionViewSize diff:(nullable HUBViewModelDiff *)diff addHeaderMargin:(BOOL)addHeaderMargin { + [super computeForCollectionViewSize:collectionViewSize viewModel:viewModel diff:diff addHeaderMargin:addHeaderMargin]; [self.capturedViewModels addObject:viewModel]; HUBViewModelDiff *nonNullDiff = (diff == nil) ? (HUBViewModelDiff *)[NSNull null] : diff; [self.capturedViewModelDiffs addObject:nonNullDiff]; diff --git a/tests/mocks/HUBCollectionViewMock.h b/tests/mocks/HUBCollectionViewMock.h index 7480c6e2..3788083e 100644 --- a/tests/mocks/HUBCollectionViewMock.h +++ b/tests/mocks/HUBCollectionViewMock.h @@ -50,6 +50,8 @@ NS_ASSUME_NONNULL_BEGIN /// Whether the collection view should act like the user is dragging its content @property (nonatomic) BOOL mockedIsDragging; +- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout; + @end NS_ASSUME_NONNULL_END diff --git a/tests/mocks/HUBCollectionViewMock.m b/tests/mocks/HUBCollectionViewMock.m index 51b4b428..826099aa 100644 --- a/tests/mocks/HUBCollectionViewMock.m +++ b/tests/mocks/HUBCollectionViewMock.m @@ -34,10 +34,8 @@ @interface HUBCollectionViewMock () @implementation HUBCollectionViewMock -- (instancetype)init +- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout { - HUBCollectionViewLayoutMock * const layout = [[HUBCollectionViewLayoutMock alloc] init]; - if (!(self = [super initWithFrame:CGRectZero collectionViewLayout:layout])) { return nil; } From f679dfc3f5d0e662863b76c2d9779b53994e97b4 Mon Sep 17 00:00:00 2001 From: Ceri Hughes Date: Wed, 12 Apr 2017 15:12:45 +0200 Subject: [PATCH 5/5] Revert unnecessary changes. --- tests/HUBViewControllerImplementationTests.m | 7 +++---- tests/mocks/HUBCollectionViewMock.m | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/HUBViewControllerImplementationTests.m b/tests/HUBViewControllerImplementationTests.m index 9d9d0ae9..aa751cf1 100644 --- a/tests/HUBViewControllerImplementationTests.m +++ b/tests/HUBViewControllerImplementationTests.m @@ -33,7 +33,6 @@ #import "HUBImageLoaderMock.h" #import "HUBViewModelBuilder.h" #import "HUBViewModelRendererMock.h" -#import "HUBCollectionViewLayoutMock.h" #import "HUBComponentModelBuilder.h" #import "HUBComponentModel.h" #import "HUBComponentImageDataBuilder.h" @@ -44,6 +43,7 @@ #import "HUBComponentWrapper.h" #import "HUBCollectionViewFactoryMock.h" #import "HUBCollectionViewMock.h" +#import "HUBCollectionViewLayoutMock.h" #import "HUBActionHandlerMock.h" #import "HUBInitialViewModelRegistry.h" #import "HUBActionRegistryImplementation.h" @@ -70,7 +70,6 @@ @interface HUBViewControllerImplementationTests : XCTestCase