Skip to content

Commit 000d233

Browse files
committed
Added a mock sharedInstance to fix watchOS crash
1 parent 3945ad4 commit 000d233

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Tests/Unit-Tests/NewRelicAgentTests/Analytics-Tests/PersistentStoreTests.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#import "NRMACustomEvent.h"
1515
#import "NRMARequestEvent.h"
1616
#import "NRMAInteractionEvent.h"
17+
#import "NewRelicAgentInternal.h"
18+
#import <OCMock/OCMock.h>
1719

1820
#import "BlockAttributeValidator.h"
1921
#import "NRMAFlags.h"
@@ -65,8 +67,12 @@ - (nullable instancetype)initWithCoder:(nonnull NSCoder *)coder {
6567
@end
6668

6769
@interface PersistentStoreTests : XCTestCase
70+
@property id mockNewRelicInternals;
71+
6872
@end
6973

74+
static NewRelicAgentInternal* _sharedInstance;
75+
7076
@implementation PersistentStoreTests {
7177
BlockAttributeValidator *agreeableAttributeValidator;
7278
}
@@ -77,7 +83,11 @@ @implementation PersistentStoreTests {
7783

7884
- (void)setUp {
7985
[super setUp];
80-
86+
self.mockNewRelicInternals = [OCMockObject mockForClass:[NewRelicAgentInternal class]];
87+
_sharedInstance = [[NewRelicAgentInternal alloc] init];
88+
_sharedInstance.analyticsController = [[NRMAAnalytics alloc] initWithSessionStartTimeMS:0.0];
89+
[[[[self.mockNewRelicInternals stub] classMethod] andReturn:_sharedInstance] sharedInstance];
90+
8191
if(agreeableAttributeValidator == nil) {
8292
agreeableAttributeValidator = [[BlockAttributeValidator alloc] initWithNameValidator:^BOOL(NSString *) {
8393
return YES;

0 commit comments

Comments
 (0)