Skip to content

Commit

Permalink
More refactoring for more meaningful naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex da Franca committed Dec 2, 2024
1 parent 6bba6a0 commit e15e940
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Sources/xcresultparser/JunitXML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public struct JunitXML: XmlSerializable {
}

var isDirectory: ObjCBool = false
if DependencyFactory.createFileManager().fileExists(atPath: projectRoot, isDirectory: &isDirectory),
if SharedInstances.fileManager.fileExists(atPath: projectRoot, isDirectory: &isDirectory),
isDirectory.boolValue == true {
self.projectRoot = URL(fileURLWithPath: projectRoot)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
// Created by Alex da Franca on 01.12.24.
//

import Foundation

class DependencyFactory {
static var createShell: () -> Commandline = {
Shell()
}
static var createFileManager: () -> FileManaging = {
FileManager.default
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions Sources/xcresultparser/SharedTypes/SharedInstances.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// SharedInstances.swift
// Xcresultparser
//
// Created by Alex da Franca on 02.12.24.
//

import Foundation

class SharedInstances {
static var fileManager: FileManaging = FileManager.default
}
18 changes: 8 additions & 10 deletions Tests/XcresultparserTests/XcresultparserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,11 @@ final class XcresultparserTests: XCTestCase {
let cliResult = """
./Tests/XcresultparserTests.swift:class XcresultparserTests
"""
let savedFilemangerFactory = DependencyFactory.createFileManager
let savedFilemanger = SharedInstances.fileManager
let savedShellFactory = DependencyFactory.createShell

DependencyFactory.createFileManager = {
MockedFileManager(fileExists: true , isPathDirectory: true)
}
SharedInstances.fileManager = MockedFileManager(fileExists: true , isPathDirectory: true)

let mockedShell = MockedShell(response: Data(cliResult.utf8), error: nil)
DependencyFactory.createShell = {
mockedShell
Expand All @@ -370,7 +369,7 @@ final class XcresultparserTests: XCTestCase {
}
try assertXmlTestReportsAreEqual(expectedFileName: "sonarTestExecutionWithProjectRootRelative", actual: junitXML)

DependencyFactory.createFileManager = savedFilemangerFactory
SharedInstances.fileManager = savedFilemanger
DependencyFactory.createShell = savedShellFactory
}

Expand All @@ -380,12 +379,11 @@ final class XcresultparserTests: XCTestCase {
/Users/actual/project/Tests/XcresultparserTests.swift:class XcresultparserTests
"""

let savedFilemangerFactory = DependencyFactory.createFileManager
let savedFilemanger = SharedInstances.fileManager
let savedShellFactory = DependencyFactory.createShell

DependencyFactory.createFileManager = {
MockedFileManager(fileExists: true , isPathDirectory: true)
}
SharedInstances.fileManager = MockedFileManager(fileExists: true , isPathDirectory: true)

let mockedShell = MockedShell(response: Data(cliResult.utf8), error: nil)
DependencyFactory.createShell = {
mockedShell
Expand All @@ -407,7 +405,7 @@ final class XcresultparserTests: XCTestCase {
}
try assertXmlTestReportsAreEqual(expectedFileName: "sonarTestExecutionWithProjectRootAbsolute", actual: junitXML)

DependencyFactory.createFileManager = savedFilemangerFactory
SharedInstances.fileManager = savedFilemanger
DependencyFactory.createShell = savedShellFactory
}

Expand Down

0 comments on commit e15e940

Please sign in to comment.