Skip to content

Commit c9cdcb2

Browse files
committed
Replace JSONLoader with static functions
Currently fatalError is used to "handle errors", but they'll be replaced with throwing errors later.
1 parent 2009f8a commit c9cdcb2

12 files changed

Lines changed: 41 additions & 55 deletions

WordPress/WordPressTest/ActivityContentFactoryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ final class ActivityContentFactoryTests: XCTestCase {
1515
}
1616

1717
private func getDictionaryFromFile(named fileName: String) -> [String: AnyObject] {
18-
return JSONLoader().loadFile(named: fileName) ?? [:]
18+
return JSONObject.loadFile(named: fileName)
1919
}
2020
}

WordPress/WordPressTest/ActivityLogTestData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ActivityLogTestData {
2828
}
2929

3030
private func getDictionaryFromFile(named fileName: String) -> [String: AnyObject] {
31-
return JSONLoader().loadFile(named: fileName) ?? [:]
31+
return JSONObject.loadFile(named: fileName)
3232
}
3333

3434
func getCommentEventDictionary() -> [String: AnyObject] {

WordPress/WordPressTest/FormattableCommentContentTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ final class FormattableCommentContentTests: XCTestCase {
138138
}
139139

140140
private func getDictionaryFromFile(named fileName: String) -> [String: AnyObject] {
141-
return JSONLoader().loadFile(named: fileName) ?? [:]
141+
return JSONObject.loadFile(named: fileName)
142142
}
143143

144144
private func loadLikeNotification() -> WordPress.Notification {

WordPress/WordPressTest/FormattableContentGroupTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ final class FormattableContentGroupTests: XCTestCase {
6464
}
6565

6666
private func getDictionaryFromFile(named fileName: String) -> [String: AnyObject] {
67-
return JSONLoader().loadFile(named: fileName) ?? [:]
67+
return JSONObject.loadFile(named: fileName)
6868
}
6969
}

WordPress/WordPressTest/FormattableUserContentTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ final class FormattableUserContentTests: XCTestCase {
134134
}
135135

136136
private func getDictionaryFromFile(named fileName: String) -> [String: AnyObject] {
137-
return JSONLoader().loadFile(named: fileName) ?? [:]
137+
return JSONObject.loadFile(named: fileName)
138138
}
139139

140140
private func loadLikeNotification() -> WordPress.Notification {

WordPress/WordPressTest/NSManagedObject+Fixture.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ extension NSManagedObject {
99
/// - context: The managed object context to use
1010
/// - Returns: A new instance with property values of the given JSON file.
1111
static func fixture(fromFile fileName: String, insertInto context: NSManagedObjectContext) -> Self {
12-
guard let jsonObject = JSONLoader().loadFile(named: fileName) else {
13-
fatalError("Mockup data could not be parsed, the filename is \(fileName)")
14-
}
12+
let jsonObject = JSONObject.loadFile(named: fileName)
1513
let model = Self.init(context: context)
1614
for (key, value) in jsonObject {
1715
model.setValue(value, forKey: key)

WordPress/WordPressTest/NotificationContentRangeFactoryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ final class NotificationContentRangeFactoryTests: XCTestCase {
6565
}
6666

6767
private func getDictionaryFromFile(named fileName: String) -> [String: AnyObject] {
68-
return JSONLoader().loadFile(named: fileName) ?? [:]
68+
return JSONObject.loadFile(named: fileName)
6969
}
7070
}

WordPress/WordPressTest/NotificationTextContentTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ final class NotificationTextContentTests: XCTestCase {
9696
}
9797

9898
private func getDictionaryFromFile(named fileName: String) -> [String: AnyObject] {
99-
return JSONLoader().loadFile(named: fileName) ?? [:]
99+
return JSONObject.loadFile(named: fileName)
100100
}
101101

102102
private func loadLikeNotification() -> WordPress.Notification {

WordPress/WordPressTest/NotificationUtility.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class NotificationUtility {
4545
}
4646

4747
func mockCommentContent() -> FormattableCommentContent {
48-
let dictionary = JSONLoader().loadFile(named: "notifications-replied-comment.json") ?? [:]
48+
let dictionary = JSONObject.loadFile(named: "notifications-replied-comment.json")
4949
let body = dictionary["body"]
5050
let blocks = NotificationContentFactory.content(from: body as! [[String: AnyObject]], actionsParser: NotificationActionParser(), parent: WordPress.Notification(context: contextManager.mainContext))
5151
return blocks.filter { $0.kind == .comment }.first! as! FormattableCommentContent

WordPress/WordPressTest/NotificationsContentFactoryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class NotificationsContentFactoryTests: XCTestCase {
3636
}
3737

3838
private func getDictionaryFromFile(named fileName: String) -> [String: AnyObject] {
39-
return JSONLoader().loadFile(named: fileName) ?? [:]
39+
return JSONObject.loadFile(named: fileName)
4040
}
4141

4242
func loadLikeNotification() -> WordPress.Notification {

0 commit comments

Comments
 (0)