Skip to content

Commit

Permalink
Rename mock properties, remove not needed try catch block
Browse files Browse the repository at this point in the history
- Address PR comments
  • Loading branch information
EgzonArifi committed Jan 13, 2025
1 parent c85b635 commit f328b3d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = ""
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit f328b3d

Please sign in to comment.