Skip to content

Instantly share code, notes, and snippets.

@andru255
Created July 25, 2018 16:27
Show Gist options
  • Save andru255/ff3f447d8cce7b8dcecc95e6b677d505 to your computer and use it in GitHub Desktop.
Save andru255/ff3f447d8cce7b8dcecc95e6b677d505 to your computer and use it in GitHub Desktop.
class MockBookFinder: BookFinderProtocol {
private var adapter: NetworkAdapter
private var totalSearch: Int
public init(adapter: NetworkAdapter){
self.adapter = adapter
self.totalSearch = 0
}
public func searchBy(author: String, success:((_ data:[BookModel?]) -> Void )? = nil, fail: FailCallback = nil) {
let dataFake:[BookModel] = [
BookModel(id: "a", title: "five cities", author: [ "jhon doe" ])
]
self.adapter.requestServiceSuccess(
url: "fake",
success: { _ in
if let successCallback = success {
successCallback(dataFake)
}
}
)
totalSearch += 1
}
public func searchByFail(author: String, success:((_ data:[BookModel?]) -> Void )? = nil, fail:FailCallback = nil){
self.adapter.requestServiceFail(
url: "fake",
fail: fail
)
totalSearch += 1
}
public func getTotalSearch() -> Int {
return self.totalSearch
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment