Authored by 周蓉君

更新YH_Analytics测试样例。Review by 阿瑟。

@@ -102,7 +102,21 @@ static dispatch_queue_t persisitingQueue; @@ -102,7 +102,21 @@ static dispatch_queue_t persisitingQueue;
102 return _locationManager; 102 return _locationManager;
103 } 103 }
104 104
105 -#pragma mark - Functions 105 +- (void)setLogStrategy:(YHLogStrategy)strategyNumber
  106 +{
  107 + NSUserDefaults *strategy = [NSUserDefaults standardUserDefaults];
  108 + [strategy setObject: [NSNumber numberWithInteger:strategyNumber] forKey:@"LOGSTRATEGY"];
  109 + [strategy synchronize];
  110 +}
  111 +
  112 +- (YHLogStrategy)logStrategy
  113 +{
  114 + NSUserDefaults *strategy = [NSUserDefaults standardUserDefaults];
  115 + NSNumber * strategyObj = [strategy objectForKey:@"LOGSTRATEGY"];
  116 + return [strategyObj intValue];
  117 +}
  118 +
  119 +#pragma mark - Private Method
106 120
107 // 添加网络监测回调block 121 // 添加网络监测回调block
108 - (void)startObserverNetworkReachabilityStatus 122 - (void)startObserverNetworkReachabilityStatus
@@ -185,6 +199,36 @@ static dispatch_queue_t persisitingQueue; @@ -185,6 +199,36 @@ static dispatch_queue_t persisitingQueue;
185 self.session = nil; 199 self.session = nil;
186 } 200 }
187 201
  202 +- (NSString *)timestamp
  203 +{
  204 + long long now = [[NSDate date] timeIntervalSince1970];
  205 + long long int date = (long long int)now;
  206 + return [NSString stringWithFormat:@"%lld", date];
  207 +}
  208 +
  209 +// 发送本地持久化数据
  210 +- (void)uploadDiskData
  211 +{
  212 + [[YHAssemblyAssistant sharedInstance] uploadDiskData];
  213 +}
  214 +
  215 +// 发送本地持久化数据
  216 +- (void)tryUploadDiskData
  217 +{
  218 + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  219 + NSString *lastUploadTime = [defaults objectForKey:kKeyUserDefaultsLastUploadTimestamp];
  220 + NSString *timeStamp = [self timestamp];
  221 + NSInteger uploadTimeInterval = [timeStamp integerValue] - [lastUploadTime integerValue];
  222 +
  223 + if (uploadTimeInterval > self.currentInterval) {
  224 + [self uploadDiskData];
  225 + [defaults setObject:timeStamp forKey:kKeyUserDefaultsLastUploadTimestamp];
  226 + [defaults synchronize];
  227 + }
  228 +}
  229 +
  230 +#pragma mark - Public Method
  231 +
