From 8d820fa4bf67ad2e8f3fb661c6386f86b2c8c353 Mon Sep 17 00:00:00 2001 From: Antoine van der Lee <4329185+AvdLee@users.noreply.github.com> Date: Wed, 14 Jun 2023 12:08:56 +0200 Subject: [PATCH] Remove force unwraps for data --- .../Changelog/ChangelogItemsFactoryTests.swift | 6 +++--- .../GitBuddyTests/Models/ChangelogItemTests.swift | 4 ++-- Tests/GitBuddyTests/TestHelpers/Mocks.swift | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/GitBuddyTests/Changelog/ChangelogItemsFactoryTests.swift b/Tests/GitBuddyTests/Changelog/ChangelogItemsFactoryTests.swift index 59d0bc6..6c77d12 100644 --- a/Tests/GitBuddyTests/Changelog/ChangelogItemsFactoryTests.swift +++ b/Tests/GitBuddyTests/Changelog/ChangelogItemsFactoryTests.swift @@ -31,7 +31,7 @@ final class ChangelogItemsFactoryTests: XCTestCase { /// It should return the pull request only if no referencing issues are found. func testCreatingItems() { - let pullRequest = PullRequestsJSON.data(using: .utf8)!.mapJSON(to: [PullRequest].self).first! + let pullRequest = Data(PullRequestsJSON.utf8).mapJSON(to: [PullRequest].self).first! let factory = ChangelogItemsFactory(octoKit: octoKit, pullRequests: [pullRequest], project: project) let items = factory.items(using: urlSession) XCTAssertEqual(items.count, 1) @@ -41,8 +41,8 @@ final class ChangelogItemsFactoryTests: XCTestCase { /// It should return the referencing issue with the pull request. func testReferencingIssue() { - let pullRequest = PullRequestsJSON.data(using: .utf8)!.mapJSON(to: [PullRequest].self).last! - let issue = IssueJSON.data(using: .utf8)!.mapJSON(to: Issue.self) + let pullRequest = Data(PullRequestsJSON.utf8).mapJSON(to: [PullRequest].self).last! + let issue = Data(IssueJSON.utf8).mapJSON(to: Issue.self) let factory = ChangelogItemsFactory(octoKit: octoKit, pullRequests: [pullRequest], project: project) Mocker.mockForIssueNumber(39) let items = factory.items(using: urlSession) diff --git a/Tests/GitBuddyTests/Models/ChangelogItemTests.swift b/Tests/GitBuddyTests/Models/ChangelogItemTests.swift index fa47ae0..644569e 100644 --- a/Tests/GitBuddyTests/Models/ChangelogItemTests.swift +++ b/Tests/GitBuddyTests/Models/ChangelogItemTests.swift @@ -38,7 +38,7 @@ final class ChangelogItemTests: XCTestCase { /// It should show the user if possible. func testUser() { - let input = PullRequestsJSON.data(using: .utf8)!.mapJSON(to: [PullRequest].self).first! + let input = Data(PullRequestsJSON.utf8).mapJSON(to: [PullRequest].self).first! input.htmlURL = nil let item = ChangelogItem(input: input, closedBy: input) XCTAssertEqual(item.title, "Add charset utf-8 to html head via [@AvdLee](https://github.com/AvdLee)") @@ -46,7 +46,7 @@ final class ChangelogItemTests: XCTestCase { /// It should fallback to the assignee if the user is nil for Pull Requests. func testAssigneeFallback() { - let input = PullRequestsJSON.data(using: .utf8)!.mapJSON(to: [PullRequest].self).first! + let input = Data(PullRequestsJSON.utf8).mapJSON(to: [PullRequest].self).first! input.user = nil input.htmlURL = nil let item = ChangelogItem(input: input, closedBy: input) diff --git a/Tests/GitBuddyTests/TestHelpers/Mocks.swift b/Tests/GitBuddyTests/TestHelpers/Mocks.swift index 97eb2b7..5efe0c3 100644 --- a/Tests/GitBuddyTests/TestHelpers/Mocks.swift +++ b/Tests/GitBuddyTests/TestHelpers/Mocks.swift @@ -80,7 +80,7 @@ extension Mocker { URLQueryItem(name: "state", value: "closed") ] - let pullRequestJSONData = PullRequestsJSON.data(using: .utf8)! + let pullRequestJSONData = Data(PullRequestsJSON.utf8) let mock = Mock(url: urlComponents.url!, dataType: .json, statusCode: 200, data: [.get: pullRequestJSONData]) mock.register() } @@ -101,19 +101,19 @@ extension Mocker { URLQueryItem(name: "state", value: "closed") ] - let data = IssuesJSON.data(using: .utf8)! + let data = Data(IssuesJSON.utf8) let mock = Mock(url: urlComponents.url!, dataType: .json, statusCode: 200, data: [.get: data]) mock.register() } static func mockForIssueNumber(_ issueNumber: Int) { let urlComponents = URLComponents(string: "https://api.github.com/repos/WeTransfer/Diagnostics/issues/\(issueNumber)")! - let issueJSONData = IssueJSON.data(using: .utf8)! + let issueJSONData = Data(IssueJSON.utf8) Mock(url: urlComponents.url!, dataType: .json, statusCode: 200, data: [.get: issueJSONData]).register() } @discardableResult static func mockRelease() -> Mock { - let releaseJSONData = ReleaseJSON.data(using: .utf8)! + let releaseJSONData = Data(ReleaseJSON.utf8) let mock = Mock( url: URL(string: "https://api.github.com/repos/WeTransfer/Diagnostics/releases")!, dataType: .json, @@ -125,7 +125,7 @@ extension Mocker { } @discardableResult static func mockReleaseNotes() -> Mock { - let releaseNotesJSONData = ReleaseNotesJSON.data(using: .utf8)! + let releaseNotesJSONData = Data(ReleaseNotesJSON.utf8) let mock = Mock( url: URL(string: "https://api.github.com/repos/WeTransfer/Diagnostics/releases/generate-notes")!, dataType: .json, @@ -137,7 +137,7 @@ extension Mocker { } @discardableResult static func mockListReleases() -> Mock { - let releaseJSONData = ListReleasesJSON.data(using: .utf8)! + let releaseJSONData = Data(ListReleasesJSON.utf8) let mock = Mock( url: URL(string: "https://api.github.com/repos/WeTransfer/Diagnostics/releases?per_page=100")!, dataType: .json, @@ -172,7 +172,7 @@ extension Mocker { static func mockForCommentingOn(issueNumber: Int) -> Mock { let urlComponents = URLComponents(string: "https://api.github.com/repos/WeTransfer/Diagnostics/issues/\(issueNumber)/comments")! - let commentJSONData = CommentJSON.data(using: .utf8)! + let commentJSONData = Data(CommentJSON.utf8) return Mock(url: urlComponents.url!, dataType: .json, statusCode: 201, data: [.post: commentJSONData]) } }