-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Kuniwak/test-doubles
Add spy/stubs
- Loading branch information
Showing
7 changed files
with
192 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Combine | ||
import BLEModel | ||
|
||
|
||
public class SpyPeripheralsDiscoveryModel: PeripheralsDiscoveryModelProtocol { | ||
public var state: PeripheralsDiscoveryModelState { inherited.state } | ||
public var stateDidUpdate: AnyPublisher<PeripheralsDiscoveryModelState, Never> { | ||
inherited.stateDidUpdate | ||
} | ||
|
||
|
||
public var inherited: any PeripheralsDiscoveryModelProtocol | ||
public private(set) var callArgs = [CallArg]() | ||
|
||
|
||
public init(inheriting inherited: any PeripheralsDiscoveryModelProtocol = StubPeripheralsDiscoveryModel()) { | ||
self.inherited = inherited | ||
} | ||
|
||
|
||
public func scan() { | ||
callArgs.append(.scan) | ||
inherited.scan() | ||
} | ||
|
||
|
||
public func stopScan() { | ||
callArgs.append(.stopScan) | ||
inherited.stopScan() | ||
} | ||
|
||
|
||
public enum CallArg: Equatable { | ||
case scan | ||
case stopScan | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Sources/BLEModelStub/SpyPeripheralsNewDiscoveryModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Combine | ||
import BLEModel | ||
|
||
|
||
public class SpyPeripheralsNewDiscoveryModel: PeripheralsNewDiscoveryModelProtocol { | ||
public var didDiscover: AnyPublisher<PeripheralDiscoveryEntry, Never> { inherited.didDiscover } | ||
|
||
public var inherited: any PeripheralsNewDiscoveryModelProtocol | ||
public private(set) var callArgs = [CallArg]() | ||
|
||
|
||
public init(inheriting inherited: any PeripheralsNewDiscoveryModelProtocol = StubPeripheralsNewDiscoveryModel()) { | ||
self.inherited = inherited | ||
} | ||
|
||
|
||
public func scan() { | ||
callArgs.append(.scan) | ||
inherited.scan() | ||
} | ||
|
||
|
||
public func stopScan() { | ||
callArgs.append(.stopScan) | ||
inherited.stopScan() | ||
} | ||
|
||
|
||
public enum CallArg: Equatable { | ||
case scan | ||
case stopScan | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Combine | ||
import BLEModel | ||
|
||
|
||
public class StubPeripheralsDiscoveryModel: PeripheralsDiscoveryModelProtocol { | ||
public var state: PeripheralsDiscoveryModelState { | ||
stateDidUpdateSubject.value | ||
} | ||
public let stateDidUpdate: AnyPublisher<PeripheralsDiscoveryModelState, Never> | ||
public let stateDidUpdateSubject: CurrentValueSubject<PeripheralsDiscoveryModelState, Never> | ||
|
||
|
||
public init(state: PeripheralsDiscoveryModelState = .notReady) { | ||
let stateDidUpdateSubject = CurrentValueSubject<PeripheralsDiscoveryModelState, Never>(state) | ||
self.stateDidUpdateSubject = stateDidUpdateSubject | ||
self.stateDidUpdate = stateDidUpdateSubject.eraseToAnyPublisher() | ||
} | ||
|
||
|
||
public func scan() { | ||
} | ||
|
||
|
||
public func stopScan() { | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Sources/BLEModelStub/StubPeripheralsNewDiscoveryModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Combine | ||
import BLEModel | ||
|
||
|
||
public class StubPeripheralsNewDiscoveryModel: PeripheralsNewDiscoveryModelProtocol { | ||
public let didDiscover: AnyPublisher<PeripheralDiscoveryEntry, Never> | ||
public let didDiscoverSubject: PassthroughSubject<PeripheralDiscoveryEntry, Never> | ||
|
||
|
||
public init() { | ||
let didDiscoverSubject = PassthroughSubject<PeripheralDiscoveryEntry, Never>() | ||
self.didDiscoverSubject = didDiscoverSubject | ||
self.didDiscover = didDiscoverSubject.eraseToAnyPublisher() | ||
} | ||
|
||
|
||
public func scan() { | ||
} | ||
|
||
|
||
public func stopScan() { | ||
} | ||
} |