Skip to content

Commit

Permalink
test: Fix asserts for SentryCrashTestInstallation (#2500)
Browse files Browse the repository at this point in the history
Two asserts wrapped with SentryCrashCRASH_HAS_UIAPPLICATION were not executed.
This is fixed now.
  • Loading branch information
philipphofmann authored Dec 12, 2022
1 parent bc27163 commit 6c7ab81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions Tests/SentryTests/Helper/TestNSNotificationCenterWrapper.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation

@objc public class TestNSNotificationCenterWrapper: SentryNSNotificationCenterWrapper {
@objcMembers public class TestNSNotificationCenterWrapper: SentryNSNotificationCenterWrapper {
var addObserverInvocations = Invocations<(observer: Any, selector: Selector, name: NSNotification.Name)>()
@objc public var addObserverInvocationsCount: Int {
public var addObserverInvocationsCount: Int {
return addObserverInvocations.count
}

Expand All @@ -12,12 +12,18 @@ import Foundation
}

var removeObserverWithNameInvocations = Invocations<(observer: Any, name: NSNotification.Name)>()
public var removeObserverWithNameInvocationsCount: Int {
return removeObserverWithNameInvocations.count
}
public override func removeObserver(_ observer: Any, name aName: NSNotification.Name) {
removeObserverWithNameInvocations.record((observer, aName))
NotificationCenter.default.removeObserver(observer, name: aName, object: nil)
}

var removeObserverInvocations = Invocations<Any>()
public var removeObserverInvocationsCount: Int {
return removeObserverInvocations.count
}
public override func removeObserver(_ observer: Any) {
removeObserverInvocations.record(observer)
NotificationCenter.default.removeObserver(observer)
Expand Down
5 changes: 3 additions & 2 deletions Tests/SentryTests/SentryCrash/SentryCrashInstallationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import "SentryCrashInstallation.h"
#import "SentryCrashMonitor.h"
#import "SentryCrashMonitor_MachException.h"
#import "SentryCrashSystemCapabilities.h"
#import "SentryNSNotificationCenterWrapper.h"
#import "SentryTests-Swift.h"
#import <XCTest/XCTest.h>
Expand Down Expand Up @@ -62,7 +63,7 @@ - (void)testUninstall_CallsRemoveObservers
[installation uninstall];

#if SentryCrashCRASH_HAS_UIAPPLICATION
XCTAssertEqual(5, self.notificationCenter.removeObserverWithNameInvocations.count);
XCTAssertEqual(5, self.notificationCenter.removeObserverWithNameInvocationsCount);
#endif
}

Expand Down Expand Up @@ -95,7 +96,7 @@ - (void)testUninstall_Install
crashHandlerDataAfterInstall:crashHandlerDataAfterInstall];

#if SentryCrashCRASH_HAS_UIAPPLICATION
XCTAssertEqual(55, self.notificationCenter.removeObserverWithNameInvocations.count);
XCTAssertEqual(55, self.notificationCenter.removeObserverWithNameInvocationsCount);
#endif
}

Expand Down

0 comments on commit 6c7ab81

Please sign in to comment.