Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MacTHEgenius committed Jul 4, 2017
1 parent 8b31d79 commit b07f430
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions Swap/Controller/ParticipantController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum ParticipantError: Error, Equatable {
func ==(lhs: ParticipantError, rhs: ParticipantError) -> Bool {
switch (lhs, rhs) {
case (.notValid(let leftErrors), .notValid(let rightErrors)): return leftErrors == rightErrors
case (.notEnoughPicked(let leftCount), .notEnoughPicked(let rightCount)): return leftCount == rightCount
default: return true
}
}
2 changes: 1 addition & 1 deletion Swap/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>598</string>
<string>604</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
28 changes: 17 additions & 11 deletions SwapTests/Controller/ParticipantControllerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,38 @@ class ParticipantControllerTest: XCTestCase {
self.controller = ParticipantController(self.participant, parent: self.parent)
}

func testToggle_withCurrentParticipant() {
let expected = [String]()

self.controller.toggle(self.participant)

XCTAssertEqual(self.controller.cantPick, expected)
}

func testToggle_withParticipantNotPicked() {
let expected = [Constant.other.id]

self.controller.toggle(Constant.other)
XCTAssertNoThrow(try self.controller.toggle(Constant.other), "toggle() did throw, but was not supposed to.")

XCTAssertEqual(self.controller.cantPick, expected)
}

func testPick_withAlreadyParticipantPicked() {
func testToggle_withAlreadyParticipantPicked() {
let expected = [String]()
self.participant.cantPick = [Constant.other.id]
self.controller = ParticipantController(self.participant, parent: self.parent)

self.controller.toggle(Constant.other)
XCTAssertNoThrow(try self.controller.toggle(Constant.other), "toggle() did throw, but was not supposed to.")

XCTAssertEqual(self.controller.cantPick, expected)
}

func testToggle_shouldThrowCantToggleYourself_withCurrentParticipant() {
XCTAssertThrowsError(try self.controller.toggle(self.participant), "toggle() did throw, but was not supposed to.") { (error) in
XCTAssertEqual(error as! ParticipantError, ParticipantError.cantToggleYourself)
}
}

func testToggle_shouldThrowNotEnoughPicked() {
self.parent.setReturnedCount(integer: 1)

XCTAssertThrowsError(try self.controller.toggle(Constant.other), "toggle() did throw, but was not supposed to.") { (error) in
XCTAssertEqual(error as! ParticipantError, ParticipantError.notEnoughPicked(count: 0))
}
}

func testSave_ShouldNotThrow_WithAllValid() {
_ = self.participant.setUpValidateAreInvalid()

Expand Down
13 changes: 13 additions & 0 deletions SwapTests/Mocks/ParticipantsControllerMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ import Foundation

class ParticipantsControllerMock: ParticipantsController {

// Count
private var mockCount: Int?
func setReturnedCount(integer: Int) {
self.mockCount = integer
}

override var count: Int {
get {
if let mock = self.mockCount {
return mock
}
return super.count
}
}

}

0 comments on commit b07f430

Please sign in to comment.