diff --git a/Support/HockeySDKTests/BITTelemetryManagerTests.m b/Support/HockeySDKTests/BITTelemetryManagerTests.m index 497df5146c..c179d1e86a 100644 --- a/Support/HockeySDKTests/BITTelemetryManagerTests.m +++ b/Support/HockeySDKTests/BITTelemetryManagerTests.m @@ -2,7 +2,9 @@ #import #import "BITTestsDependencyInjection.h" #import "BITTelemetryManager.h" +#import "BITTelemetryManagerPrivate.h" #import "BITHockeyBaseManagerPrivate.h" +#import "BITSession.h" #define HC_SHORTHAND #import @@ -24,13 +26,35 @@ } - (void)tearDown { - // Put teardown code here. This method is called after the invocation of each test method in the class. [super tearDown]; } +- (void)testTelemetryManagerGetsInstantiated { + self.sut = [BITTelemetryManager new]; + XCTAssertNotNil(self.sut, @"Should not be nil."); +} + +- (void)testNewSessionIsCreatedCorrectly { + self.sut = [BITTelemetryManager new]; + [self.mockUserDefaults setBool:NO forKey:@"BITApplicationWasLaunched"]; + NSString *testSessionId1 = @"12345"; + NSString *testSessionId2 = @"67890"; + + // First session + BITSession *actualSession1 = [self.sut createNewSessionWithId:testSessionId1]; + XCTAssertEqualObjects(actualSession1.sessionId, testSessionId1); + XCTAssertEqualObjects(actualSession1.isNew, @"true"); + XCTAssertEqualObjects(actualSession1.isFirst, @"true"); + + // Next sessions + BITSession *actualSession2 = [self.sut createNewSessionWithId:testSessionId2]; + XCTAssertEqualObjects(actualSession2.sessionId, testSessionId2); + XCTAssertEqualObjects(actualSession2.isNew, @"true"); + XCTAssertEqualObjects(actualSession2.isFirst, @"false"); +} + - (void)testRegisterObserversOnStart { self.mockNotificationCenter = mock(NSNotificationCenter.class); - self.sut = [BITTelemetryManager new]; [self.sut startManager]; diff --git a/Support/HockeySDKTests/BITTestsDependencyInjection.m b/Support/HockeySDKTests/BITTestsDependencyInjection.m index d9110a9a90..81315a9978 100644 --- a/Support/HockeySDKTests/BITTestsDependencyInjection.m +++ b/Support/HockeySDKTests/BITTestsDependencyInjection.m @@ -23,8 +23,8 @@ static id mockCenter; } - (void)tearDown { - [super tearDown]; mockUserDefaults = nil; + [super tearDown]; } # pragma mark - Helper