@@ -5,37 +5,27 @@ import XCTest
55#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
66final class FlushLogsIntegrationTests : XCTestCase {
77
8- private class Fixture {
9- let options : Options
10- let client : TestClient
11- let hub : SentryHubInternal
12- let dependencies : SentryDependencyContainer
13- let notificationCenterWrapper : TestNSNotificationCenterWrapper
14-
15- init ( ) throws {
16- options = Options ( )
17- options. dsn = TestConstants . dsnForTestCase ( type: FlushLogsIntegrationTests . self)
18- options. enableLogs = true
19-
20- client = TestClient ( options: options) !
21- hub = TestHub ( client: client, andScope: nil )
22- dependencies = SentryDependencyContainer . sharedInstance ( )
23- notificationCenterWrapper = TestNSNotificationCenterWrapper ( )
24- dependencies. notificationCenterWrapper = notificationCenterWrapper
25- }
26-
27- func getSut( ) -> FlushLogsIntegration < SentryDependencyContainer > ? {
28- return FlushLogsIntegration ( with: options, dependencies: dependencies)
29- }
30- }
31-
32- private var fixture : Fixture !
8+ private var options : Options !
9+ private var client : TestClient !
10+ private var hub : SentryHubInternal !
11+ private var dependencies : SentryDependencyContainer !
12+ private var notificationCenterWrapper : TestNSNotificationCenterWrapper !
3313 private var sut : FlushLogsIntegration < SentryDependencyContainer > ?
3414
3515 override func setUpWithError( ) throws {
3616 try super. setUpWithError ( )
37- fixture = try Fixture ( )
38- SentrySDKInternal . setCurrentHub ( fixture. hub)
17+
18+ options = Options ( )
19+ options. dsn = TestConstants . dsnForTestCase ( type: FlushLogsIntegrationTests . self)
20+ options. enableLogs = true
21+
22+ client = TestClient ( options: options) !
23+ hub = TestHub ( client: client, andScope: nil )
24+ dependencies = SentryDependencyContainer . sharedInstance ( )
25+ notificationCenterWrapper = TestNSNotificationCenterWrapper ( )
26+ dependencies. notificationCenterWrapper = notificationCenterWrapper
27+
28+ SentrySDKInternal . setCurrentHub ( hub)
3929 }
4030
4131 override func tearDown( ) {
@@ -45,61 +35,61 @@ final class FlushLogsIntegrationTests: XCTestCase {
4535 }
4636
4737 func testInstall_Success( ) {
48- sut = fixture . getSut ( )
38+ sut = FlushLogsIntegration ( with : options , dependencies : dependencies )
4939 XCTAssertNotNil ( sut)
5040 }
5141
5242 func testInstall_FailsWhenLogsDisabled( ) {
53- fixture . options. enableLogs = false
54- sut = fixture . getSut ( )
43+ options. enableLogs = false
44+ sut = FlushLogsIntegration ( with : options , dependencies : dependencies )
5545
5646 XCTAssertNil ( sut)
5747 }
5848
5949 func testName_ReturnsCorrectName( ) {
60- sut = fixture . getSut ( )
50+ sut = FlushLogsIntegration ( with : options , dependencies : dependencies )
6151
6252 XCTAssertEqual ( FlushLogsIntegration< SentryDependencyContainer> . name, " FlushLogsIntegration " )
6353 }
6454
6555 func testWillResignActive_FlushesLogs( ) {
66- sut = fixture . getSut ( )
56+ sut = FlushLogsIntegration ( with : options , dependencies : dependencies )
6757
68- fixture . notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willResignActiveNotification) )
58+ notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willResignActiveNotification) )
6959
70- XCTAssertEqual ( fixture . client. captureLogsInvocations. count, 1 )
60+ XCTAssertEqual ( client. captureLogsInvocations. count, 1 )
7161 }
7262
7363 func testWillTerminate_FlushesLogs( ) {
74- sut = fixture . getSut ( )
64+ sut = FlushLogsIntegration ( with : options , dependencies : dependencies )
7565
76- fixture . notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willTerminateNotification) )
66+ notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willTerminateNotification) )
7767
78- XCTAssertEqual ( fixture . client. captureLogsInvocations. count, 1 )
68+ XCTAssertEqual ( client. captureLogsInvocations. count, 1 )
7969 }
8070
8171 func testUninstall_RemovesObservers( ) {
82- guard let sut = fixture . getSut ( ) else {
72+ guard let sut = FlushLogsIntegration ( with : options , dependencies : dependencies ) else {
8373 XCTFail ( " Integration should be initialized " )
8474 return
8575 }
8676 sut. uninstall ( )
8777
88- fixture . notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willResignActiveNotification) )
89- fixture . notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willTerminateNotification) )
78+ notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willResignActiveNotification) )
79+ notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willTerminateNotification) )
9080
9181 // Should not flush logs after uninstall
92- XCTAssertEqual ( fixture . client. captureLogsInvocations. count, 0 )
82+ XCTAssertEqual ( client. captureLogsInvocations. count, 0 )
9383 }
9484
9585 func testMultipleNotifications_FlushesLogsMultipleTimes( ) {
96- sut = fixture . getSut ( )
86+ sut = FlushLogsIntegration ( with : options , dependencies : dependencies )
9787
98- fixture . notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willResignActiveNotification) )
99- fixture . notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willTerminateNotification) )
100- fixture . notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willResignActiveNotification) )
88+ notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willResignActiveNotification) )
89+ notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willTerminateNotification) )
90+ notificationCenterWrapper. post ( Notification ( name: CrossPlatformApplication . willResignActiveNotification) )
10191
102- XCTAssertEqual ( fixture . client. captureLogsInvocations. count, 3 )
92+ XCTAssertEqual ( client. captureLogsInvocations. count, 3 )
10393 }
10494}
10595#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
0 commit comments