Stub test double: a predefined collaborator

A test stub is a collaborator that has canned returns so that we can control the indirect input of the SUT.

Considering the example of the fake, we create a Stub that already has two tasks:

class StubTaskStoreWithTwoTasks: TaskStore {
private(set) var allTasks = [Task(), Task()]

func add(task: Task) {
allTasks.append(task)
}
}

The test is as follows:

func testAddATaskToPreloadedTasks() {
let taskManager = TaskManager(store: StubTaskStoreWithTwoTasks())
taskManager.add(task: Task())
XCTAssertEqual(taskManager.count, 3)
}