Skip to content

Commit 4e73b0e

Browse files
committed
update tests according to recommendations from @lightsprint09
1 parent 93b02b5 commit 4e73b0e

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

SourcingTests/CDTrain+CoreDataProperties.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extension CDTrain {
1818
return NSFetchRequest<CDTrain>(entityName: "CDTrain")
1919
}
2020

21-
2221
@NSManaged var id: String
2322
@NSManaged var name: String
2423
}

SourcingTests/CollectionViewDataSource_SingleCellTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import XCTest
3030
import UIKit
3131
@testable import Sourcing
3232

33-
// swiftlint:disable force_cast force_unwrapping
33+
// swiftlint:disable force_cast force_unwrapping xctfail_message
3434
class CollectionViewDataSourceSingleCellTest: XCTestCase {
3535

3636
let cellIdentifier = "cellIdentifier"

SourcingTests/FetchedResultsDataProviderTests.swift

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,25 @@ class FetchedResultsDataProviderTests: XCTestCase {
216216
XCTAssert(didUpdateDataSource)
217217
}
218218

219-
func testProcessUpdatesNumberForMoveChange() {
219+
func testProcessUpdatesForMoveChange() {
220220
//Given
221-
var updatesNumber = 0
221+
var updateIndexPath = IndexPath()
222+
var moveIndexPaths = [IndexPath]()
222223

223224
dataProvider = try! FetchedResultsDataProvider(fetchedResultsController: fetchedResultsController, dataProviderDidUpdate: { _ in })
224225
dataProvider.whenDataProviderChanged = { updates in
225-
if !updates!.isEmpty {
226-
updatesNumber += 1
226+
if updates!.isEmpty {
227+
return
228+
}
229+
230+
for update in updates! {
231+
switch update {
232+
case .update(let indexPath, _):
233+
updateIndexPath = indexPath
234+
case .move(let indexPath, let newIndexPath):
235+
moveIndexPaths = [indexPath, newIndexPath]
236+
default: break
237+
}
227238
}
228239
}
229240

@@ -236,17 +247,26 @@ class FetchedResultsDataProviderTests: XCTestCase {
236247
dataProvider.controllerDidChangeContent(fetchedResultsController as! NSFetchedResultsController<NSFetchRequestResult>)
237248

238249
//Then
239-
XCTAssertEqual(updatesNumber, 2)
250+
XCTAssertEqual(updateIndexPath, newIndexPath)
251+
XCTAssertEqual(moveIndexPaths, [oldIndexPath, newIndexPath])
240252
}
241253

242-
func testProcessUpdatesNumberForOtherThenMoveChange() {
254+
func testProcessUpdatesForUpdateChange() {
243255
//Given
244-
var updatesNumber = 0
256+
var updateIndexPath = IndexPath()
245257

246258
dataProvider = try! FetchedResultsDataProvider(fetchedResultsController: fetchedResultsController, dataProviderDidUpdate: { _ in })
247259
dataProvider.whenDataProviderChanged = { updates in
248-
if !updates!.isEmpty {
249-
updatesNumber += 1
260+
if updates!.isEmpty {
261+
return
262+
}
263+
264+
for update in updates! {
265+
switch update {
266+
case .update(let indexPath, _):
267+
updateIndexPath = indexPath
268+
default: break
269+
}
250270
}
251271
}
252272

@@ -258,7 +278,7 @@ class FetchedResultsDataProviderTests: XCTestCase {
258278
dataProvider.controllerDidChangeContent(fetchedResultsController as! NSFetchedResultsController<NSFetchRequestResult>)
259279

260280
//Then
261-
XCTAssertEqual(updatesNumber, 1)
281+
XCTAssertEqual(updateIndexPath, indexPath)
262282
}
263283

264284
func testWillChangeContent() {

0 commit comments

Comments
 (0)