From f328b3d55f2837b7ed69e099a7cb22c6ceec0b3d Mon Sep 17 00:00:00 2001 From: Egzon Arifi Date: Mon, 13 Jan 2025 10:11:21 +0100 Subject: [PATCH] Rename mock properties, remove not needed try catch block - Address PR comments --- .../Generator/PlatformLocalizationGenerator.swift | 6 +----- .../Processor/LocalizationProcessorTests.swift | 4 ++-- .../Processor/Mock/MockLocalizationModule.swift | 10 +++++----- .../DirectoryOperations/DirectoryOperatorTests.swift | 6 +++--- .../DirectoryOperations/Mock/MockFileManager.swift | 12 ++++++------ 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Sources/LinguaLib/Infrastructure/LocalizationGenerator/Generator/PlatformLocalizationGenerator.swift b/Sources/LinguaLib/Infrastructure/LocalizationGenerator/Generator/PlatformLocalizationGenerator.swift index 35b8f3c..cd08bd8 100644 --- a/Sources/LinguaLib/Infrastructure/LocalizationGenerator/Generator/PlatformLocalizationGenerator.swift +++ b/Sources/LinguaLib/Infrastructure/LocalizationGenerator/Generator/PlatformLocalizationGenerator.swift @@ -12,11 +12,7 @@ final class PlatformLocalizationGenerator: PlatformLocalizationGenerating { func generateLocalizationFiles(data: [LocalizationSheet], config: Config.Localization) throws { try data.forEach { data in - do { - try localizedFileGenerator.generate(for: data, config: config) - } catch { - throw error - } + try localizedFileGenerator.generate(for: data, config: config) } } } diff --git a/Tests/LinguaTests/Application/Processor/LocalizationProcessorTests.swift b/Tests/LinguaTests/Application/Processor/LocalizationProcessorTests.swift index 3108825..53ea8f0 100644 --- a/Tests/LinguaTests/Application/Processor/LocalizationProcessorTests.swift +++ b/Tests/LinguaTests/Application/Processor/LocalizationProcessorTests.swift @@ -35,7 +35,7 @@ final class LocalizationProcessorTests: XCTestCase { } func test_process_throwsErrorWhenModuleLocalizationFails() async throws { - let localizationModule = MockLocalizationModule(shouldThrow: "Error_message") + let localizationModule = MockLocalizationModule(errorMessage: "Error_message") let (sut, actors) = makeSUT(localizationModule: localizationModule) let tempDirectoryURL = try createTemporaryDirectoryURL() let configPath = try createTemporaryConfigFile(data: createConfigData(in: tempDirectoryURL), tempDirectoryURL: tempDirectoryURL) @@ -85,7 +85,7 @@ private extension LocalizationProcessorTests { let mockLocalizationModule: MockLocalizationModule } - func makeSUT(localizationModule: MockLocalizationModule = MockLocalizationModule(shouldThrow: .none), + func makeSUT(localizationModule: MockLocalizationModule = MockLocalizationModule(errorMessage: .none), configFileGenerator: ConfigInitialFileGenerating = ConfigInitialFileGenerator.make()) -> (sut: LocalizationProcessor, actors: Actors) { let argumentParser = CommandLineParser() let logger = MockLogger() diff --git a/Tests/LinguaTests/Application/Processor/Mock/MockLocalizationModule.swift b/Tests/LinguaTests/Application/Processor/Mock/MockLocalizationModule.swift index 0ec1606..3779735 100644 --- a/Tests/LinguaTests/Application/Processor/Mock/MockLocalizationModule.swift +++ b/Tests/LinguaTests/Application/Processor/Mock/MockLocalizationModule.swift @@ -6,15 +6,15 @@ final class MockLocalizationModule: ModuleLocalizing { case localize(LocalizationPlatform) } private(set) var messages = [Message]() - private let shouldThrow: String? + private let errorMessage: String? - init(shouldThrow: String?) { - self.shouldThrow = shouldThrow + init(errorMessage: String?) { + self.errorMessage = errorMessage } func localize(for platform: LocalizationPlatform) async throws { - if let shouldThrow { - throw DirectoryOperationError.folderCreationFailed(shouldThrow) + if let errorMessage { + throw DirectoryOperationError.folderCreationFailed(errorMessage) } messages.append(.localize(platform)) } diff --git a/Tests/LinguaTests/Infrastructure/DirectoryOperations/DirectoryOperatorTests.swift b/Tests/LinguaTests/Infrastructure/DirectoryOperations/DirectoryOperatorTests.swift index d0c5298..7d33258 100644 --- a/Tests/LinguaTests/Infrastructure/DirectoryOperations/DirectoryOperatorTests.swift +++ b/Tests/LinguaTests/Infrastructure/DirectoryOperations/DirectoryOperatorTests.swift @@ -13,7 +13,7 @@ final class DirectoryOperatorTests: XCTestCase { func test_createDirectory_throwsError_onFailure() { let errorFileManager = MockFileManager() - errorFileManager.shouldThrowErrorOnCreateDirectory = "Create_failed" + errorFileManager.onCreateDirectoryError = "Create_failed" let sut = makeSUT(fileManager: errorFileManager) let outputDirectory = NSTemporaryDirectory() let directoryName = "TestDirectory" @@ -25,7 +25,7 @@ final class DirectoryOperatorTests: XCTestCase { func test_createDirectory_throwsError_onEmptyDirectory() { let errorFileManager = MockFileManager() - errorFileManager.shouldThrowErrorOnCreateDirectory = "Directory name is empty." + errorFileManager.onCreateDirectoryError = "Directory name is empty." let sut = makeSUT(fileManager: errorFileManager) let outputDirectory = NSTemporaryDirectory() let directoryName = "" @@ -59,7 +59,7 @@ final class DirectoryOperatorTests: XCTestCase { func test_removeFiles_throwsError_onRemoveItem() throws { let errorFileManager = MockFileManager() - errorFileManager.shouldThrowErrorOnRemoveItem = "Remove_failed" + errorFileManager.onRemoveItemError = "Remove_failed" let sut = makeSUT(fileManager: errorFileManager) let outputDirectory = NSTemporaryDirectory() let directoryName = "TestDirectory" diff --git a/Tests/LinguaTests/Infrastructure/DirectoryOperations/Mock/MockFileManager.swift b/Tests/LinguaTests/Infrastructure/DirectoryOperations/Mock/MockFileManager.swift index 895d7e2..c74a31c 100644 --- a/Tests/LinguaTests/Infrastructure/DirectoryOperations/Mock/MockFileManager.swift +++ b/Tests/LinguaTests/Infrastructure/DirectoryOperations/Mock/MockFileManager.swift @@ -3,8 +3,8 @@ import Foundation final class MockFileManager: FileManager { let files: [String] - var shouldThrowErrorOnRemoveItem: String? - var shouldThrowErrorOnCreateDirectory: String? + var onRemoveItemError: String? + var onCreateDirectoryError: String? init(files: [String] = []) { self.files = files @@ -17,16 +17,16 @@ final class MockFileManager: FileManager { override func createDirectory(at url: URL, withIntermediateDirectories createIntermediates: Bool, attributes: [FileAttributeKey : Any]? = nil) throws { - if let shouldThrowErrorOnCreateDirectory { - throw DirectoryOperationError.folderCreationFailed(shouldThrowErrorOnCreateDirectory) + if let onCreateDirectoryError { + throw DirectoryOperationError.folderCreationFailed(onCreateDirectoryError) } else { try super.createDirectory(at: url, withIntermediateDirectories: createIntermediates, attributes: attributes) } } override func removeItem(at URL: URL) throws { - if let shouldThrowErrorOnRemoveItem { - throw DirectoryOperationError.removeItemFailed(shouldThrowErrorOnRemoveItem) + if let onRemoveItemError { + throw DirectoryOperationError.removeItemFailed(onRemoveItemError) } else { try super.removeItem(at: URL) }