, , CodeCopStub
, CodeCop
:
protocol CodeCopStub: CodeCop {
static var allowed: Bool { get }
}
CodeCopStub
shouldAllowExecution()
, CodeCop
, allowed
. CodeCop
, CodeCopStub
.
extension CodeCopStub {
func shouldAllowExecution() -> Bool {
return Self.allowed
}
}
, , - Worker
CodeCopStub
:
extension Worker: CodeCopStub {
static var allowed: Bool = false
}
:
func testAllowed() {
let worker = Worker()
Worker.allowed = true
let actualResult = worker.doSomeStuff()
let expectedResult = "Cop allowed it"
XCTAssertEqual(expectedResult, actualResult)
}
func testNotAllowed() {
let worker = Worker()
Worker.allowed = false
let actualResult = worker.doSomeStuff()
let expectedResult = "Cop said no"
XCTAssertEqual(expectedResult, actualResult)
}
, , . , , .