Skip to content

Commit 1defdf4

Browse files
committed
Streamline syntax to Swift latest + remove force unwrapping
1 parent 9d53da7 commit 1defdf4

1 file changed

Lines changed: 27 additions & 15 deletions

File tree

GLTableCollectionViewTests/GLTableCollectionViewTests.swift

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class GLTableCollectionViewTests: XCTestCase {
4848

4949
// MARK: <GLTableCollectionViewController>
5050

51-
private func testInstanceVariables() {
51+
func testInstanceVariables() {
5252
XCTAssertGreaterThan(tableCollectionView.numberOfSections, 0,
5353
"numberOfSections was: \(tableCollectionView.numberOfSections)\nUITableView must have at least one section")
5454

@@ -68,7 +68,7 @@ final class GLTableCollectionViewTests: XCTestCase {
6868
"tableCellID was: \(GLTableCollectionViewController.tableCellID)\nUITableViewCell's cellIdentifier must contain only one # in it")
6969
}
7070

71-
private func testRandomColorsGeneration() {
71+
func testRandomColorsGeneration() {
7272
let colorsDictionary: [Int: [UIColor]] = tableCollectionView.colorsDict
7373

7474
XCTAssertNotNil(colorsDictionary, "Colors dictionary is nil")
@@ -82,43 +82,55 @@ final class GLTableCollectionViewTests: XCTestCase {
8282
}
8383
}
8484

85-
private func testTableViewDataSource() {
85+
func testTableViewDataSource() {
8686
XCTAssertNotNil(tableCollectionView.tableView.dataSource, "UITableView dataSource is nil")
8787
}
8888

89-
private func testTableViewDelegate() {
89+
func testTableViewDelegate() {
9090
XCTAssertNotNil(tableCollectionView.tableView.delegate, "UITableView delegate is nil")
9191
}
9292

93-
private func testUITableViewCellClasses() {
93+
func testUITableViewCellClasses() {
9494
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")
9595

9696
for tableViewCell in visibleCells {
9797
XCTAssertTrue(tableViewCell is GLCollectionTableViewCell, "UITableViewCells must be GLCollectionTableViewCell")
9898
}
9999
}
100100

101-
private func testTableViewCellIdentifiers() {
101+
func testTableViewCellIdentifiers() {
102102
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")
103103

104-
for tableViewCell: GLCollectionTableViewCell in visibleCells as! [GLCollectionTableViewCell] {
105-
XCTAssertTrue(Int(tableViewCell.reuseIdentifier!.components(separatedBy: "#").last!)! >= 0,
106-
"GLCollectionTableViewCell cellIdentifier was: \(String(describing: tableViewCell.reuseIdentifier))\nGLCollectionTableViewCell's cellIdentifier must end with a positive integer")
104+
visibleCells.forEach { cell in
105+
guard let tableViewCell = cell as? GLCollectionTableViewCell else {
106+
fatalError("UITableViewCells must be GLCollectionTableViewCell")
107+
}
108+
109+
guard let reuseID: String = tableViewCell.reuseIdentifier else {
110+
fatalError("UITableViewCells must have a reuse identifier")
111+
}
112+
113+
XCTAssertTrue(Int(reuseID.components(separatedBy: "#").last!)! >= 0,
114+
"GLCollectionTableViewCell cellIdentifier was: \(String(describing: reuseID))\nGLCollectionTableViewCell's cellIdentifier must end with a positive integer")
107115
}
108116
}
109117

110118
// MARK: <GLCollectionTableViewCell>
111119

112-
private func testCollectionViewsDelegateAndDataSource() {
120+
func testCollectionViewsDelegateAndDataSource() {
113121
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")
114122

115-
for collectionTableCell: GLCollectionTableViewCell in visibleCells as! [GLCollectionTableViewCell] {
123+
visibleCells.forEach { cell in
124+
guard let collectionTableCell = cell as? GLCollectionTableViewCell else {
125+
fatalError("UITableViewCells must be GLCollectionTableViewCell")
126+
}
127+
116128
XCTAssertNotNil(collectionTableCell.collectionView.dataSource, "GLCollectionTableViewCell dataSource is nil")
117129
XCTAssertNotNil(collectionTableCell.collectionView.delegate, "GLCollectionTableViewCell delegate is nil")
118130
}
119131
}
120132

121-
private func testCollectionNativePaginationFlag() {
133+
func testCollectionNativePaginationFlag() {
122134
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")
123135

124136
for collectionTableCell: GLCollectionTableViewCell in visibleCells as! [GLCollectionTableViewCell] {
@@ -129,7 +141,7 @@ final class GLTableCollectionViewTests: XCTestCase {
129141
}
130142
}
131143

132-
private func testCollectionViewPaginationConsistency() {
144+
func testCollectionViewPaginationConsistency() {
133145
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")
134146

135147
for collectionTableCell: GLCollectionTableViewCell in visibleCells as! [GLCollectionTableViewCell] {
@@ -143,7 +155,7 @@ final class GLTableCollectionViewTests: XCTestCase {
143155
}
144156
}
145157

146-
private func testCollectionViewCellHeights() {
158+
func testCollectionViewCellHeights() {
147159
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")
148160

149161
let tableViewCellHeight: CGFloat = tableCollectionView.tableView.rowHeight
@@ -154,7 +166,7 @@ final class GLTableCollectionViewTests: XCTestCase {
154166

155167
// MARK: <Other>
156168

157-
private func testOpaqueFlag() {
169+
func testOpaqueFlag() {
158170
XCTAssertTrue(tableCollectionView.tableView.isOpaque, "The UITableView should be opaque for increased performances")
159171

160172
XCTAssertGreaterThan(visibleCells.count, 0, "UITableView visible cells must be greater than 0")

0 commit comments

Comments
 (0)