Skip to content

Commit

Permalink
Improved InteractorExecutorTests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Rieger committed May 15, 2019
1 parent 20e30fa commit b7f5415
Showing 1 changed file with 44 additions and 21 deletions.
65 changes: 44 additions & 21 deletions Tests/ACInteractorTests/InteractorExecutorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,6 @@ class InteractorExecutorTests: XCTestCase {
}
}

// MARK: - registerInteractor

func testRegisterInteractor_succeeds(){
// Act
executor.registerInteractor(firstInteractor, request: firstRequest)
}

func testRegisterInteractor_callsErrorClosureOnRequest_whenInteractorDoesNotMatchRequest() {
// Arrange
executor.registerInteractor(secondInteractor, request: firstRequest)

// Act
executor.execute(firstRequest)

// Assert
let expected = "ACInteractor.ACInteractorExecutor: Request does not match execute function of registered Interactor!"
XCTAssertEqual(errorMessageFromFirstRequest, expected)
}

// MARK: - execute

func testExecute_callsExecuteOnInteractor_thatIsRegisteredForRequest() {
Expand Down Expand Up @@ -70,6 +51,18 @@ class InteractorExecutorTests: XCTestCase {
XCTAssertEqual(errorMessageFromFirstRequest, expected)
}

func testExecute_callsErrorOnRequest_whenRegisteredInteractorDoesNotMatchRequest() {
// Arrange
executor.registerInteractor(secondInteractor, request: FirstInteractor.Request.self)

// Act
executor.execute(firstRequest)

// Assert
let expected = "ACInteractor.ACInteractorExecutor: Request does not match execute function of registered Interactor!"
XCTAssertEqual(errorMessageFromFirstRequest, expected)
}

// MARK: - execute (deprecated)

@available(*, deprecated)
Expand Down Expand Up @@ -103,12 +96,25 @@ class InteractorExecutorTests: XCTestCase {
XCTAssertEqual(errorMessageFromFirstRequest, expected)
}

@available(*, deprecated)
func testExecute_callsErrorOnRequest_whenRegisteredInteractorDoesNotMatchRequestInstance() {
// Arrange
executor.registerInteractor(secondInteractor, request: firstRequest)

// Act
executor.execute(firstRequest)

// Assert
let expected = "ACInteractor.ACInteractorExecutor: Request does not match execute function of registered Interactor!"
XCTAssertEqual(errorMessageFromFirstRequest, expected)
}

// MARK: - getInteractor

func testGetInteractor_returnsInteractor_registeredForRequest() {
// Arrange
executor.registerInteractor(firstInteractor, request: firstRequest)
executor.registerInteractor(secondInteractor, request: secondRequest)
executor.registerInteractor(firstInteractor, request: FirstInteractor.Request.self)
executor.registerInteractor(secondInteractor, request: SecondInteractor.Request.self)

// Act
let firstResult = executor.getInteractor(request: firstRequest)
Expand All @@ -127,4 +133,21 @@ class InteractorExecutorTests: XCTestCase {
XCTAssertNil(result)
}

// MARK: - getInteractor (deprecated)

@available(*, deprecated)
func testGetInteractor_returnsInteractor_registeredForRequestInstance() {
// Arrange
executor.registerInteractor(firstInteractor, request: firstRequest)
executor.registerInteractor(secondInteractor, request: secondRequest)

// Act
let firstResult = executor.getInteractor(request: firstRequest)
let secondResult = executor.getInteractor(request: secondRequest)

// Assert
XCTAssert(firstResult === firstInteractor)
XCTAssert(secondResult === secondInteractor)
}

}

0 comments on commit b7f5415

Please sign in to comment.