Skip to content

Commit 45ab1df

Browse files
authored
Rename JSONObject.loadFile(named:) to JSONObject(fromFileNamed:)` (#18529)
2 parents e6f44ea + e2e5327 commit 45ab1df

14 files changed

+80
-55
lines changed

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@
933933
46F584B92624E6380010A723 /* BlockEditorSettings+GutenbergEditorSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F584B72624E6380010A723 /* BlockEditorSettings+GutenbergEditorSettings.swift */; };
934934
46F58501262605930010A723 /* BlockEditorSettingsServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F58500262605930010A723 /* BlockEditorSettingsServiceTests.swift */; };
935935
4A17C1A4281A823E0001FFE5 /* NSManagedObject+Fixture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A17C1A3281A823E0001FFE5 /* NSManagedObject+Fixture.swift */; };
936+
4A266B8F282B05210089CF3D /* JSONObjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A266B8E282B05210089CF3D /* JSONObjectTests.swift */; };
936937
4B2DD0F29CD6AC353C056D41 /* Pods_WordPressUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DCE7542239FBC709B90EA85 /* Pods_WordPressUITests.framework */; };
937938
4C8A715EBCE7E73AEE216293 /* Pods_WordPressShareExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F47DB4A8EC2E6844E213A3FA /* Pods_WordPressShareExtension.framework */; };
938939
4D520D4F22972BC9002F5924 /* acknowledgements.html in Resources */ = {isa = PBXBuildFile; fileRef = 4D520D4E22972BC9002F5924 /* acknowledgements.html */; };
@@ -5729,6 +5730,7 @@
57295730
46F58500262605930010A723 /* BlockEditorSettingsServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockEditorSettingsServiceTests.swift; sourceTree = "<group>"; };
57305731
46F84612185A8B7E009D0DA5 /* PostContentProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PostContentProvider.h; sourceTree = "<group>"; };
57315732
4A17C1A3281A823E0001FFE5 /* NSManagedObject+Fixture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSManagedObject+Fixture.swift"; sourceTree = "<group>"; };
5733+
4A266B8E282B05210089CF3D /* JSONObjectTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONObjectTests.swift; sourceTree = "<group>"; };
57325734
4D520D4E22972BC9002F5924 /* acknowledgements.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = acknowledgements.html; path = "../Pods/Target Support Files/Pods-Apps-WordPress/acknowledgements.html"; sourceTree = "<group>"; };
57335735
51A5F017948878F7E26979A0 /* Pods-Apps-WordPress.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Apps-WordPress.release.xcconfig"; path = "../Pods/Target Support Files/Pods-Apps-WordPress/Pods-Apps-WordPress.release.xcconfig"; sourceTree = "<group>"; };
57345736
528B9926294302CD0A4EB5C4 /* Pods-WordPressScreenshotGeneration.release-alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressScreenshotGeneration.release-alpha.xcconfig"; path = "../Pods/Target Support Files/Pods-WordPressScreenshotGeneration/Pods-WordPressScreenshotGeneration.release-alpha.xcconfig"; sourceTree = "<group>"; };
@@ -11427,6 +11429,7 @@
1142711429
FAE8EE9B273AD0A800A65307 /* QuickStartSettingsTests.swift */,
1142811430
179501CC27A01D4100882787 /* PublicizeAuthorizationURLComponentsTests.swift */,
1142911431
80EF92922810FA5A0064A971 /* QuickStartFactoryTests.swift */,
11432+
4A266B8E282B05210089CF3D /* JSONObjectTests.swift */,
1143011433
);
1143111434
name = Utility;
1143211435
sourceTree = "<group>";
@@ -19721,6 +19724,7 @@
1972119724
C3DA0EE02807062600DA3250 /* SiteCreationNameTracksEventTests.swift in Sources */,
1972219725
73C8F06621BEF76B00DDDF7E /* SiteAssemblyViewTests.swift in Sources */,
1972319726
73178C2821BEE09300E37C9A /* SiteCreationDataCoordinatorTests.swift in Sources */,
19727+
4A266B8F282B05210089CF3D /* JSONObjectTests.swift in Sources */,
1972419728
D81C2F6020F891C4002AE1F1 /* TrashCommentActionTests.swift in Sources */,
1972519729
570BFD8D22823DE5007859A8 /* PostActionSheetTests.swift in Sources */,
1972619730
FA4ADADA1C509FE400F858D7 /* SiteManagementServiceTests.swift in Sources */,

WordPress/WordPressTest/ActivityContentFactoryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ final class ActivityContentFactoryTests: XCTestCase {
99
}
1010

1111
private func mockBlock() throws -> JSONObject {
12-
return try .loadFile(named: "activity-log-activity-content.json")
12+
return try JSONObject(fromFileNamed: "activity-log-activity-content.json")
1313
}
1414

1515
}

WordPress/WordPressTest/ActivityLogTestData.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,39 @@ class ActivityLogTestData {
2626
}
2727

2828
func getCommentEventDictionary() throws -> JSONObject {
29-
return try .loadFile(named: "activity-log-comment.json")
29+
return try JSONObject(fromFileNamed: "activity-log-comment.json")
3030
}
3131

3232
func getPostEventDictionary() throws -> JSONObject {
33-
return try .loadFile(named: "activity-log-post.json")
33+
return try JSONObject(fromFileNamed: "activity-log-post.json")
3434
}
3535

3636
func getPingbackDictionary() throws -> JSONObject {
37-
return try .loadFile(named: "activity-log-pingback-content.json")
37+
return try JSONObject(fromFileNamed: "activity-log-pingback-content.json")
3838
}
3939

4040
func getPostContentDictionary() throws -> JSONObject {
41-
return try .loadFile(named: "activity-log-post-content.json")
41+
return try JSONObject(fromFileNamed: "activity-log-post-content.json")
4242
}
4343

4444
func getCommentContentDictionary() throws -> JSONObject {
45-
return try .loadFile(named: "activity-log-comment-content.json")
45+
return try JSONObject(fromFileNamed: "activity-log-comment-content.json")
4646
}
4747

4848
func getThemeContentDictionary() throws -> JSONObject {
49-
return try .loadFile(named: "activity-log-theme-content.json")
49+
return try JSONObject(fromFileNamed: "activity-log-theme-content.json")
5050
}
5151

5252
func getSettingsContentDictionary() throws -> JSONObject {
53-
return try .loadFile(named: "activity-log-settings-content.json")
53+
return try JSONObject(fromFileNamed: "activity-log-settings-content.json")
5454
}
5555

5656
func getSiteContentDictionary() throws -> JSONObject {
57-
return try .loadFile(named: "activity-log-site-content.json")
57+
return try JSONObject(fromFileNamed: "activity-log-site-content.json")
5858
}
5959

6060
func getPluginContentDictionary() throws -> JSONObject {
61-
return try .loadFile(named: "activity-log-plugin-content.json")
61+
return try JSONObject(fromFileNamed: "activity-log-plugin-content.json")
6262
}
6363

6464
func getCommentRangeDictionary() throws -> JSONObject {

WordPress/WordPressTest/FormattableCommentContentTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ final class FormattableCommentContentTests: XCTestCase {
133133
}
134134

135135
private func mockDictionary() throws -> JSONObject {
136-
return try .loadFile(named: "notifications-comment-content.json")
136+
return try JSONObject(fromFileNamed: "notifications-comment-content.json")
137137
}
138138

139139
private func loadLikeNotification() throws -> WordPress.Notification {
140140
return try utility.loadLikeNotification()
141141
}
142142

143143
private func loadMeta() throws -> JSONObject {
144-
return try .loadFile(named: "notifications-comment-meta.json")
144+
return try JSONObject(fromFileNamed: "notifications-comment-meta.json")
145145
}
146146

147147
private func mockedActions() -> [FormattableContentAction] {

WordPress/WordPressTest/FormattableContentGroupTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class FormattableContentGroupTests: XCTestCase {
5959
}
6060

6161
private func mockActivity() throws -> JSONObject {
62-
return try .loadFile(named: "activity-log-activity-content.json")
62+
return try JSONObject(fromFileNamed: "activity-log-activity-content.json")
6363
}
6464

6565
}

WordPress/WordPressTest/FormattableUserContentTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ final class FormattableUserContentTests: XCTestCase {
130130
}
131131

132132
private func mockDictionary() throws -> JSONObject {
133-
return try .loadFile(named: "notifications-user-content.json")
133+
return try JSONObject(fromFileNamed: "notifications-user-content.json")
134134
}
135135

136136
private func loadLikeNotification() throws -> WordPress.Notification {
137137
return try .fixture(fromFile: "notifications-like.json", insertInto: contextManager.mainContext)
138138
}
139139

140140
private func loadMeta() throws -> JSONObject {
141-
return try .loadFile(named: "notifications-user-content-meta.json")
141+
return try JSONObject(fromFileNamed: "notifications-user-content-meta.json")
142142
}
143143

144144
private func mockedActions() -> [FormattableContentAction] {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import XCTest
2+
3+
class JSONObjectTests: XCTestCase {
4+
func testParsingFileWithUnexpectedFileExtension() throws {
5+
try XCTAssertThrowsError(JSONObject(fromFileNamed: "notifications.josn"))
6+
}
7+
8+
func testParsingNonexistentFiles() throws {
9+
try XCTAssertThrowsError(JSONObject(fromFileNamed: "a-file-that-does-not-exist"))
10+
try XCTAssertThrowsError(JSONObject(fromFileNamed: "a-file-that-does-not-exist.json"))
11+
}
12+
13+
func testAllowedFileNames() throws {
14+
try XCTAssertNoThrow(JSONObject(fromFileNamed: "authtoken"))
15+
try XCTAssertNoThrow(JSONObject(fromFileNamed: "authtoken.json"))
16+
}
17+
}

WordPress/WordPressTest/NSManagedObject+Fixture.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +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) throws -> Self {
12-
let jsonObject = try JSONObject.loadFile(named: fileName)
12+
let jsonObject = try JSONObject(fromFileNamed: fileName)
1313
let model = Self.init(context: context)
1414
for (key, value) in jsonObject {
1515
model.setValue(value, forKey: key)

WordPress/WordPressTest/NotificationContentRangeFactoryTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,27 @@ final class NotificationContentRangeFactoryTests: XCTestCase {
4040
}
4141

4242
private func mockCommentRange() throws -> JSONObject {
43-
return try .loadFile(named: "notifications-comment-range.json")
43+
return try JSONObject(fromFileNamed: "notifications-comment-range.json")
4444
}
4545

4646
private func mockIconRange() throws -> JSONObject {
47-
return try .loadFile(named: "notifications-icon-range.json")
47+
return try JSONObject(fromFileNamed: "notifications-icon-range.json")
4848
}
4949

5050
private func mockPostRange() throws -> JSONObject {
51-
return try .loadFile(named: "notifications-post-range.json")
51+
return try JSONObject(fromFileNamed: "notifications-post-range.json")
5252
}
5353

5454
private func mockSiteRange() throws -> JSONObject {
55-
return try .loadFile(named: "notifications-site-range.json")
55+
return try JSONObject(fromFileNamed: "notifications-site-range.json")
5656
}
5757

5858
private func mockUserRange() throws -> JSONObject {
59-
return try .loadFile(named: "notifications-user-range.json")
59+
return try JSONObject(fromFileNamed: "notifications-user-range.json")
6060
}
6161

6262
private func mockBlockQuoteRange() throws -> JSONObject {
63-
return try .loadFile(named: "notifications-blockquote-range.json")
63+
return try JSONObject(fromFileNamed: "notifications-blockquote-range.json")
6464
}
6565

6666
}

WordPress/WordPressTest/NotificationTextContentTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ final class NotificationTextContentTests: XCTestCase {
8989
}
9090

9191
private func mockDictionary() throws -> JSONObject {
92-
return try .loadFile(named: "notifications-text-content.json")
92+
return try JSONObject(fromFileNamed: "notifications-text-content.json")
9393
}
9494

9595
private func mockButtonContentDictionary() throws -> JSONObject {
96-
return try .loadFile(named: "notifications-button-text-content.json")
96+
return try JSONObject(fromFileNamed: "notifications-button-text-content.json")
9797
}
9898

9999
private func loadLikeNotification() throws -> WordPress.Notification {

0 commit comments

Comments
 (0)