Skip to content

Commit b10093a

Browse files
author
Florian Rieger
committed
Added MutableInteractorError.
1 parent 15ac469 commit b10093a

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import Foundation
2+
3+
public class MutableInteractorError: InteractorError {
4+
5+
private var mutableMessage: String
6+
private var mutableCode: Int
7+
private var mutableDict: [String : Any]
8+
9+
// MARK: - Init
10+
11+
public init(message: String, code: Int, dict: [String: Any]) {
12+
mutableMessage = message
13+
mutableCode = code
14+
mutableDict = dict
15+
super.init(domain: "com.appcron.acinteractor", code: code, userInfo: nil)
16+
}
17+
18+
public convenience init(message: String, code: Int) {
19+
self.init(message: message, code: code, dict: [String: Any]())
20+
}
21+
22+
public convenience init(message: String) {
23+
self.init(message: message, code: 0)
24+
}
25+
26+
public required init?(coder aDecoder: NSCoder) {
27+
fatalError("init(coder:) has not been implemented")
28+
}
29+
30+
// MARK: - Getter & Setter
31+
32+
public override var message: String {
33+
get {
34+
return mutableMessage
35+
}
36+
set {
37+
mutableMessage = newValue
38+
}
39+
}
40+
41+
public override var code: Int {
42+
get {
43+
return mutableCode
44+
}
45+
set {
46+
mutableCode = newValue
47+
}
48+
}
49+
50+
public override var dict: [String : Any] {
51+
get {
52+
return mutableDict
53+
}
54+
set {
55+
mutableDict = newValue
56+
}
57+
}
58+
59+
60+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import XCTest
2+
@testable import ACInteractor
3+
4+
class MutableInteractorErrorTests: XCTestCase {
5+
6+
var testError: MutableInteractorError?
7+
var testErrorDict = [String: Any]()
8+
9+
override func setUp() {
10+
super.setUp()
11+
// Put setup code here. This method is called before the invocation of each test method in the class.
12+
13+
testError = MutableInteractorError(message: "")
14+
15+
testErrorDict["key1"] = "value1"
16+
testErrorDict["key2"] = 2
17+
}
18+
19+
// MARK: - Init
20+
21+
func testInit_withMessage_setsMessage() {
22+
// Act
23+
let error = MutableInteractorError(message: "testMessage")
24+
25+
// Assert
26+
XCTAssertEqual(error.message, "testMessage")
27+
}
28+
29+
func testInit_withCode_setsCode() {
30+
// Act
31+
let error = MutableInteractorError(message: "", code: 42)
32+
33+
// Assert
34+
XCTAssertEqual(error.code, 42)
35+
}
36+
37+
func testInit_withDict_setsDict() {
38+
// Act
39+
let error = MutableInteractorError(message: "", code: 0, dict: testErrorDict)
40+
41+
// Assert
42+
XCTAssertEqual(error.dict["key1"] as? String, "value1")
43+
XCTAssertEqual(error.dict["key2"] as? Int, 2)
44+
}
45+
46+
// MARK: - Setters
47+
48+
func testSetMessage_setsMessage() {
49+
// Act
50+
testError?.message = "newMessage"
51+
52+
// Assert
53+
XCTAssertEqual(testError?.message, "newMessage")
54+
}
55+
56+
func testSetCode_setCode() {
57+
// Act
58+
testError?.code = 42
59+
60+
// Assert
61+
XCTAssertEqual(testError?.code, 42)
62+
}
63+
64+
func testSetDict_setsDict() {
65+
// Act
66+
testError?.dict = testErrorDict
67+
68+
// Assert
69+
XCTAssertEqual(testError?.dict["key1"] as? String, "value1")
70+
XCTAssertEqual(testError?.dict["key2"] as? Int, 2)
71+
}
72+
73+
func testSetDictValue_addsDictValue() {
74+
// Arrange
75+
testError?.dict = testErrorDict
76+
77+
// Act
78+
testError?.dict["newKey"] = "newValue"
79+
80+
// Assert
81+
XCTAssertEqual(testError?.dict["newKey"] as? String, "newValue")
82+
XCTAssertEqual(testError?.dict.count, testErrorDict.count + 1)
83+
}
84+
85+
}

0 commit comments

Comments
 (0)