3030import XCTest
3131@testable import GLTableCollectionView
3232
33- class GLTableCollectionViewTests : XCTestCase {
34- var tableCollectionView : GLTableCollectionViewController !
35- var visibleCells : [ UITableViewCell ] !
33+ final class GLTableCollectionViewTests : XCTestCase {
34+ private var tableCollectionView : GLTableCollectionViewController !
35+ private var visibleCells : [ UITableViewCell ] !
3636
3737 override func setUp( ) {
3838 super. setUp ( )
@@ -93,17 +93,29 @@ class GLTableCollectionViewTests: XCTestCase {
9393 func testUITableViewCellClasses( ) {
9494 XCTAssertGreaterThan ( visibleCells. count, 0 , " UITableView visible cells must be greater than 0 " )
9595
96- for tableViewCell in visibleCells {
97- XCTAssertTrue ( tableViewCell is GLCollectionTableViewCell , " UITableViewCells must be GLCollectionTableViewCell " )
96+ visibleCells. forEach { cell in
97+ if cell is GLCollectionTableViewCell {
98+ return
99+ } else {
100+ XCTAssertTrue ( cell is GLCollectionTableViewCell , " UITableViewCells must be GLCollectionTableViewCell " )
101+ }
98102 }
99103 }
100104
101105 func testTableViewCellIdentifiers( ) {
102106 XCTAssertGreaterThan ( visibleCells. count, 0 , " UITableView visible cells must be greater than 0 " )
103107
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) ) \n GLCollectionTableViewCell's cellIdentifier must end with a positive integer " )
108+ visibleCells. forEach { cell in
109+ guard let tableViewCell: GLCollectionTableViewCell = cell as? GLCollectionTableViewCell else {
110+ fatalError ( " UITableViewCells must be GLCollectionTableViewCell " )
111+ }
112+
113+ guard let reuseID: String = tableViewCell. reuseIdentifier else {
114+ fatalError ( " UITableViewCells must have a reuse identifier " )
115+ }
116+
117+ XCTAssertTrue ( Int ( reuseID. components ( separatedBy: " # " ) . last!) ! >= 0 ,
118+ " GLCollectionTableViewCell cellIdentifier was: \( String ( describing: reuseID) ) \n GLCollectionTableViewCell's cellIdentifier must end with a positive integer " )
107119 }
108120 }
109121
@@ -112,7 +124,11 @@ class GLTableCollectionViewTests: XCTestCase {
112124 func testCollectionViewsDelegateAndDataSource( ) {
113125 XCTAssertGreaterThan ( visibleCells. count, 0 , " UITableView visible cells must be greater than 0 " )
114126
115- for collectionTableCell : GLCollectionTableViewCell in visibleCells as! [ GLCollectionTableViewCell ] {
127+ visibleCells. forEach { cell in
128+ guard let collectionTableCell: GLCollectionTableViewCell = cell as? GLCollectionTableViewCell else {
129+ fatalError ( " UITableViewCells must be GLCollectionTableViewCell " )
130+ }
131+
116132 XCTAssertNotNil ( collectionTableCell. collectionView. dataSource, " GLCollectionTableViewCell dataSource is nil " )
117133 XCTAssertNotNil ( collectionTableCell. collectionView. delegate, " GLCollectionTableViewCell delegate is nil " )
118134 }
@@ -121,7 +137,11 @@ class GLTableCollectionViewTests: XCTestCase {
121137 func testCollectionNativePaginationFlag( ) {
122138 XCTAssertGreaterThan ( visibleCells. count, 0 , " UITableView visible cells must be greater than 0 " )
123139
124- for collectionTableCell : GLCollectionTableViewCell in visibleCells as! [ GLCollectionTableViewCell ] {
140+ visibleCells. forEach { cell in
141+ guard let collectionTableCell: GLCollectionTableViewCell = cell as? GLCollectionTableViewCell else {
142+ fatalError ( " UITableViewCells must be GLCollectionTableViewCell " )
143+ }
144+
125145 if collectionTableCell. collectionViewPaginatedScroll == true {
126146 XCTAssertFalse ( collectionTableCell. collectionView. isPagingEnabled,
127147 " Custom scrolling pagination and native UICollectionView pagination can't be enabled at the same time " )
@@ -132,7 +152,11 @@ class GLTableCollectionViewTests: XCTestCase {
132152 func testCollectionViewPaginationConsistency( ) {
133153 XCTAssertGreaterThan ( visibleCells. count, 0 , " UITableView visible cells must be greater than 0 " )
134154
135- for collectionTableCell : GLCollectionTableViewCell in visibleCells as! [ GLCollectionTableViewCell ] {
155+ visibleCells. forEach { cell in
156+ guard let collectionTableCell: GLCollectionTableViewCell = cell as? GLCollectionTableViewCell else {
157+ fatalError ( " UITableViewCells must be GLCollectionTableViewCell " )
158+ }
159+
136160 if collectionTableCell. collectionViewPaginatedScroll == true {
137161 XCTAssertTrue ( collectionTableCell. collectionView. isScrollEnabled,
138162 " If custom paginated scroll is enabled the UICollectionView should be scrollable " )
@@ -159,7 +183,11 @@ class GLTableCollectionViewTests: XCTestCase {
159183
160184 XCTAssertGreaterThan ( visibleCells. count, 0 , " UITableView visible cells must be greater than 0 " )
161185
162- for collectionTableCell : GLCollectionTableViewCell in visibleCells as! [ GLCollectionTableViewCell ] {
186+ visibleCells. forEach { cell in
187+ guard let collectionTableCell: GLCollectionTableViewCell = cell as? GLCollectionTableViewCell else {
188+ fatalError ( " UITableViewCells must be GLCollectionTableViewCell " )
189+ }
190+
163191 XCTAssertTrue ( collectionTableCell. collectionView. isOpaque, " The UICollectionView should be opaque for increased performances " )
164192 }
165193 }
0 commit comments