diff --git a/Darkly/LDClient.h b/Darkly/LDClient.h index a6be9ce0..ac3e7d25 100644 --- a/Darkly/LDClient.h +++ b/Darkly/LDClient.h @@ -27,11 +27,11 @@ /** * Start the client with a valid configuration and user. * - * @param inputConfigBuilder Desired configuration for the client - * @param inputUserBuilder Desired user for the client - * @return whether the client was able to be started + * @param inputConfig Desired configuration for the client. + * @param inputUserBuilder Desired user for the client. + * @return whether the client was able to be started. */ -- (BOOL)start:(LDConfigBuilder *)inputConfigBuilder userBuilder:(LDUserBuilder *)inputUserBuilder; +- (BOOL)start:(LDConfig *)inputConfig userBuilder:(LDUserBuilder *)inputUserBuilder; /** * Retrieve a feature flag value. If the configuration for this feature * flag is retrieved from the server that value is returned, otherwise diff --git a/Darkly/LDClient.m b/Darkly/LDClient.m index 94707d71..a7fcf315 100644 --- a/Darkly/LDClient.m +++ b/Darkly/LDClient.m @@ -35,11 +35,11 @@ +(LDClient *)sharedInstance return sharedLDClient; } -- (BOOL)start:(LDConfigBuilder *)inputConfigBuilder userBuilder:(LDUserBuilder *)inputUserBuilder { +- (BOOL)start:(LDConfig *)inputConfig userBuilder:(LDUserBuilder *)inputUserBuilder { DEBUG_LOGX(@"LDClient start method called"); if (!clientStarted) { - if (inputConfigBuilder) { - ldConfig = [inputConfigBuilder build]; + if (inputConfig) { + ldConfig = inputConfig; if (ldConfig) { DarklyLogLevel logLevel = DarklyLogLevelCriticalOnly; if ([ldConfig debugEnabled]) { diff --git a/Darkly/LDConfig.h b/Darkly/LDConfig.h index 9dc47a01..229624d2 100644 --- a/Darkly/LDConfig.h +++ b/Darkly/LDConfig.h @@ -2,100 +2,71 @@ // Copyright © 2015 Catamorphic Co. All rights reserved. // -@interface LDConfig : NSObject { - -} +@interface LDConfig : NSObject -@property (nonatomic) NSString* mobileKey; -@property (nonatomic) NSString* baseUrl; -@property (nonatomic) NSString* eventsUrl; -@property (nonatomic) NSNumber* capacity; -@property (nonatomic) NSNumber* connectionTimeout; -@property (nonatomic) NSNumber* flushInterval; -@property (nonatomic) NSNumber* pollingInterval; -@property (nonatomic) BOOL streaming; -@property (nonatomic) BOOL debugEnabled; - -@end - -@interface LDConfigBuilder : NSObject { - -} +/** + This is the mobileKey retrieved from the Launch Darkly account settings. + */ +@property (nonatomic, readonly, nonnull) NSString* mobileKey; /** - * Provide an mobileKey to the configuration builder. This is the mobileKey - * retrieved from the Launch Darkly account settings. (Required) - * - * @param mobileKey the mobileKey for the configuration - * @return the configuration builder + The baseUrl of the Launch Darkly server. This will allow you to + switch between production and staging environments. */ -- (LDConfigBuilder *)withMobileKey:(NSString *)mobileKey; +@property (nonatomic, copy, nullable) NSString* baseUrl; + /** - * Provide the baseUrl of the Launch Darkly server. This will allow you - * to switch between production and staging environments. (Optional) - * - * @param baseUrl the baseUrl of the server - * @return the configuration builder + The eventsUrl of the Launch Darkly server. This will allow you + to switch between production and staging environments. */ -- (LDConfigBuilder *)withBaseUrl:(NSString *)baseUrl; +@property (nonatomic, copy, nullable) NSString* eventsUrl; + /** - * Provide the eventsUrl of the Launch Darkly server. This will allow you - * to switch between production and staging environments. (Optional) - * - * @param eventsUrl the eventsUrl of the server - * @return the configuration builder + The capacity for storing feature flag and custom events. Events + are persisted on the client and then synced to the server on a regular + basis. If there is ever a prolonged period of time between the last server + sync, the capacity defined here will determine at what points the events + are ignored and no longer stored. The default is 100. */ -- (LDConfigBuilder *)withEventsUrl:(NSString *)eventsUrl; +@property (nonatomic, copy, nullable) NSNumber* capacity; + /** - * Provide the capacity for storing feature flag and custom events. Events - * are persisted on the client and then synced to the server on a regular - * basis. If there is ever a prolonged period of time between the last server - * sync, the capacity defined here will determine at what points the events - * are ignored and no longer stored. The default is 100. (Optional) - * - * @param capacity the number of events to store - * @return the configuration builder + The connection timeout to be used when syncing to the Launch Darkly + server. The default is 10 seconds. */ -- (LDConfigBuilder *)withCapacity:(int)capacity; +@property (nonatomic, copy, nullable) NSNumber* connectionTimeout; + /** - * The connection timeout to be used when syncing to the Launch Darkly - * server. The default is 10 seconds. (Optional) - * - * @param connectionTimeout timeout for network connections in seconds - * @return the configuration builder + The interval at which events are synced to the server. The default + is 30 seconds for streaming mode; in polling mode, the flush interval defaults + to the polling interval. (Optional) */ -- (LDConfigBuilder *)withConnectionTimeout:(int)connectionTimeout; +@property (nonatomic, copy, nullable) NSNumber* flushInterval; + /** - * The interval at which events are synced to the server. The default - * is 30 seconds for streaming mode; in polling mode, the flush interval defaults to the polling interval. (Optional) - * - * @param flushInterval the flush interval in seconds - * @return the configuration builder + The polling interval (in seconds) for polling mode only. An interval + less than 300 is set to the default (5 minutes). */ -- (LDConfigBuilder *)withFlushInterval:(int)flushInterval; +@property (nonatomic, copy, nullable) NSNumber* pollingInterval; + /** - * Set the polling interval (in seconds) for polling mode only. An interval - * less than 300 is set to the default (5 minutes). - * - * @param pollingInterval the polling interval in seconds - * @return the configuration builder + Flag that enables streaming mode. When streaming is false, disable streaming + and switch to polling mode. */ -- (LDConfigBuilder *)withPollingInterval:(int)pollingInterval; +@property (nonatomic) BOOL streaming; + /** - * Enable streaming mode for flags. When streaming is false, disable streaming and switch to polling mode. (Optional) - * - * @param streamingEnabled Whether streaming is enabled or not - * @return the configuration builder + Flat that enables debug mode to allow things such as logging. */ -- (LDConfigBuilder *)withStreaming:(BOOL)streamingEnabled; +@property (nonatomic) BOOL debugEnabled; + /** - * Enable debug mode to allow things such as logging. (Optional) - * - * @param debugEnabled Whether debugging is enabled or not - * @return the configuration builder + Initializes an LDConfig object with the provided mobile key. + @param mobileKey The mobileKey retrieved from the Launch Darkly account settings. + @return An instance of LDConfig object. */ -- (LDConfigBuilder *)withDebugEnabled:(BOOL)debugEnabled; +- (instancetype _Nonnull)initWithMobileKey:(nonnull NSString *)mobileKey NS_DESIGNATED_INITIALIZER; --(LDConfig *)build; +- (instancetype _Nonnull )init NS_UNAVAILABLE; @end diff --git a/Darkly/LDConfig.m b/Darkly/LDConfig.m index 64b79cc1..6d24b2c0 100644 --- a/Darkly/LDConfig.m +++ b/Darkly/LDConfig.m @@ -5,149 +5,103 @@ #import "LDConfig.h" #import "LDUtil.h" -@implementation LDConfig - -@synthesize mobileKey, baseUrl, eventsUrl, capacity, connectionTimeout, flushInterval, pollingInterval, streaming, debugEnabled; - -@end - -@interface LDConfigBuilder() { - NSString *mobileKey; - NSString *baseUrl; - NSString *eventsUrl; - NSNumber *capacity; - NSNumber *connectionTimeout; - NSNumber *flushInterval; - NSNumber *pollingInterval; - BOOL streaming; - BOOL debugEnabled; -} - +@interface LDConfig() +@property (nonatomic, copy, nonnull) NSString* mobileKey; @end -@implementation LDConfigBuilder - -- (id)init { - self = [super init]; - streaming = YES; - return self; -} - -- (LDConfigBuilder *)withMobileKey:(NSString *)inputMobileKey -{ - mobileKey = inputMobileKey; - return self; -} - -- (LDConfigBuilder *)withBaseUrl:(NSString *)inputBaseUrl -{ - baseUrl = inputBaseUrl; - return self; -} - --(LDConfigBuilder *)withEventsUrl:(NSString *)inputEventsUrl{ - eventsUrl = inputEventsUrl; - return self; -} - -- (LDConfigBuilder *)withCapacity:(int)inputCapacity -{ - capacity = [NSNumber numberWithInt:inputCapacity]; - return self; -} - -- (LDConfigBuilder *)withConnectionTimeout:(int)inputConnectionTimeout -{ - connectionTimeout = [NSNumber numberWithInt:inputConnectionTimeout]; - return self; -} +@implementation LDConfig -- (LDConfigBuilder *)withFlushInterval:(int)inputFlushInterval -{ - flushInterval = [NSNumber numberWithInt:inputFlushInterval]; - return self; -} +- (instancetype)initWithMobileKey:(NSString *)mobileKey { + if (!(self = [super init])) { + return nil; + } -- (LDConfigBuilder *)withPollingInterval:(int)inputPollingInterval -{ - pollingInterval = [NSNumber numberWithInt:MAX(inputPollingInterval, kMinimumPollingInterval)]; - return self; -} + self.mobileKey = mobileKey; + self.streaming = YES; + self.capacity = [NSNumber numberWithInt:kCapacity]; + self.connectionTimeout = [NSNumber numberWithInt:kConnectionTimeout]; + self.flushInterval = [NSNumber numberWithInt:kDefaultFlushInterval]; + self.pollingInterval = [NSNumber numberWithInt:kDefaultPollingInterval]; + self.baseUrl = kBaseUrl; + self.eventsUrl = kEventsUrl; -- (LDConfigBuilder *)withStreaming:(BOOL)inputStreamingEnabled -{ - streaming = inputStreamingEnabled; return self; } -- (LDConfigBuilder *)withDebugEnabled:(BOOL)inputDebugEnabled -{ - debugEnabled = inputDebugEnabled; - return self; +- (void)setMobileKey:(NSString *)mobileKey { + _mobileKey = [mobileKey copy]; + DEBUG_LOG(@"Set LDConfig mobileKey: %@", mobileKey); } --(LDConfig *)build -{ - DEBUG_LOGX(@"LDConfigBuilder build method called"); - LDConfig *config = [[LDConfig alloc] init]; - if (mobileKey) { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with mobileKey: %@", mobileKey); - [config setMobileKey:mobileKey]; - } else { - DEBUG_LOGX(@"LDConfigBuilder requires an MobileKey"); - return nil; - } +- (void)setBaseUrl:(NSString *)baseUrl { if (baseUrl) { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with baseUrl: %@", baseUrl); - [config setBaseUrl:baseUrl]; + DEBUG_LOG(@"Set LDConfig baseUrl: %@", baseUrl); + _baseUrl = [baseUrl copy]; } else { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with default baseUrl: %@", kBaseUrl); - [config setBaseUrl:kBaseUrl]; + DEBUG_LOG(@"Set LDConfig default baseUrl: %@", kBaseUrl); + _baseUrl = kBaseUrl; } +} + +- (void)setEventsUrl:(NSString *)eventsUrl { if (eventsUrl) { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with eventsUrl: %@", eventsUrl); - [config setEventsUrl:eventsUrl]; + DEBUG_LOG(@"Set LDConfig eventsUrl: %@", eventsUrl); + _eventsUrl = [eventsUrl copy]; } else { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with default eventsUrl: %@", kEventsUrl); - [config setEventsUrl:kEventsUrl]; + DEBUG_LOG(@"Set LDConfig default eventsUrl: %@", kEventsUrl); + _eventsUrl = kEventsUrl; } +} + +- (void)setCapacity:(NSNumber *)capacity { if (capacity) { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with capacity: %@", capacity); - [config setCapacity:capacity]; + DEBUG_LOG(@"Set LDConfig capacity: %@", capacity); + _capacity = capacity; + } else { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with default capacity: %d", kCapacity); - [config setCapacity:[NSNumber numberWithInt:kCapacity]]; + DEBUG_LOG(@"Set LDConfig default capacity: %d", kCapacity); + _capacity = [NSNumber numberWithInt:kCapacity]; } +} + +- (void)setConnectionTimeout:(NSNumber *)connectionTimeout { if (connectionTimeout) { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with timeout: %@", connectionTimeout); - [config setConnectionTimeout:connectionTimeout]; + DEBUG_LOG(@"Set LDConfig timeout: %@", connectionTimeout); + _connectionTimeout = connectionTimeout; } else { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with default timeout: %d", kConnectionTimeout); - [config setConnectionTimeout:[NSNumber numberWithInt:kConnectionTimeout]]; + DEBUG_LOG(@"Set LDConfig default timeout: %d", kConnectionTimeout); + _connectionTimeout = [NSNumber numberWithInt:kConnectionTimeout]; } +} + +- (void)setFlushInterval:(NSNumber *)flushInterval { if (flushInterval) { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with flush interval: %@", flushInterval); - [config setFlushInterval:flushInterval]; + DEBUG_LOG(@"Set LDConfig flush interval: %@", flushInterval); + _flushInterval = flushInterval; } else { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with default flush interval: %d", kDefaultFlushInterval); - [config setFlushInterval:[NSNumber numberWithInt:kDefaultFlushInterval]]; + DEBUG_LOG(@"Set LDConfig default flush interval: %d", kDefaultFlushInterval); + _flushInterval = [NSNumber numberWithInt:kDefaultFlushInterval]; } +} + +- (void)setPollingInterval:(NSNumber *)pollingInterval { if (pollingInterval) { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with polling interval: %@", pollingInterval); - [config setPollingInterval:pollingInterval]; + DEBUG_LOG(@"Set LDConfig polling interval: %@", pollingInterval); + _pollingInterval = [NSNumber numberWithInt:MAX(pollingInterval.intValue, kMinimumPollingInterval)]; } else { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with default polling interval: %d", kDefaultPollingInterval); - [config setPollingInterval:[NSNumber numberWithInt:kDefaultPollingInterval]]; - } - - DEBUG_LOG(@"LDConfigBuilder building LDConfig with streaming enabled: %d", streaming); - [config setStreaming:streaming]; - - if (debugEnabled) { - DEBUG_LOG(@"LDConfigBuilder building LDConfig with debug enabled: %d", debugEnabled); - [config setDebugEnabled:debugEnabled]; + DEBUG_LOG(@"Set LDConfig default polling interval: %d", kDefaultPollingInterval); + _pollingInterval = [NSNumber numberWithInt:kDefaultPollingInterval]; } - return config; +} + +- (void)setStreaming:(BOOL)streaming { + _streaming = streaming; + DEBUG_LOG(@"Set LDConfig streaming enabled: %d", streaming); +} + +- (void)setDebugEnabled:(BOOL)debugEnabled { + _debugEnabled = debugEnabled; + DEBUG_LOG(@"Set LDConfig debug enabled: %d", debugEnabled); } @end diff --git a/DarklyTests/LDClientManagerTest.m b/DarklyTests/LDClientManagerTest.m index d6a7c95f..9867596b 100644 --- a/DarklyTests/LDClientManagerTest.m +++ b/DarklyTests/LDClientManagerTest.m @@ -31,11 +31,9 @@ - (void)setUp { LDUserBuilder *userBuilder = [[LDUserBuilder alloc] init]; userBuilder.key = @"jeff@test.com"; LDUserModel *user = [userBuilder build]; - - LDConfigBuilder *configBuilder = [[LDConfigBuilder alloc] init]; - configBuilder = [configBuilder withFlushInterval:30]; - LDConfig *config = [configBuilder build]; - + LDConfig *config = [[LDConfig alloc] initWithMobileKey:@""]; + config.flushInterval = [NSNumber numberWithInt:30]; + ldClientMock = OCMClassMock([LDClient class]); OCMStub(ClassMethod([ldClientMock sharedInstance])).andReturn(ldClientMock); OCMStub([ldClientMock ldUser]).andReturn(user); diff --git a/DarklyTests/LDClientTest.m b/DarklyTests/LDClientTest.m index 5f255037..32b2b221 100644 --- a/DarklyTests/LDClientTest.m +++ b/DarklyTests/LDClientTest.m @@ -41,40 +41,36 @@ - (void)testStartWithoutConfig { - (void)testStartWithValidConfig { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; LDClient *client = [LDClient sharedInstance]; - BOOL didStart = [client start:builder userBuilder:nil]; + BOOL didStart = [client start:config userBuilder:nil]; XCTAssertTrue(didStart); } - (void)testStartWithValidConfigMultipleTimes { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - XCTAssertTrue([[LDClient sharedInstance] start:builder userBuilder:nil]); - XCTAssertFalse([[LDClient sharedInstance] start:builder userBuilder:nil]); + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + XCTAssertTrue([[LDClient sharedInstance] start:config userBuilder:nil]); + XCTAssertFalse([[LDClient sharedInstance] start:config userBuilder:nil]); } - (void)testBoolVariationWithStart { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - [[LDClient sharedInstance] start:builder userBuilder:nil]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + [[LDClient sharedInstance] start:config userBuilder:nil]; BOOL boolValue = [[LDClient sharedInstance] boolVariation:@"test" fallback:YES]; XCTAssertTrue(boolValue); } - (void)testUserPersisted { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; LDUserBuilder *userBuilder = [[LDUserBuilder alloc] init]; userBuilder.key = @"myKey"; userBuilder.email = @"my@email.com"; - [[LDClient sharedInstance] start:builder userBuilder:userBuilder]; + [[LDClient sharedInstance] start:config userBuilder:userBuilder]; BOOL toggleValue = [[LDClient sharedInstance] boolVariation:@"test" fallback:YES]; XCTAssertTrue(toggleValue); @@ -84,7 +80,7 @@ - (void)testUserPersisted { LDUserModel *user = [[LDClient sharedInstance] ldUser]; OCMStub([self.dataManagerMock findUserWithkey:[OCMArg any]]).andReturn(user); - [[LDClient sharedInstance] start:builder userBuilder:anotherUserBuilder]; + [[LDClient sharedInstance] start:config userBuilder:anotherUserBuilder]; user = [[LDClient sharedInstance] ldUser]; XCTAssertEqual(user.email, @"my@email.com"); @@ -94,10 +90,9 @@ -(void)testToggleCreatesEventWithCorrectArguments { NSString *toggleName = @"test"; BOOL fallbackValue = YES; NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; OCMStub([self.dataManagerMock createFeatureEvent:[OCMArg any] keyValue:[OCMArg any] defaultKeyValue:[OCMArg any]]); - [[LDClient sharedInstance] start:builder userBuilder:nil]; + [[LDClient sharedInstance] start:config userBuilder:nil]; [[LDClient sharedInstance] boolVariation:toggleName fallback:fallbackValue]; OCMVerify([self.dataManagerMock createFeatureEvent:toggleName keyValue:[NSNumber numberWithBool:fallbackValue] defaultKeyValue:[NSNumber numberWithBool:fallbackValue]]); @@ -111,10 +106,8 @@ - (void)testTrackWithoutStart { - (void)testTrackWithStart { NSDictionary *customData = @{@"key": @"value"}; NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - [[LDClient sharedInstance] start:builder userBuilder:nil]; - + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + [[LDClient sharedInstance] start:config userBuilder:nil]; OCMStub([self.dataManagerMock createCustomEvent:[OCMArg isKindOfClass:[NSString class]] withCustomValuesDictionary:[OCMArg isKindOfClass:[NSDictionary class]]]); @@ -122,7 +115,6 @@ - (void)testTrackWithStart { OCMVerify([self.dataManagerMock createCustomEvent: @"test" withCustomValuesDictionary: customData]); - } - (void)testOfflineWithoutStart { @@ -131,22 +123,19 @@ - (void)testOfflineWithoutStart { - (void)testOfflineWithStart { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - [[LDClient sharedInstance] start:builder userBuilder:nil]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + [[LDClient sharedInstance] start:config userBuilder:nil]; XCTAssertTrue([[LDClient sharedInstance] offline]); } - - (void)testOnlineWithoutStart { XCTAssertFalse([[LDClient sharedInstance] online]); } - (void)testOnlineWithStart { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - [[LDClient sharedInstance] start:builder userBuilder:nil]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + [[LDClient sharedInstance] start:config userBuilder:nil]; XCTAssertTrue([[LDClient sharedInstance] online]); } @@ -156,9 +145,8 @@ - (void)testFlushWithoutStart { - (void)testFlushWithStart { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - [[LDClient sharedInstance] start:builder userBuilder:nil]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + [[LDClient sharedInstance] start:config userBuilder:nil]; XCTAssertTrue([[LDClient sharedInstance] flush]); } @@ -168,12 +156,11 @@ - (void)testUpdateUserWithoutStart { -(void)testUpdateUserWithStart { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *configBuilder = [[LDConfigBuilder alloc] init]; - [configBuilder withMobileKey:testMobileKey]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; LDUserBuilder *userBuilder = [[LDUserBuilder alloc] init]; LDClient *ldClient = [LDClient sharedInstance]; - [ldClient start:configBuilder userBuilder:userBuilder]; + [ldClient start:config userBuilder:userBuilder]; XCTAssertTrue([[LDClient sharedInstance] updateUser:[[LDUserBuilder alloc] init]]); } @@ -184,12 +171,11 @@ - (void)testCurrentUserBuilderWithoutStart { -(void)testCurrentUserBuilderWithStart { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *configBuilder = [[LDConfigBuilder alloc] init]; - [configBuilder withMobileKey:testMobileKey]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; LDUserBuilder *userBuilder = [[LDUserBuilder alloc] init]; LDClient *ldClient = [LDClient sharedInstance]; - [ldClient start:configBuilder userBuilder:userBuilder]; + [ldClient start:config userBuilder:userBuilder]; XCTAssertNotNil([[LDClient sharedInstance] currentUserBuilder]); } @@ -201,5 +187,4 @@ - (void)testDelegateSet { XCTAssertEqualObjects(self, ldClient.delegate); } - @end diff --git a/DarklyTests/LDConfigTest.m b/DarklyTests/LDConfigTest.m index 2c484c41..e64f0bd8 100644 --- a/DarklyTests/LDConfigTest.m +++ b/DarklyTests/LDConfigTest.m @@ -21,16 +21,9 @@ - (void)tearDown { [super tearDown]; } -- (void)testConfigWithoutMobileKey { - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - XCTAssertNil([builder build]); -} - - (void)testConfigDefaultValues { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - LDConfig *config = [builder build]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; XCTAssertEqualObjects([config mobileKey], testMobileKey); XCTAssertEqualObjects([config capacity], [NSNumber numberWithInt:kCapacity]); XCTAssertEqualObjects([config connectionTimeout], [NSNumber numberWithInt:kConnectionTimeout]); @@ -41,10 +34,8 @@ - (void)testConfigDefaultValues { - (void)testConfigOverrideBaseUrl { NSString *testMobileKey = @"testMobileKey"; NSString *testBaseUrl = @"testBaseUrl"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - [builder withBaseUrl:testBaseUrl]; - LDConfig *config = [builder build]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + config.baseUrl = testBaseUrl; XCTAssertEqualObjects([config mobileKey], testMobileKey); XCTAssertEqualObjects([config capacity], [NSNumber numberWithInt:kCapacity]); XCTAssertEqualObjects([config connectionTimeout], [NSNumber numberWithInt:kConnectionTimeout]); @@ -55,10 +46,8 @@ - (void)testConfigOverrideBaseUrl { - (void)testConfigOverrideCapacity { NSString *testMobileKey = @"testMobileKey"; int testCapacity = 20; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - [builder withCapacity:testCapacity]; - LDConfig *config = [builder build]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + config.capacity = [NSNumber numberWithInt:testCapacity]; XCTAssertEqualObjects([config mobileKey], testMobileKey); XCTAssertEqualObjects([config capacity], [NSNumber numberWithInt:testCapacity]); XCTAssertEqualObjects([config connectionTimeout], [NSNumber numberWithInt:kConnectionTimeout]); @@ -69,10 +58,8 @@ - (void)testConfigOverrideCapacity { - (void)testConfigOverrideConnectionTimeout { NSString *testMobileKey = @"testMobileKey"; int testConnectionTimeout = 15; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - [builder withConnectionTimeout:testConnectionTimeout]; - LDConfig *config = [builder build]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + config.connectionTimeout = [NSNumber numberWithInt:testConnectionTimeout]; XCTAssertEqualObjects([config mobileKey], testMobileKey); XCTAssertEqualObjects([config capacity], [NSNumber numberWithInt:kCapacity]); XCTAssertEqualObjects([config connectionTimeout], [NSNumber numberWithInt:testConnectionTimeout]); @@ -83,10 +70,8 @@ - (void)testConfigOverrideConnectionTimeout { - (void)testConfigOverrideFlushInterval { NSString *testMobileKey = @"testMobileKey"; int testFlushInterval = 5; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - [builder withFlushInterval:testFlushInterval]; - LDConfig *config = [builder build]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + config.flushInterval = [NSNumber numberWithInt:testFlushInterval]; XCTAssertEqualObjects([config mobileKey], testMobileKey); XCTAssertEqualObjects([config capacity], [NSNumber numberWithInt:kCapacity]); XCTAssertEqualObjects([config connectionTimeout], [NSNumber numberWithInt:kConnectionTimeout]); @@ -96,43 +81,34 @@ - (void)testConfigOverrideFlushInterval { - (void)testConfigOverridePollingInterval { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - - LDConfig *config = [builder build]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; XCTAssertEqualObjects([config mobileKey], testMobileKey); XCTAssertEqualObjects([config pollingInterval], [NSNumber numberWithInt:kDefaultPollingInterval]); XCTAssertFalse([config debugEnabled]); - - [builder withPollingInterval:5000]; - config = [builder build]; - XCTAssertEqualObjects([config pollingInterval], [NSNumber numberWithInt:5000]); - - [builder withPollingInterval:50]; - config = [builder build]; + + NSNumber *pollingInterval = [NSNumber numberWithInt:5000]; + config.pollingInterval = pollingInterval; + XCTAssertEqualObjects(config.pollingInterval, pollingInterval); + + pollingInterval = [NSNumber numberWithInt:50]; + config.pollingInterval = pollingInterval; XCTAssertEqualObjects([config pollingInterval], [NSNumber numberWithInt:kMinimumPollingInterval]); } - (void)testConfigOverrideStreaming { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - - LDConfig *config = [builder build]; - XCTAssertEqualObjects([config mobileKey], testMobileKey); - XCTAssertTrue([config streaming]); + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + XCTAssertEqualObjects(config.mobileKey, testMobileKey); + XCTAssertTrue(config.streaming); - [builder withStreaming:NO]; - config = [builder build]; - XCTAssertFalse([config streaming]); + config.streaming = NO; + XCTAssertFalse(config.streaming); } - (void)testConfigOverrideDebug { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; - [builder withDebugEnabled:YES]; - LDConfig *config = [builder build]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; + config.debugEnabled = YES; XCTAssertEqualObjects([config mobileKey], testMobileKey); XCTAssertEqualObjects([config capacity], [NSNumber numberWithInt:kCapacity]); XCTAssertEqualObjects([config connectionTimeout], [NSNumber numberWithInt:kConnectionTimeout]); diff --git a/DarklyTests/LDPollingManagerTest.m b/DarklyTests/LDPollingManagerTest.m index 3e846497..0ec0ac6e 100644 --- a/DarklyTests/LDPollingManagerTest.m +++ b/DarklyTests/LDPollingManagerTest.m @@ -64,31 +64,30 @@ - (void)testEventPollingStates { - (void)testPollingInterval { NSString *testMobileKey = @"testMobileKey"; - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - [builder withMobileKey:testMobileKey]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:testMobileKey]; LDClient *client = [LDClient sharedInstance]; LDPollingManager *pollingManager = [LDPollingManager sharedInstance]; - [client start:builder userBuilder:nil]; + [client start:config userBuilder:nil]; XCTAssertEqual(pollingManager.eventPollingIntervalMillis, kDefaultFlushInterval*kMillisInSecs); XCTAssertEqual([pollingManager configPollingState], POLL_STOPPED); [client stopClient]; - - [builder withStreaming:NO]; - [client start:builder userBuilder:nil]; + + config.streaming = NO; + [client start:config userBuilder:nil]; XCTAssertEqual(pollingManager.eventPollingIntervalMillis, kDefaultPollingInterval*kMillisInSecs); XCTAssertEqual(pollingManager.configPollingIntervalMillis, kDefaultPollingInterval*kMillisInSecs); XCTAssertEqual([pollingManager configPollingState], POLL_RUNNING); [client stopClient]; - - [builder withPollingInterval:50]; - [client start:builder userBuilder:nil]; + + config.pollingInterval = [NSNumber numberWithInt:50]; + [client start:config userBuilder:nil]; XCTAssertEqual(pollingManager.eventPollingIntervalMillis, kMinimumPollingInterval*kMillisInSecs); XCTAssertEqual(pollingManager.configPollingIntervalMillis, kMinimumPollingInterval*kMillisInSecs); [client stopClient]; - - [builder withFlushInterval:50]; - [client start:builder userBuilder:nil]; + + config.flushInterval = [NSNumber numberWithInt:50]; + [client start:config userBuilder:nil]; XCTAssertEqual(pollingManager.eventPollingIntervalMillis, 50*kMillisInSecs); XCTAssertEqual(pollingManager.configPollingIntervalMillis, kMinimumPollingInterval*kMillisInSecs); [client stopClient]; diff --git a/DarklyTests/LDRequestManagerTest.m b/DarklyTests/LDRequestManagerTest.m index 5cba6bda..89a1f208 100644 --- a/DarklyTests/LDRequestManagerTest.m +++ b/DarklyTests/LDRequestManagerTest.m @@ -29,12 +29,10 @@ - (void)setUp { LDUserBuilder *userBuilder = [[LDUserBuilder alloc] init]; userBuilder.key = @"jeff@test.com"; LDUserModel *user = [userBuilder build]; - - LDConfigBuilder *configBuilder = [[LDConfigBuilder alloc] init]; + LDConfig *config = [[LDConfig alloc] initWithMobileKey:@"testMobileKey"]; tempFlushInterval = 30; - configBuilder = [configBuilder withFlushInterval:tempFlushInterval]; - LDConfig *config = [configBuilder build]; - + config.flushInterval = [NSNumber numberWithInt:tempFlushInterval]; + ldClientMock = OCMClassMock([LDClient class]); OCMStub(ClassMethod([ldClientMock sharedInstance])).andReturn(ldClientMock); OCMStub([ldClientMock ldUser]).andReturn(user); diff --git a/DarklyTests/Models/LDDataManagerTest.m b/DarklyTests/Models/LDDataManagerTest.m index 094b8f1c..a61de203 100644 --- a/DarklyTests/Models/LDDataManagerTest.m +++ b/DarklyTests/Models/LDDataManagerTest.m @@ -134,12 +134,9 @@ -(void) testPurgeUsers { XCTAssertNotNil(fourthCreatedUser); } --(void)testCreateEventAfterCapacityReached{ - LDConfigBuilder *builder = [[LDConfigBuilder alloc] init]; - builder = [builder withCapacity: 2]; - builder = [builder withMobileKey: @"AMobileKey"]; - LDConfig *config = [builder build]; - +-(void)testCreateEventAfterCapacityReached { + LDConfig *config = [[LDConfig alloc] initWithMobileKey:@"AMobileKey"]; + config.capacity = [NSNumber numberWithInt:2]; OCMStub([clientMock ldConfig]).andReturn(config); LDDataManager *manager = [LDDataManager sharedManager];