testing builder code example
Example: testing builder
// The builder
class LoggerBuilder {
var sink: LogSink = MockLogSink()
var config: LogConfig = TestLogConfig()
func build() -> Logger {
return Logger(sink: sink, config: config)
}
}
// in a test class
func testLoggerWritesToSuppliedSink() {
let loggerBuilder = LoggerBuilder()
let logger = loggerBuilder.build()
logger.log("hello world")
XCTAssertTrue(loggerBuilder.sink.contains("hello world")
}