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
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link href="./Risk warning_files/css" rel="stylesheet" type="text/css"> | |
<title>Risk warning</title> | |
<style> | |
body { |
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
let repository = builder.makeRepository( | |
with: [.sample(id: "1"), .sample(id: "2")] | |
) |
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
// preparation | |
let builder = Builder() | |
let repository = builder.makeRepository() | |
// actual test | |
builder.priceAlertStorageService.cachedPriceAlertsMockFunc | |
.returns([.sample(id: "1"), .sample(id: "2")]) | |
let result = repository.cachedPriceAlerts(symbol: "AAPL") | |
expect(result.map { $0.id }) == ["1", "2"] |
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
private class Builder { | |
var priceAlertApiService = PriceAlertApiServiceMock() | |
var priceAlertStorageService = PriceAlertStorageServiceMock() | |
func makeRepository() -> PriceAlertRepository { | |
let repository = PriceAlertRepository( | |
network: priceAlertApiService, | |
storage: priceAlertStorageService | |
) | |
return repository |
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
// preparation | |
var priceAlertApiService = PriceAlertApiServiceMock() | |
var priceAlertStorageService = PriceAlertStorageServiceMock() | |
let repository = PriceAlertRepository( | |
network: priceAlertApiService, | |
storage: priceAlertStorageService | |
) | |
// actual test |
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
someMockFunc.succeeds(.sample()) // if ouput is Result<T> | |
someMockFunc.fails(error) // if ouput is Result<T> | |
someMockFunc.returnsNil() // if ouput is T? | |
someMockFunc.returns() // if ouput is Void | |
expect(someMockFunc).to(beCalled()) |
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
var priceAlertRepository = PriceAlertRepositoryMock() | |
priceAlertRepository.cachedPriceAlertsMockFunc.returns([.sample(id: "53")]) |
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
final class PriceAlertRepositoryMock: PriceAlertRepositoryProtocol { | |
var cachedPriceAlertsMockFunc = MockFunc<String?, [PriceAlert]>() | |
func cachedPriceAlerts(symbol: String?) -> [PriceAlert] { | |
return cachedPriceAlertsMockFunc.callAndReturn(symbol) | |
} | |
} |
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
public struct MockFunc<Input, Output> { | |
public var parameters: [Input] = [] | |
public var result: (Input) -> Output = { _ in fatalError() } | |
public mutating func callAndReturn(_ input: Input) -> Output { | |
parameters.append(input) | |
return result(input) | |
} | |
public mutating func returns(_ value: Output) { |
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
class AnimatorSpy: Animator { | |
var invokedAnimate = false | |
var invokedAnimateCount = 0 | |
var invokedAnimateParameters: (duration: TimeInterval, Void)? | |
var invokedAnimateParametersList = [(duration: TimeInterval, Void)]() | |
var shouldInvokeAnimateAnimations = false | |
var stubbedAnimateCompletionResult: (Bool, Void)? | |
var stubbedAnimateResult: Bool! = false |
NewerOlder