Skip to content

Commit c0c09d6

Browse files
author
Florian Rieger
committed
Improved LazyInteractorTests.
1 parent 943cc97 commit c0c09d6

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

Tests/ACInteractorTests/InteractorErrorTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class InteractorErrorTests: XCTestCase {
1717

1818
// MARK: - Init
1919

20-
func testInit_withMessage_setsMessageAsLocalizedDescription() {
20+
func testInit_setsMessageAsLocalizedDescription() {
2121
// Act
2222
let error = InteractorError(message: "testMessage")
2323

@@ -26,15 +26,15 @@ class InteractorErrorTests: XCTestCase {
2626
XCTAssertEqual(error.userInfo[NSLocalizedDescriptionKey] as? String, "testMessage")
2727
}
2828

29-
func testInit_withCode_setsCode() {
29+
func testInit_setsCode() {
3030
// Act
3131
let error = InteractorError(message: "", code: 42)
3232

3333
// Assert
3434
XCTAssertEqual(error.code, 42)
3535
}
3636

37-
func testInit_withDict_setsDict() {
37+
func testInit_setsDict() {
3838
// Act
3939
let error = InteractorError(message: "", code: 0, dict: testErrorDict)
4040

Tests/ACInteractorTests/LazyInteractorTests.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ class LazyInteractorTests: XCTestCase {
1212
lazyInteractor = LazyInteractor(factory: testFactory)
1313
}
1414

15-
// MARK: init()
15+
// MARK: - Init
1616

1717
func testInit_doesNotInitializeLazyInstance()
1818
{
1919
// Assert
2020
XCTAssertNil(lazyInteractor.lazyInstance)
2121
}
2222

23-
// MARK: getInteractor()
23+
// MARK: - getInteractor
2424

2525
func testGetInteractor_returnsInstanceBuiltWithFactory()
2626
{
@@ -32,7 +32,7 @@ class LazyInteractorTests: XCTestCase {
3232
}
3333

3434

35-
func testGetInteractor_calledTwice_doesNotCreateNewInstance()
35+
func testGetInteractor_alwaysReturnsSameInstance()
3636
{
3737
// Act
3838
let firstInteractor = lazyInteractor.getInteractor()
@@ -42,7 +42,7 @@ class LazyInteractorTests: XCTestCase {
4242
XCTAssert(firstInteractor === secondInteractor)
4343
}
4444

45-
// MARK: execute()
45+
// MARK: - execute
4646

4747
func testExceute_callsExecuteOfInteractor()
4848
{
@@ -53,9 +53,25 @@ class LazyInteractorTests: XCTestCase {
5353
lazyInteractor.execute(request)
5454

5555
// Assert
56-
let interactor = lazyInteractor.getInteractor()
57-
XCTAssertEqual(interactor.executedRequests.count, 1)
58-
XCTAssert(interactor.executedRequests.first === request)
56+
let interactor = lazyInteractor.lazyInstance
57+
XCTAssertEqual(interactor?.executedRequests.count, 1)
58+
XCTAssert(interactor?.executedRequests.first === request)
59+
}
60+
61+
func testExecute_alwaysUsesSameInteractorInstance() {
62+
// Arrange
63+
let firstRequest = TestInteractor.Request()
64+
let secondRequest = TestInteractor.Request()
65+
66+
// Act
67+
lazyInteractor.execute(firstRequest)
68+
lazyInteractor.execute(secondRequest)
69+
70+
// Assert
71+
let interactor = lazyInteractor.lazyInstance
72+
XCTAssertEqual(interactor?.executedRequests.count, 2)
73+
XCTAssert(interactor?.executedRequests.first === firstRequest)
74+
XCTAssert(interactor?.executedRequests.last === secondRequest)
5975
}
6076

6177
}

0 commit comments

Comments
 (0)