@@ -33,7 +33,7 @@ class ControllerTest: XCTestCase {
33
33
*/
34
34
func testGetInstance( ) {
35
35
// Test Factory Method
36
- let controller : IController = Controller . getInstance ( " ControllerTestKey1 " ) { key in Controller ( key: key) }
36
+ let controller : IController ? = Controller . getInstance ( " ControllerTestKey1 " ) { key in Controller ( key: key) }
37
37
38
38
// test assertions
39
39
XCTAssertNotNil ( controller as? Controller , " Expecting instance not nil " )
@@ -54,8 +54,8 @@ class ControllerTest: XCTestCase {
54
54
*/
55
55
func testRegisterAndExecuteCommand( ) {
56
56
// Create the controller, register the ControllerTestCommand to handle 'ControllerTest' notes
57
- let controller : IController = Controller . getInstance ( " ControllerTestKey1 " ) { key in Controller ( key: key) }
58
- controller. registerCommand ( " ControllerTest " , factory: { ControllerTestCommand ( ) } )
57
+ let controller : IController ? = Controller . getInstance ( " ControllerTestKey1 " ) { key in Controller ( key: key) }
58
+ controller? . registerCommand ( " ControllerTest " , factory: { ControllerTestCommand ( ) } )
59
59
60
60
// Create a 'ControllerTest' note
61
61
let vo : ControllerTestVO = ControllerTestVO ( input: 12 )
@@ -64,7 +64,7 @@ class ControllerTest: XCTestCase {
64
64
// Tell the controller to execute the Command associated with the note
65
65
// the ControllerTestCommand invoked will multiply the vo.input value
66
66
// by 2 and set the result on vo.result
67
- controller. executeCommand ( note)
67
+ controller? . executeCommand ( note)
68
68
69
69
// test assertions
70
70
XCTAssertTrue ( vo. result == 24 , " Expecting vo.result == 24 " )
@@ -79,8 +79,8 @@ class ControllerTest: XCTestCase {
79
79
*/
80
80
func testRegisterAndRemoveCommand( ) {
81
81
// Create the controller, register the ControllerTestCommand to handle 'ControllerTest' notes
82
- let controller : IController = Controller . getInstance ( " ControllerTestKey3 " ) { key in Controller ( key: key) }
83
- controller. registerCommand ( " ControllerRemoveTest " , factory: { ControllerTestCommand ( ) } )
82
+ let controller : IController ? = Controller . getInstance ( " ControllerTestKey3 " ) { key in Controller ( key: key) }
83
+ controller? . registerCommand ( " ControllerRemoveTest " , factory: { ControllerTestCommand ( ) } )
84
84
85
85
// Create a 'ControllerTest' note
86
86
let vo = ControllerTestVO ( input: 12 )
@@ -89,7 +89,7 @@ class ControllerTest: XCTestCase {
89
89
// Tell the controller to execute the Command associated with the note
90
90
// the ControllerTestCommand invoked will multiply the vo.input value
91
91
// by 2 and set the result on vo.result
92
- controller. executeCommand ( note)
92
+ controller? . executeCommand ( note)
93
93
94
94
// test assertions
95
95
XCTAssertTrue ( vo. result == 24 , " Expecting vo.result == 24 " )
@@ -98,12 +98,12 @@ class ControllerTest: XCTestCase {
98
98
vo. result = 0
99
99
100
100
// Remove the Command from the Controller
101
- controller. removeCommand ( " ControllerRemoveTest " )
101
+ controller? . removeCommand ( " ControllerRemoveTest " )
102
102
103
103
// Tell the controller to execute the Command associated with the
104
104
// note. This time, it should not be registered, and our vo result
105
105
// will not change
106
- controller. executeCommand ( note)
106
+ controller? . executeCommand ( note)
107
107
108
108
// test assertions
109
109
XCTAssertTrue ( vo. result == 0 , " Expecting vo.result == 0 " )
@@ -115,16 +115,16 @@ class ControllerTest: XCTestCase {
115
115
func testHasCommand( ) {
116
116
// register the ControllerTestCommand to handle 'hasCommandTest' notes
117
117
let controller = Controller . getInstance ( " ControllerTestKey4 " ) { key in Controller ( key: key) }
118
- controller. registerCommand ( " hasCommandTest " , factory: { ControllerTestCommand ( ) } )
118
+ controller? . registerCommand ( " hasCommandTest " , factory: { ControllerTestCommand ( ) } )
119
119
120
120
// test that hasCommand returns true for hasCommandTest notifications
121
- XCTAssertTrue ( controller. hasCommand ( " hasCommandTest " ) , " Expecting controller.hasCommand('hasCommandTest') == true " )
121
+ XCTAssertTrue ( controller? . hasCommand ( " hasCommandTest " ) == true , " Expecting controller.hasCommand('hasCommandTest') == true " )
122
122
123
123
// Remove the Command from the Controller
124
- controller. removeCommand ( " hasCommandTest " )
124
+ controller? . removeCommand ( " hasCommandTest " )
125
125
126
126
// test that hasCommand returns false for hasCommandTest notifications
127
- XCTAssertTrue ( controller. hasCommand ( " hasCommandTest " ) == false , " Expecting controller.hasCommand('hasCommandTest') == false " )
127
+ XCTAssertTrue ( controller? . hasCommand ( " hasCommandTest " ) == false , " Expecting controller.hasCommand('hasCommandTest') == false " )
128
128
}
129
129
130
130
/**
@@ -141,13 +141,13 @@ class ControllerTest: XCTestCase {
141
141
func testReregisterAndExecuteCommand( ) {
142
142
// Fetch the controller, register the ControllerTestCommand2 to handle 'ControllerTest2' notes
143
143
let controller = Controller . getInstance ( " ControllerTestKey5 " ) { key in Controller ( key: key) }
144
- controller. registerCommand ( " ControllerTest2 " , factory: { ControllerTestCommand2 ( ) } )
144
+ controller? . registerCommand ( " ControllerTest2 " , factory: { ControllerTestCommand2 ( ) } )
145
145
146
146
// Remove the Command from the Controller
147
- controller. removeCommand ( " ControllerTest2 " )
147
+ controller? . removeCommand ( " ControllerTest2 " )
148
148
149
149
// Re-register the Command with the Controller
150
- controller. registerCommand ( " ControllerTest2 " , factory: { ControllerTestCommand2 ( ) } )
150
+ controller? . registerCommand ( " ControllerTest2 " , factory: { ControllerTestCommand2 ( ) } )
151
151
152
152
// Create a 'ControllerTest2' note
153
153
let vo = ControllerTestVO ( input: 12 )
@@ -157,14 +157,14 @@ class ControllerTest: XCTestCase {
157
157
let view = View . getInstance ( " ControllerTestKey5 " ) { key in View ( key: key) }
158
158
159
159
// send the Notification
160
- view. notifyObservers ( note)
160
+ view? . notifyObservers ( note)
161
161
162
162
// test assertions
163
163
// if the command is executed once the value will be 24
164
164
XCTAssertTrue ( vo. result == 24 , " Expecting vo.result == 24 " )
165
165
166
166
// Prove that accumulation works in the VO by sending the notification again
167
- view. notifyObservers ( note)
167
+ view? . notifyObservers ( note)
168
168
169
169
// if the command is executed twice the value will be 48
170
170
XCTAssertTrue ( vo. result == 48 , " Expecting vo.result == 48 " )
0 commit comments