@@ -33,7 +33,7 @@ class ControllerTest: XCTestCase {
3333 */
3434 func testGetInstance( ) {
3535 // 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) }
3737
3838 // test assertions
3939 XCTAssertNotNil ( controller as? Controller , " Expecting instance not nil " )
@@ -54,8 +54,8 @@ class ControllerTest: XCTestCase {
5454 */
5555 func testRegisterAndExecuteCommand( ) {
5656 // 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 ( ) } )
5959
6060 // Create a 'ControllerTest' note
6161 let vo : ControllerTestVO = ControllerTestVO ( input: 12 )
@@ -64,7 +64,7 @@ class ControllerTest: XCTestCase {
6464 // Tell the controller to execute the Command associated with the note
6565 // the ControllerTestCommand invoked will multiply the vo.input value
6666 // by 2 and set the result on vo.result
67- controller. executeCommand ( note)
67+ controller? . executeCommand ( note)
6868
6969 // test assertions
7070 XCTAssertTrue ( vo. result == 24 , " Expecting vo.result == 24 " )
@@ -79,8 +79,8 @@ class ControllerTest: XCTestCase {
7979 */
8080 func testRegisterAndRemoveCommand( ) {
8181 // 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 ( ) } )
8484
8585 // Create a 'ControllerTest' note
8686 let vo = ControllerTestVO ( input: 12 )
@@ -89,7 +89,7 @@ class ControllerTest: XCTestCase {
8989 // Tell the controller to execute the Command associated with the note
9090 // the ControllerTestCommand invoked will multiply the vo.input value
9191 // by 2 and set the result on vo.result
92- controller. executeCommand ( note)
92+ controller? . executeCommand ( note)
9393
9494 // test assertions
9595 XCTAssertTrue ( vo. result == 24 , " Expecting vo.result == 24 " )
@@ -98,12 +98,12 @@ class ControllerTest: XCTestCase {
9898 vo. result = 0
9999
100100 // Remove the Command from the Controller
101- controller. removeCommand ( " ControllerRemoveTest " )
101+ controller? . removeCommand ( " ControllerRemoveTest " )
102102
103103 // Tell the controller to execute the Command associated with the
104104 // note. This time, it should not be registered, and our vo result
105105 // will not change
106- controller. executeCommand ( note)
106+ controller? . executeCommand ( note)
107107
108108 // test assertions
109109 XCTAssertTrue ( vo. result == 0 , " Expecting vo.result == 0 " )
@@ -115,16 +115,16 @@ class ControllerTest: XCTestCase {
115115 func testHasCommand( ) {
116116 // register the ControllerTestCommand to handle 'hasCommandTest' notes
117117 let controller = Controller . getInstance ( " ControllerTestKey4 " ) { key in Controller ( key: key) }
118- controller. registerCommand ( " hasCommandTest " , factory: { ControllerTestCommand ( ) } )
118+ controller? . registerCommand ( " hasCommandTest " , factory: { ControllerTestCommand ( ) } )
119119
120120 // 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 " )
122122
123123 // Remove the Command from the Controller
124- controller. removeCommand ( " hasCommandTest " )
124+ controller? . removeCommand ( " hasCommandTest " )
125125
126126 // 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 " )
128128 }
129129
130130 /**
@@ -141,13 +141,13 @@ class ControllerTest: XCTestCase {
141141 func testReregisterAndExecuteCommand( ) {
142142 // Fetch the controller, register the ControllerTestCommand2 to handle 'ControllerTest2' notes
143143 let controller = Controller . getInstance ( " ControllerTestKey5 " ) { key in Controller ( key: key) }
144- controller. registerCommand ( " ControllerTest2 " , factory: { ControllerTestCommand2 ( ) } )
144+ controller? . registerCommand ( " ControllerTest2 " , factory: { ControllerTestCommand2 ( ) } )
145145
146146 // Remove the Command from the Controller
147- controller. removeCommand ( " ControllerTest2 " )
147+ controller? . removeCommand ( " ControllerTest2 " )
148148
149149 // Re-register the Command with the Controller
150- controller. registerCommand ( " ControllerTest2 " , factory: { ControllerTestCommand2 ( ) } )
150+ controller? . registerCommand ( " ControllerTest2 " , factory: { ControllerTestCommand2 ( ) } )
151151
152152 // Create a 'ControllerTest2' note
153153 let vo = ControllerTestVO ( input: 12 )
@@ -157,14 +157,14 @@ class ControllerTest: XCTestCase {
157157 let view = View . getInstance ( " ControllerTestKey5 " ) { key in View ( key: key) }
158158
159159 // send the Notification
160- view. notifyObservers ( note)
160+ view? . notifyObservers ( note)
161161
162162 // test assertions
163163 // if the command is executed once the value will be 24
164164 XCTAssertTrue ( vo. result == 24 , " Expecting vo.result == 24 " )
165165
166166 // Prove that accumulation works in the VO by sending the notification again
167- view. notifyObservers ( note)
167+ view? . notifyObservers ( note)
168168
169169 // if the command is executed twice the value will be 48
170170 XCTAssertTrue ( vo. result == 48 , " Expecting vo.result == 48 " )
0 commit comments