diff --git a/Tests/NetworkReachabilityTests/NetworkMonitorCombineTests.swift b/Tests/NetworkReachabilityTests/NetworkMonitorCombineTests.swift new file mode 100644 index 00000000..70d57470 --- /dev/null +++ b/Tests/NetworkReachabilityTests/NetworkMonitorCombineTests.swift @@ -0,0 +1,61 @@ +// NetworkReachabiliy +// NetworkMonitorCombineTests.swift +// +// MIT License +// +// Copyright (c) 2021 Varun Santhanam +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#if canImport(Network) + import Network +#endif + +#if canImport(Combine) + + import Combine + import Foundation + @testable import NetworkReachability + import XCTest + + @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) + final class NetworkMonitorCombineTests: XCTestCase { + + var cancellable: AnyCancellable? + + @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) + func test_observe_combine() { + let expectation = expectation(description: "pass") + cancellable = NetworkMonitor + .networkPathPublisher + .map { $0.status == .satisfied } + .removeDuplicates() + .sink { isReachable in + XCTAssertTrue(isReachable) + expectation.fulfill() + } + waitForExpectations(timeout: 5) + } + + deinit { + cancellable?.cancel() + } + } + +#endif diff --git a/Tests/NetworkReachabilityTests/NetworkMonitorConcurrencyTests.swift b/Tests/NetworkReachabilityTests/NetworkMonitorConcurrencyTests.swift new file mode 100644 index 00000000..bfd9a146 --- /dev/null +++ b/Tests/NetworkReachabilityTests/NetworkMonitorConcurrencyTests.swift @@ -0,0 +1,55 @@ +// NetworkReachabiliy +// NetworkMonitorConcurrencyTests.swift +// +// MIT License +// +// Copyright (c) 2021 Varun Santhanam +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#if canImport(Network) + import Network +#endif + +import Foundation +@testable import NetworkReachability +import XCTest + +@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) +final class NetworkMonitorConcurrencyTests: XCTestCase { + + func test_get_concurrency() async { + let path = await NetworkMonitor.networkPath + XCTAssertEqual(path.status, .satisfied) + } + + func test_observe_concurrency() { + let expectation = expectation(description: "pass") + + Task { + for await status in NetworkMonitor.networkPathUpdates.map(\.status) { + if status == .satisfied { + expectation.fulfill() + } + } + } + waitForExpectations(timeout: 5, handler: nil) + } + +} diff --git a/Tests/NetworkReachabilityTests/NetworkMonitorTests.swift b/Tests/NetworkReachabilityTests/NetworkMonitorTests.swift index fe0c2106..460ffd62 100644 --- a/Tests/NetworkReachabilityTests/NetworkMonitorTests.swift +++ b/Tests/NetworkReachabilityTests/NetworkMonitorTests.swift @@ -23,8 +23,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#if canImport(Combine) - import Combine +#if canImport(Network) import Network #endif @@ -34,30 +33,6 @@ import XCTest @available(macOS 10.14, iOS 12.0, watchOS 5.0, tvOS 12.0, *) final class NetworkMonitorTests: XCTestCase { - #if canImport(Combine) - var cancellable: AnyCancellable? - #endif - - @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) - func test_get_concurrency() async { - let path = await NetworkMonitor.networkPath - XCTAssertEqual(path.status, .satisfied) - } - - @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) - func test_observe_concurrency() { - let expectation = expectation(description: "pass") - - Task { - for await status in NetworkMonitor.networkPathUpdates.map(\.status) { - if status == .satisfied { - expectation.fulfill() - } - } - } - waitForExpectations(timeout: 5, handler: nil) - } - func test_observe_closure() { let expectation = expectation(description: "pass") withExtendedLifetime(NetworkMonitor(updateHandler: { _, path in @@ -69,20 +44,6 @@ final class NetworkMonitorTests: XCTestCase { } } - @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) - func test_observe_combine() { - let expectation = expectation(description: "pass") - cancellable = NetworkMonitor - .networkPathPublisher - .map { $0.status == .satisfied } - .removeDuplicates() - .sink { isReachable in - XCTAssertTrue(isReachable) - expectation.fulfill() - } - waitForExpectations(timeout: 5) - } - func test_observe_delegate() { let expectation = expectation(description: "pass") @@ -146,10 +107,4 @@ final class NetworkMonitorTests: XCTestCase { } } } - - deinit { - if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) { - cancellable?.cancel() - } - } } diff --git a/Tests/NetworkReachabilityTests/ReachabilityMonitorCombineTests.swift b/Tests/NetworkReachabilityTests/ReachabilityMonitorCombineTests.swift new file mode 100644 index 00000000..19d3c268 --- /dev/null +++ b/Tests/NetworkReachabilityTests/ReachabilityMonitorCombineTests.swift @@ -0,0 +1,58 @@ +// NetworkReachabiliy +// ReachabilityMonitorCombineTests.swift +// +// MIT License +// +// Copyright (c) 2021 Varun Santhanam +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#if canImport(Combine) + + import Combine + import Foundation + @testable import NetworkReachability + import XCTest + + @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) + final class ReachabilityMonitorConcurrencyTests: XCTestCase { + + var cancellable: AnyCancellable? + + func test_observe_combine() { + let expectation = expectation(description: "pass") + cancellable = ReachabilityMonitor + .reachabilityPublisher + .map(\.status.isReachable) + .replaceError(with: false) + .removeDuplicates() + .sink { isReachable in + XCTAssertTrue(isReachable) + expectation.fulfill() + } + waitForExpectations(timeout: 5) + } + + deinit { + cancellable?.cancel() + } + + } + +#endif diff --git a/Tests/NetworkReachabilityTests/ReachabilityMonitorConcurrencyTests.swift b/Tests/NetworkReachabilityTests/ReachabilityMonitorConcurrencyTests.swift new file mode 100644 index 00000000..292eae8a --- /dev/null +++ b/Tests/NetworkReachabilityTests/ReachabilityMonitorConcurrencyTests.swift @@ -0,0 +1,52 @@ +// NetworkReachabiliy +// ReachabilityMonitorConcurrencyTests.swift +// +// MIT License +// +// Copyright (c) 2021 Varun Santhanam +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +import Foundation +@testable import NetworkReachability +import XCTest + +@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) +final class ReachabiltyMonitorConcurrencyTests: XCTestCase { + + func test_observe_concurrency() { + let expectation = expectation(description: "pass") + + Task { + do { + for try await isReachable in ReachabilityMonitor.reachabilityUpdates.map(\.status.isReachable) { + if isReachable { + expectation.fulfill() + } else { + XCTFail() + } + } + } catch { + XCTFail() + } + } + waitForExpectations(timeout: 5, handler: nil) + } + +} diff --git a/Tests/NetworkReachabilityTests/ReachabilityMonitorTests.swift b/Tests/NetworkReachabilityTests/ReachabilityMonitorTests.swift index a5b5a5e0..5fe29207 100644 --- a/Tests/NetworkReachabilityTests/ReachabilityMonitorTests.swift +++ b/Tests/NetworkReachabilityTests/ReachabilityMonitorTests.swift @@ -46,26 +46,6 @@ final class ReachabilityMonitorTests: XCTestCase { } } - @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) - func test_observe_concurrency() { - let expectation = expectation(description: "pass") - - Task { - do { - for try await isReachable in ReachabilityMonitor.reachabilityUpdates.map(\.status.isReachable) { - if isReachable { - expectation.fulfill() - } else { - XCTFail() - } - } - } catch { - XCTFail() - } - } - waitForExpectations(timeout: 5, handler: nil) - } - func test_observe_closure() { let expectation = expectation(description: "pass") do { @@ -87,21 +67,6 @@ final class ReachabilityMonitorTests: XCTestCase { } } - @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) - func test_observe_combine() { - let expectation = expectation(description: "pass") - cancellable = ReachabilityMonitor - .reachabilityPublisher - .map(\.status.isReachable) - .replaceError(with: false) - .removeDuplicates() - .sink { isReachable in - XCTAssertTrue(isReachable) - expectation.fulfill() - } - waitForExpectations(timeout: 5) - } - func test_observe_delegate() { let expectation = expectation(description: "pass")