188 - (void)startWithAppId:(NSString *)appId 232 - (void)startWithAppId:(NSString *)appId
189 { 233 {
190 [self startObserverNetworkReachabilityStatus]; 234 [self startObserverNetworkReachabilityStatus];
@@ -281,35 +325,6 @@ static dispatch_queue_t persisitingQueue; @@ -281,35 +325,6 @@ static dispatch_queue_t persisitingQueue;
281 } 325 }
282 326
283 327
284 -- (NSString *)timestamp  
285 -{  
286 - long long now = [[NSDate date] timeIntervalSince1970];  
287 - long long int date = (long long int)now;  
288 - return [NSString stringWithFormat:@"%lld", date];  
289 -}  
290 -  
291 -// 发送本地持久化数据  
292 -- (void)uploadDiskData  
293 -{  
294 - [[YHAssemblyAssistant sharedInstance] uploadDiskData];  
295 -}  
296 -  
297 -// 发送本地持久化数据  
298 -- (void)tryUploadDiskData  
299 -{  
300 - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];  
301 - NSString *lastUploadTime = [defaults objectForKey:kKeyUserDefaultsLastUploadTimestamp];  
302 - NSString *timeStamp = [self timestamp];  
303 - NSInteger uploadTimeInterval = [timeStamp integerValue] - [lastUploadTime integerValue];  
304 -  
305 - if (uploadTimeInterval > self.currentInterval) {  
306 - [self uploadDiskData];  
307 - [defaults setObject:timeStamp forKey:kKeyUserDefaultsLastUploadTimestamp];  
308 - [defaults synchronize];  
309 - }  
310 -}  
311 -  
312 -#pragma mark - Location  
313 #pragma mark - CLLocationManagerDelegate 328 #pragma mark - CLLocationManagerDelegate
314 329
315 - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status 330 - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
@@ -345,18 +360,4 @@ static dispatch_queue_t persisitingQueue; @@ -345,18 +360,4 @@ static dispatch_queue_t persisitingQueue;
345 NSLog(@"%@", errorMsg); 360 NSLog(@"%@", errorMsg);
346 } 361 }
347 362
348 -  
349 -- (void)setLogStrategy:(YHLogStrategy)strategyNumber  
350 -{  
351 - NSUserDefaults *strategy = [NSUserDefaults standardUserDefaults];  
352 - [strategy setObject: [NSNumber numberWithInteger:strategyNumber] forKey:@"LOGSTRATEGY"];  
353 - [strategy synchronize];  
354 -}  
355 -  
356 -- (YHLogStrategy)logStrategy  
357 -{  
358 - NSUserDefaults *strategy = [NSUserDefaults standardUserDefaults];  
359 - NSNumber * strategyObj = [strategy objectForKey:@"LOGSTRATEGY"];  
360 - return [strategyObj intValue];  
361 -}  
362 @end 363 @end
@@ -47,6 +47,10 @@ @@ -47,6 +47,10 @@
47 47
48 - (void)tearDown { 48 - (void)tearDown {
49 // Put teardown code here. This method is called after the invocation of each test method in the class. 49 // Put teardown code here. This method is called after the invocation of each test method in the class.
  50 + assemblyAssistantMock = nil;
  51 + crashReporterMock = nil;
  52 + networkAssistantMock = nil;
  53 + analytics = nil;
50 [super tearDown]; 54 [super tearDown];
51 } 55 }
52 56
@@ -39,8 +39,8 @@ @@ -39,8 +39,8 @@
39 - (void)testStartWithAppIdMethodWithConstraint { 39 - (void)testStartWithAppIdMethodWithConstraint {
40 NSLog(@"%@ start", self.name); // self.name is the name of the test-case method. 40 NSLog(@"%@ start", self.name); // self.name is the name of the test-case method.
41 41
42 - [[mock stub] startWithAppId:[OCMArg any]];  
43 - [mock startWithAppId:[OCMArg any]]; 42 + [[mock stub] startWithAppId:[OCMArg isKindOfClass:[NSString class]]];
  43 + [mock startWithAppId:@"appId"];
44 44
45 NSLog(@"%@ end", self.name); 45 NSLog(@"%@ end", self.name);
46 } 46 }
@@ -48,7 +48,7 @@ @@ -48,7 +48,7 @@
48 - (void)testLogEventMethodWithConstraint { 48 - (void)testLogEventMethodWithConstraint {
49 NSLog(@"%@ start", self.name); 49 NSLog(@"%@ start", self.name);
50 50
51 - [[mock stub] logEvent:[OCMArg any] parameters:[OCMArg any]]; 51 + [[mock stub] logEvent:[OCMArg isKindOfClass:[NSString class]] parameters:[OCMArg isKindOfClass:[NSDictionary class]]];
52 [mock logEvent:@"event" parameters:nil]; 52 [mock logEvent:@"event" parameters:nil];
53 53
54 NSLog(@"%@ end", self.name); 54 NSLog(@"%@ end", self.name);
@@ -57,7 +57,7 @@ @@ -57,7 +57,7 @@
57 - (void)testLogErrorMethodWithConstraint { 57 - (void)testLogErrorMethodWithConstraint {
58 NSLog(@"%@ start", self.name); 58 NSLog(@"%@ start", self.name);
59 59
60 - [[mock stub] logError:[OCMArg any] parameters:[OCMArg any]]; 60 + [[mock stub] logError:[OCMArg isKindOfClass:[NSString class]] parameters:[OCMArg isKindOfClass:[NSDictionary class]]];
61 [mock logError:@"error" parameters:nil]; 61 [mock logError:@"error" parameters:nil];
62 62
63 NSLog(@"%@ end", self.name); 63 NSLog(@"%@ end", self.name);