From 8734d7a567274ff910e78ccb988f36cd29826124 Mon Sep 17 00:00:00 2001 From: Saad Date: Tue, 12 Dec 2023 23:32:13 -0500 Subject: [PATCH] update --- .gitignore | 23 ++ VERSION | 6 +- go.mod | 2 +- src/core/controller/Controller.go | 76 +++--- src/core/model/Model.go | 46 ++-- src/core/view/View.go | 88 +++---- src/interfaces/ICommand.go | 2 +- src/interfaces/IController.go | 6 +- src/interfaces/IFacade.go | 10 +- src/interfaces/IMediator.go | 8 +- src/interfaces/IModel.go | 2 +- src/interfaces/INotification.go | 2 +- src/interfaces/INotifier.go | 2 +- src/interfaces/IObserver.go | 2 +- src/interfaces/IProxy.go | 4 +- src/interfaces/IView.go | 2 +- src/patterns/command/MacroCommand.go | 60 ++--- src/patterns/command/SimpleCommand.go | 14 +- src/patterns/facade/Facade.go | 195 +++++++------- src/patterns/facade/Notifier.go | 38 +-- src/patterns/mediator/Mediator.go | 32 +-- src/patterns/observer/Notification.go | 18 +- src/patterns/observer/Observer.go | 16 +- src/patterns/proxy/Proxy.go | 14 +- test/core/controller/ControllerTestCommand.go | 6 +- .../core/controller/ControllerTestCommand2.go | 8 +- test/core/controller/ControllerTestVO.go | 2 +- test/core/controller/Controller_test.go | 88 +++---- test/core/model/Model_test.go | 82 +++--- test/core/view/ViewTestMediator.go | 2 +- test/core/view/ViewTestMediator2.go | 2 +- test/core/view/ViewTestMediator3.go | 4 +- test/core/view/ViewTestMediator4.go | 2 +- test/core/view/ViewTestMediator5.go | 2 +- test/core/view/ViewTestMediator6.go | 2 +- test/core/view/ViewTestNote.go | 18 -- test/core/view/View_test.go | 245 +++++++++--------- .../command/MacroCommandTestCommand.go | 18 +- .../command/MacroCommandTestSub1Command.go | 6 +- .../command/MacroCommandTestSub2Command.go | 6 +- test/patterns/command/MacroCommandTestVO.go | 2 +- test/patterns/command/MacroCommand_test.go | 16 +- .../command/SimpleCommandTestCommand.go | 8 +- test/patterns/command/SimpleCommandTestVO.go | 2 +- test/patterns/command/SimpleCommand_test.go | 18 +- test/patterns/facade/FacadeTestCommand.go | 8 +- test/patterns/facade/FacadeTestVO.go | 2 +- test/patterns/facade/Facade_test.go | 128 +++++---- test/patterns/proxy/Proxy_test.go | 24 +- 49 files changed, 688 insertions(+), 681 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5922f2e --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +.idea/ +.DS_Store \ No newline at end of file diff --git a/VERSION b/VERSION index 0dd26f8..e839627 100644 --- a/VERSION +++ b/VERSION @@ -1,10 +1,12 @@ PureMVC Standard Framework for Go -------------------------------------------------------------------------- -Release Date: 04/25/19 +Release Date: 12/12/23 Platform: Go Version: 1 - Revision: 0 + Revision: 1 Minor: 0 Author: Saad Shams -------------------------------------------------------------------------- 1.0 - Initial release. + +1.1 - Updated to use Go 1.21. Minor Updates. diff --git a/go.mod b/go.mod index 10bbe97..18542b2 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/puremvc/puremvc-go-standard-framework -go 1.12 +go 1.21 diff --git a/src/core/controller/Controller.go b/src/core/controller/Controller.go index b5f9d96..c6d3cff 100755 --- a/src/core/controller/Controller.go +++ b/src/core/controller/Controller.go @@ -16,7 +16,7 @@ import ( ) /* -A Singleton IController implementation. +Controller A Singleton IController implementation. In PureMVC, the Controller class follows the 'Command and Controller' strategy, and assumes these @@ -47,37 +47,37 @@ var instance interfaces.IController // The Singleton Controller instanceMap. var instanceMutex sync.RWMutex // instanceMap Mutex /* - Controller Singleton Factory method. +GetInstance Controller Singleton Factory method. - - parameter controllerFunc: reference that returns IController +- parameter factory: reference that returns IController - - returns: the Singleton instance +- returns: the Singleton instance */ -func GetInstance(controllerFunc func() interfaces.IController) interfaces.IController { +func GetInstance(factory func() interfaces.IController) interfaces.IController { instanceMutex.Lock() defer instanceMutex.Unlock() if instance == nil { - instance = controllerFunc() + instance = factory() instance.InitializeController() } return instance } /* - Initialize the Singleton Controller instance. +InitializeController Initialize the Singleton Controller instance. - Called automatically by the GetInstance. +Called automatically by the GetInstance. - Note that if you are using a subclass of View - in your application, you should also subclass Controller - and override the InitializeController method in the - following way: +Note that if you are using a subclass of View +in your application, you should also subclass Controller +and override the InitializeController method in the +following way: - func (self *MyController) InitializeController() { - self.commandMap = map[string]func() interfaces.ICommand{} - self.view = MyView.GetInstance(func() interfaces.IView { return &MyView{} }) - } + func (self *MyController) InitializeController() { + self.commandMap = map[string]func() interfaces.ICommand{} + self.view = MyView.GetInstance(func() interfaces.IView { return &MyView{} }) + } */ func (self *Controller) InitializeController() { self.commandMap = map[string]func() interfaces.ICommand{} @@ -85,55 +85,55 @@ func (self *Controller) InitializeController() { } /* - If an ICommand has previously been registered - to handle a the given INotification, then it is executed. +ExecuteCommand If an ICommand has previously been registered +to handle the given INotification, then it is executed. - - parameter note: an INotification +- parameter note: an INotification */ func (self *Controller) ExecuteCommand(notification interfaces.INotification) { self.commandMapMutex.RLock() defer self.commandMapMutex.RUnlock() - var commandFunc = self.commandMap[notification.Name()] - if commandFunc == nil { + var factory = self.commandMap[notification.Name()] + if factory == nil { return } - commandInstance := commandFunc() + commandInstance := factory() commandInstance.InitializeNotifier() commandInstance.Execute(notification) } /* - Register a particular ICommand class as the handler - for a particular INotification. +RegisterCommand Register a particular ICommand class as the handler +for a particular INotification. - If an ICommand has already been registered to - handle INotifications with this name, it is no longer - used, the new ICommand is used instead. +If an ICommand has already been registered to +handle INotifications with this name, it is no longer +used, the new ICommand is used instead. - The Observer for the new ICommand is only created if this the - first time an ICommand has been regisered for this Notification name. +The Observer for the new ICommand is only created if this the +first time an ICommand has been regisered for this Notification name. - - parameter notificationName: the name of the INotification +- parameter notificationName: the name of the INotification - - parameter commandFunc: reference that returns ICommand +- parameter factory: reference that returns ICommand */ -func (self *Controller) RegisterCommand(notificationName string, commandFunc func() interfaces.ICommand) { +func (self *Controller) RegisterCommand(notificationName string, factory func() interfaces.ICommand) { self.commandMapMutex.Lock() defer self.commandMapMutex.Unlock() if self.commandMap[notificationName] == nil { self.view.RegisterObserver(notificationName, &observer.Observer{Notify: self.ExecuteCommand, Context: self}) } - self.commandMap[notificationName] = commandFunc + self.commandMap[notificationName] = factory } /* - Check if a Command is registered for a given Notification +HasCommand Check if a Command is registered for a given Notification - - parameter notificationName: +- parameter notificationName: - - returns: whether a Command is currently registered for the given notificationName. +- returns: whether a Command is currently registered for the given notificationName. */ func (self *Controller) HasCommand(notificationName string) bool { self.commandMapMutex.RLock() @@ -143,9 +143,9 @@ func (self *Controller) HasCommand(notificationName string) bool { } /* - Remove a previously registered ICommand to INotification mapping. +RemoveCommand Remove a previously registered ICommand to INotification mapping. - - parameter notificationName: the name of the INotification to remove the ICommand mapping for +- parameter notificationName: the name of the INotification to remove the ICommand mapping for */ func (self *Controller) RemoveCommand(notificationName string) { self.commandMapMutex.Lock() diff --git a/src/core/model/Model.go b/src/core/model/Model.go index d3896a3..e7010b9 100755 --- a/src/core/model/Model.go +++ b/src/core/model/Model.go @@ -14,7 +14,7 @@ import ( ) /* -A Singleton IModel implementation. +Model A Singleton IModel implementation. In PureMVC, the Model class provides access to model objects (Proxies) by named lookup. @@ -40,39 +40,39 @@ var instance interfaces.IModel // The Singleton Model instance. var instanceMutex sync.RWMutex // instanceMutex for thread safety /* - Model Singleton Factory method. +GetInstance Model Singleton Factory method. - - parameter modelFunc: reference that returns IModel +- parameter factory: reference that returns IModel - - returns: the instance returned by the passed modelFunc +- returns: the instance returned by the passed modelFunc */ -func GetInstance(modelFunc func() interfaces.IModel) interfaces.IModel { +func GetInstance(factory func() interfaces.IModel) interfaces.IModel { instanceMutex.Lock() defer instanceMutex.Unlock() if instance == nil { - instance = modelFunc() + instance = factory() instance.InitializeModel() } return instance } /* - Initialize the Model instance. +InitializeModel Initialize the Model instance. - Called automatically by the GetInstance, this - is your opportunity to initialize the Singleton - instance in your subclass without overriding the - constructor. +Called automatically by the GetInstance, this +is your opportunity to initialize the Singleton +instance in your subclass without overriding the +constructor. */ func (self *Model) InitializeModel() { self.proxyMap = map[string]interfaces.IProxy{} } /* - Register an IProxy with the Model. +RegisterProxy Register an IProxy with the Model. - - parameter proxy: an IProxy to be held by the Model. +- parameter proxy: an IProxy to be held by the Model. */ func (self *Model) RegisterProxy(proxy interfaces.IProxy) { self.proxyMapMutex.Lock() @@ -84,25 +84,25 @@ func (self *Model) RegisterProxy(proxy interfaces.IProxy) { } /* - Retrieve an IProxy from the Model. +RetrieveProxy Retrieve an IProxy from the Model. - - parameter proxyName: +- parameter proxyName: - - returns: the IProxy instance previously registered with the given proxyName. +- returns: the IProxy instance previously registered with the given proxyName. */ func (self *Model) RetrieveProxy(proxyName string) interfaces.IProxy { - self.proxyMapMutex.RLock(); + self.proxyMapMutex.RLock() defer self.proxyMapMutex.RUnlock() return self.proxyMap[proxyName] } /* - Remove an IProxy from the Model. +RemoveProxy Remove an IProxy from the Model. - - parameter proxyName: name of the IProxy instance to be removed. +- parameter proxyName: name of the IProxy instance to be removed. - - returns: the IProxy that was removed from the Model +- returns: the IProxy that was removed from the Model */ func (self *Model) RemoveProxy(proxyName string) interfaces.IProxy { self.proxyMapMutex.Lock() @@ -117,11 +117,11 @@ func (self *Model) RemoveProxy(proxyName string) interfaces.IProxy { } /* - Check if a Proxy is registered +HasProxy Check if a Proxy is registered - - parameter proxyName: +- parameter proxyName: - - returns: whether a Proxy is currently registered with the given proxyName. +- returns: whether a Proxy is currently registered with the given proxyName. */ func (self *Model) HasProxy(proxyName string) bool { self.proxyMapMutex.RLock() diff --git a/src/core/view/View.go b/src/core/view/View.go index 277a455..c7b56ef 100755 --- a/src/core/view/View.go +++ b/src/core/view/View.go @@ -14,15 +14,15 @@ import ( "sync" ) -/** -A Singleton IView implementation. +/* +View A Singleton IView implementation. In PureMVC, the View class assumes these responsibilities: * Maintain a cache of IMediator instances. * Provide methods for registering, retrieving, and removing IMediators. -* Notifiying IMediators when they are registered or removed. +* Notifying IMediators when they are registered or removed. * Managing the observer lists for each INotification in the application. @@ -43,30 +43,30 @@ var instance interfaces.IView // The Singleton View instance. var instanceMutex = sync.RWMutex{} // instanceMutex /* - View Singleton Factory method. +GetInstance View Singleton Factory method. - - parameter viewFunc: reference that returns IView +- parameter factory: reference that returns IView - - returns: the Singleton instance returned by executing the passed viewFunc +- returns: the Singleton instance returned by executing the passed viewFunc */ -func GetInstance(viewFunc func() interfaces.IView) interfaces.IView { +func GetInstance(factory func() interfaces.IView) interfaces.IView { instanceMutex.Lock() defer instanceMutex.Unlock() if instance == nil { - instance = viewFunc() + instance = factory() instance.InitializeView() } return instance } /* - Initialize the Singleton View instance. +InitializeView Initialize the Singleton View instance. - Called automatically by the GetInstance, this - is your opportunity to initialize the Singleton - instance in your subclass without overriding the - constructor. +Called automatically by the GetInstance, this +is your opportunity to initialize the Singleton +instance in your subclass without overriding the +constructor. */ func (self *View) InitializeView() { self.mediatorMap = map[string]interfaces.IMediator{} @@ -74,12 +74,12 @@ func (self *View) InitializeView() { } /* - Register an IObserver to be notified - of INotifications with a given name. +RegisterObserver Register an IObserver to be notified +of INotifications with a given name. - - parameter notificationName: the name of the INotifications to notify this IObserver of +- parameter notificationName: the name of the INotifications to notify this IObserver of - - parameter observer: the IObserver to register +- parameter observer: the IObserver to register */ func (self *View) RegisterObserver(notificationName string, observer interfaces.IObserver) { self.observerMapMutex.Lock() @@ -93,13 +93,13 @@ func (self *View) RegisterObserver(notificationName string, observer interfaces. } /* - Notify the IObservers for a particular INotification. +NotifyObservers Notify the IObservers for a particular INotification. - All previously attached IObservers for this INotification's - list are notified and are passed a reference to the INotification in - the order in which they were registered. +All previously attached IObservers for this INotification's +list are notified and are passed a reference to the INotification in +the order in which they were registered. - - parameter notification: the INotification to notify IObservers of. +- parameter notification: the INotification to notify IObservers of. */ func (self *View) NotifyObservers(notification interfaces.INotification) { self.observerMapMutex.RLock() @@ -124,11 +124,11 @@ func (self *View) NotifyObservers(notification interfaces.INotification) { } /* - Remove the observer for a given notifyContext from an observer list for a given Notification name. +RemoveObserver Remove the observer for a given notifyContext from an observer list for a given Notification name. - - parameter notificationName: which observer list to remove from +- parameter notificationName: which observer list to remove from - - parameter notifyContext: remove the observer with this object as its notifyContext +- parameter notifyContext: remove the observer with this object as its notifyContext */ func (self *View) RemoveObserver(notificationName string, notifyContext interface{}) { self.observerMapMutex.Lock() @@ -155,19 +155,19 @@ func (self *View) RemoveObserver(notificationName string, notifyContext interfac } /* - Register an IMediator instance with the View. +RegisterMediator Register an IMediator instance with the View. - Registers the IMediator so that it can be retrieved by name, - and further interrogates the IMediator for its - INotification interests. +Registers the IMediator so that it can be retrieved by name, +and further interrogates the IMediator for its +INotification interests. - If the IMediator returns any INotification - names to be notified about, an Observer is created encapsulating - the IMediator instance's handleNotification method - and registering it as an Observer for all INotifications the - IMediator is interested in. +If the IMediator returns any INotification +names to be notified about, an Observer is created encapsulating +the IMediator instance's handleNotification method +and registering it as an Observer for all INotifications the +IMediator is interested in. - - parameter mediator: a reference to the IMediator instance +- parameter mediator: a reference to the IMediator instance */ func (self *View) RegisterMediator(mediator interfaces.IMediator) { self.mediatorMapMutex.Lock() @@ -202,11 +202,11 @@ func (self *View) RegisterMediator(mediator interfaces.IMediator) { } /* - Retrieve an IMediator from the View. +RetrieveMediator Retrieve an IMediator from the View. - - parameter mediatorName: the name of the IMediator instance to retrieve. +- parameter mediatorName: the name of the IMediator instance to retrieve. - - returns: the IMediator instance previously registered with the given mediatorName. +- returns: the IMediator instance previously registered with the given mediatorName. */ func (self *View) RetrieveMediator(mediatorName string) interfaces.IMediator { self.mediatorMapMutex.RLock() @@ -216,11 +216,11 @@ func (self *View) RetrieveMediator(mediatorName string) interfaces.IMediator { } /* - Remove an IMediator from the View. +RemoveMediator Remove an IMediator from the View. - - parameter mediatorName: name of the IMediator instance to be removed. +- parameter mediatorName: name of the IMediator instance to be removed. - - returns: the IMediator that was removed from the View +- returns: the IMediator that was removed from the View */ func (self *View) RemoveMediator(mediatorName string) interfaces.IMediator { self.mediatorMapMutex.Lock() @@ -249,11 +249,11 @@ func (self *View) RemoveMediator(mediatorName string) interfaces.IMediator { } /* - Check if a Mediator is registered or not +HasMediator Check if a Mediator is registered or not - - parameter mediatorName: +- parameter mediatorName: - - returns: whether a Mediator is registered with the given mediatorName. +- returns: whether a Mediator is registered with the given mediatorName. */ func (self *View) HasMediator(mediatorName string) bool { self.mediatorMapMutex.RLock() diff --git a/src/interfaces/ICommand.go b/src/interfaces/ICommand.go index b46ae1d..b340d6b 100755 --- a/src/interfaces/ICommand.go +++ b/src/interfaces/ICommand.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Command. +ICommand The interface definition for a PureMVC Command. */ type ICommand interface { INotifier diff --git a/src/interfaces/IController.go b/src/interfaces/IController.go index 579913f..1f2682c 100755 --- a/src/interfaces/IController.go +++ b/src/interfaces/IController.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Controller. +IController The interface definition for a PureMVC Controller. In PureMVC, an IController implementor follows the 'Command and Controller' strategy, and @@ -34,9 +34,9 @@ type IController interface { for a particular INotification. - parameter notificationName: the name of the INotification - - parameter commandFunc: reference that returns ICommand + - parameter factory: reference that returns ICommand */ - RegisterCommand(notificationName string, commandFunc func() ICommand) + RegisterCommand(notificationName string, factory func() ICommand) /* Execute the ICommand previously registered as the diff --git a/src/interfaces/IFacade.go b/src/interfaces/IFacade.go index d34376e..612b7e5 100755 --- a/src/interfaces/IFacade.go +++ b/src/interfaces/IFacade.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Facade. +IFacade The interface definition for a PureMVC Facade. The Facade Pattern suggests providing a single class to act as a central point of communication @@ -37,12 +37,12 @@ type IFacade interface { InitializeController() /* - Initialize the Model. + Initialize the Model. */ InitializeModel() /* - Initialize the View. + Initialize the View. */ InitializeView() @@ -50,9 +50,9 @@ type IFacade interface { Register an ICommand with the Controller. - parameter noteName: the name of the INotification to associate the ICommand with. - - parameter commandFunc: reference that returns ICommand + - parameter factory: reference that returns ICommand */ - RegisterCommand(notificationName string, commandFunc func() ICommand) + RegisterCommand(notificationName string, factory func() ICommand) /* Remove a previously registered ICommand to INotification mapping from the Controller. diff --git a/src/interfaces/IMediator.go b/src/interfaces/IMediator.go index cac4434..ad178bd 100755 --- a/src/interfaces/IMediator.go +++ b/src/interfaces/IMediator.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Mediator. +IMediator The interface definition for a PureMVC Mediator. In PureMVC, IMediator implementors assume these responsibilities: @@ -43,17 +43,17 @@ type IMediator interface { /* Get the IMediator instance name - */ + */ GetMediatorName() string /* Get the IMediator's view component. - */ + */ GetViewComponent() interface{} /* Set the IMediator's view component. - */ + */ SetViewComponent(viewComponent interface{}) /* diff --git a/src/interfaces/IModel.go b/src/interfaces/IModel.go index a7114eb..b65f013 100755 --- a/src/interfaces/IModel.go +++ b/src/interfaces/IModel.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Model. +IModel The interface definition for a PureMVC Model. In PureMVC, IModel implementors provide access to IProxy objects by named lookup. diff --git a/src/interfaces/INotification.go b/src/interfaces/INotification.go index 8ecb628..45bbe83 100755 --- a/src/interfaces/INotification.go +++ b/src/interfaces/INotification.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Notification. +INotification The interface definition for a PureMVC Notification. PureMVC does not rely upon underlying event models such as the one provided with Flash, and ActionScript 3 does diff --git a/src/interfaces/INotifier.go b/src/interfaces/INotifier.go index 36e739e..8e1e245 100755 --- a/src/interfaces/INotifier.go +++ b/src/interfaces/INotifier.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Notifier. +INotifier The interface definition for a PureMVC Notifier. MacroCommand, Command, Mediator and Proxy all have a need to send Notifications. diff --git a/src/interfaces/IObserver.go b/src/interfaces/IObserver.go index 4639f9e..af1ccba 100755 --- a/src/interfaces/IObserver.go +++ b/src/interfaces/IObserver.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Observer. +IObserver The interface definition for a PureMVC Observer. In PureMVC, IObserver implementors assume these responsibilities: diff --git a/src/interfaces/IProxy.go b/src/interfaces/IProxy.go index a883b8a..263f1b5 100755 --- a/src/interfaces/IProxy.go +++ b/src/interfaces/IProxy.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC Proxy. +IProxy The interface definition for a PureMVC Proxy. In PureMVC, IProxy implementors assume these responsibilities: @@ -43,7 +43,7 @@ type IProxy interface { SetData(data interface{}) /* - Get the data object + Get the data object */ GetData() interface{} diff --git a/src/interfaces/IView.go b/src/interfaces/IView.go index 2fe303b..4a63394 100755 --- a/src/interfaces/IView.go +++ b/src/interfaces/IView.go @@ -9,7 +9,7 @@ package interfaces /* -The interface definition for a PureMVC View. +IView The interface definition for a PureMVC View. In PureMVC, IView implementors assume these responsibilities: diff --git a/src/patterns/command/MacroCommand.go b/src/patterns/command/MacroCommand.go index 062b7e7..2bce831 100755 --- a/src/patterns/command/MacroCommand.go +++ b/src/patterns/command/MacroCommand.go @@ -14,9 +14,9 @@ import ( ) /* -A base ICommand implementation that executes other ICommands. +MacroCommand A base ICommand implementation that executes other ICommands. -A MacroCommand maintains an list of +A MacroCommand maintains a list of ICommand Class references called SubCommands. When execute is called, the MacroCommand @@ -38,54 +38,54 @@ type MacroCommand struct { } /* - Initialize the MacroCommand. - - In your subclass, override this method to - initialize the MacroCommand's *SubCommand* - list with func references like - this: - - // Initialize MyMacroCommand - func (self *MacroCommandTestCommand) InitializeMacroCommand() { - self.AddSubCommand(func() interfaces.ICommand { return &FirstCommand{} }) - self.AddSubCommand(func() interfaces.ICommand { return &SecondCommand{} }) - self.AddSubCommand(func() interfaces.ICommand { return &ThirdCommand{} }) - } - - Note that SubCommands may be any func returning ICommand - implementor, MacroCommands or SimpleCommands are both acceptable. +InitializeMacroCommand Initialize the MacroCommand. + +In your subclass, override this method to +initialize the MacroCommand's *SubCommand* +list with func references like +this: + + // Initialize MyMacroCommand + func (self *MacroCommandTestCommand) InitializeMacroCommand() { + self.AddSubCommand(func() interfaces.ICommand { return &FirstCommand{} }) + self.AddSubCommand(func() interfaces.ICommand { return &SecondCommand{} }) + self.AddSubCommand(func() interfaces.ICommand { return &ThirdCommand{} }) + } + +Note that SubCommands may be any func returning ICommand +implementor, MacroCommands or SimpleCommands are both acceptable. */ func (self *MacroCommand) InitializeMacroCommand() { } /* - Add a SubCommand. +AddSubCommand Add a SubCommand. - The SubCommands will be called in First In/First Out (FIFO) - order. +The SubCommands will be called in First In/First Out (FIFO) +order. - - parameter func: reference that returns ICommand. +- parameter factory: reference that returns ICommand. */ -func (self *MacroCommand) AddSubCommand(commandFunc func() interfaces.ICommand) { - self.SubCommands = append(self.SubCommands, commandFunc) +func (self *MacroCommand) AddSubCommand(factory func() interfaces.ICommand) { + self.SubCommands = append(self.SubCommands, factory) } /* - Execute this MacroCommand's SubCommands. +Execute this MacroCommand's SubCommands. - The SubCommands will be called in First In/First Out (FIFO) - order. +The SubCommands will be called in First In/First Out (FIFO) +order. - - parameter notification: the INotification object to be passsed to each SubCommand. +- parameter notification: the INotification object to be passsed to each SubCommand. */ func (self *MacroCommand) Execute(notification interfaces.INotification) { self.InitializeMacroCommand() for len(self.SubCommands) > 0 { - commandClassRef := self.SubCommands[0] + factory := self.SubCommands[0] self.SubCommands = self.SubCommands[1:] - commandInstance := commandClassRef() + commandInstance := factory() commandInstance.InitializeNotifier() commandInstance.Execute(notification) } diff --git a/src/patterns/command/SimpleCommand.go b/src/patterns/command/SimpleCommand.go index 3c95acb..a5700f4 100755 --- a/src/patterns/command/SimpleCommand.go +++ b/src/patterns/command/SimpleCommand.go @@ -14,7 +14,7 @@ import ( ) /* -A base ICommand implementation. +SimpleCommand A base ICommand implementation. Your subclass should override the execute method where your business logic will handle the INotification. @@ -24,14 +24,14 @@ type SimpleCommand struct { } /* - Fulfill the use-case initiated by the given INotification. +Execute Fulfill the use-case initiated by the given INotification. - In the Command Pattern, an application use-case typically - begins with some user action, which results in an INotification being broadcast, which - is handled by business logic in the execute method of an - ICommand. +In the Command Pattern, an application use-case typically +begins with some user action, which results in an INotification being broadcast, which +is handled by business logic in the execute method of an +ICommand. - - parameter notification: the INotification to handle. +- parameter notification: the INotification to handle. */ func (self *SimpleCommand) Execute(notification interfaces.INotification) { diff --git a/src/patterns/facade/Facade.go b/src/patterns/facade/Facade.go index f72b18a..e61047b 100755 --- a/src/patterns/facade/Facade.go +++ b/src/patterns/facade/Facade.go @@ -18,6 +18,7 @@ import ( ) /* +Facade represents a base implementation of the Singleton pattern for IFacade. A base Singleton IFacade implementation. */ type Facade struct { @@ -30,29 +31,31 @@ var instance interfaces.IFacade // The Singleton Facade instance. var instanceMutex = sync.RWMutex{} // instanceMutex for the instance /* - Facade Singleton Factory method +GetInstance is a Facade Singleton factory method. - - parameter facadeFunc: reference that returns IFacade +# Facade Singleton Factory method - - returns: the Singleton instance of the IFacade +- parameter factory: reference that returns IFacade + +- returns: the Singleton instance of the IFacade */ -func GetInstance(facadeFunc func() interfaces.IFacade) interfaces.IFacade { +func GetInstance(factory func() interfaces.IFacade) interfaces.IFacade { instanceMutex.Lock() defer instanceMutex.Unlock() if instance == nil { - instance = facadeFunc() + instance = factory() instance.InitializeFacade() } return instance } /* - Initialize the Singleton Facade instance. +InitializeFacade Initialize the Singleton Facade instance. - Called automatically by the GetInstance. Override in your - subclass to do any subclass specific initializations. Be - sure to call self.Facade.initializeFacade(), though. +Called automatically by the GetInstance. Override in your +subclass to do any subclass specific initializations. Be +sure to call self.Facade.initializeFacade(), though. */ func (self *Facade) InitializeFacade() { self.InitializeModel() @@ -61,228 +64,228 @@ func (self *Facade) InitializeFacade() { } /* - Initialize the Controller. +InitializeController Initialize the Controller. - Called by the initializeFacade method. - Override this method in your subclass of Facade - if one or both of the following are true: +Called by the initializeFacade method. +Override this method in your subclass of Facade +if one or both of the following are true: - * You wish to initialize a different IController. +* You wish to initialize a different IController. - * You have Commands to register with the Controller at startup. +* You have Commands to register with the Controller at startup. - If you don't want to initialize a different IController, - call self.Facade.initializeController() at the beginning of your - method, then register Commands. +If you don't want to initialize a different IController, +call self.Facade.initializeController() at the beginning of your +method, then register Commands. */ func (self *Facade) InitializeController() { self.controller = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) } /* - Initialize the Model. +InitializeModel Initialize the Model. - Called by the initializeFacade method. - Override this method in your subclass of Facade - if one or both of the following are true: +Called by the initializeFacade method. +Override this method in your subclass of Facade +if one or both of the following are true: - * You wish to initialize a different IModel. +* You wish to initialize a different IModel. - * You have Proxys to register with the Model that do not retrieve a reference to the Facade at construction time. +* You have Proxys to register with the Model that do not retrieve a reference to the Facade at construction time. - If you don't want to initialize a different IModel, - call self.Facade.initializeModel() at the beginning of your - method, then register Proxys. +If you don't want to initialize a different IModel, +call self.Facade.initializeModel() at the beginning of your +method, then register Proxys. - Note: This method is rarely overridden; in practice you are more - likely to use a Command to create and register Proxys - with the Model, since Proxys with mutable data will likely - need to send INotifications and thus will likely want to fetch a reference to - the Facade during their construction. +Note: This method is rarely overridden; in practice you are more +likely to use a Command to create and register Proxys +with the Model, since Proxys with mutable data will likely +need to send INotifications and thus will likely want to fetch a reference to +the Facade during their construction. */ func (self *Facade) InitializeModel() { self.model = model.GetInstance(func() interfaces.IModel { return &model.Model{} }) } /* - Initialize the View. +InitializeView Initialize the View. - Called by the initializeFacade method. - Override this method in your subclass of Facade - if one or both of the following are true: +Called by the initializeFacade method. +Override this method in your subclass of Facade +if one or both of the following are true: - * You wish to initialize a different IView. +* You wish to initialize a different IView. - * You have Observers to register with the View +* You have Observers to register with the View - If you don't want to initialize a different IView, - call self.Facade.initializeView() at the beginning of your - method, then register IMediator instances. +If you don't want to initialize a different IView, +call self.Facade.initializeView() at the beginning of your +method, then register IMediator instances. - Note: This method is rarely overridden; in practice you are more - likely to use a Command to create and register Mediators - with the View, since IMediator instances will need to send - INotifications and thus will likely want to fetch a reference - to the Facade during their construction. +Note: This method is rarely overridden; in practice you are more +likely to use a Command to create and register Mediators +with the View, since IMediator instances will need to send +INotifications and thus will likely want to fetch a reference +to the Facade during their construction. */ func (self *Facade) InitializeView() { self.view = view.GetInstance(func() interfaces.IView { return &view.View{} }) } /* - Register an ICommand with the Controller by Notification name. +RegisterCommand Register an ICommand with the Controller by Notification name. - - parameter notificationName: the name of the INotification to associate the ICommand with +- parameter notificationName: the name of the INotification to associate the ICommand with - - parameter commandFunc: reference that returns ICommand +- parameter factory: reference that returns ICommand */ -func (self *Facade) RegisterCommand(notificationName string, commandFunc func() interfaces.ICommand) { - self.controller.RegisterCommand(notificationName, commandFunc) +func (self *Facade) RegisterCommand(notificationName string, factory func() interfaces.ICommand) { + self.controller.RegisterCommand(notificationName, factory) } /* - Remove a previously registered ICommand to INotification mapping from the Controller. +RemoveCommand Remove a previously registered ICommand to INotification mapping from the Controller. - - parameter notificationName: the name of the INotification to remove the ICommand mapping for +- parameter notificationName: the name of the INotification to remove the ICommand mapping for */ func (self *Facade) RemoveCommand(notificationName string) { self.controller.RemoveCommand(notificationName) } /* - Check if a Command is registered for a given Notification +HasCommand Check if a Command is registered for a given Notification - - parameter notificationName: +- parameter notificationName: - - returns: whether a Command is currently registered for the given notificationName. +- returns: whether a Command is currently registered for the given notificationName. */ func (self *Facade) HasCommand(notificationName string) bool { return self.controller.HasCommand(notificationName) } /* - Register an IProxy with the Model by name. +RegisterProxy Register an IProxy with the Model by name. - - parameter proxy: the IProxy instance to be registered with the Model. +- parameter proxy: the IProxy instance to be registered with the Model. */ func (self *Facade) RegisterProxy(proxy interfaces.IProxy) { self.model.RegisterProxy(proxy) } /* - Retrieve an IProxy from the Model by name. +RetrieveProxy Retrieve an IProxy from the Model by name. - - parameter proxyName: the name of the proxy to be retrieved. +- parameter proxyName: the name of the proxy to be retrieved. - - returns: the IProxy instance previously registered with the given proxyName. +- returns: the IProxy instance previously registered with the given proxyName. */ func (self *Facade) RetrieveProxy(proxyName string) interfaces.IProxy { return self.model.RetrieveProxy(proxyName) } /* - Remove an IProxy from the Model by name. +RemoveProxy Remove an IProxy from the Model by name. - - parameter proxyName: the IProxy to remove from the Model. +- parameter proxyName: the IProxy to remove from the Model. - - returns: the IProxy that was removed from the Model +- returns: the IProxy that was removed from the Model */ func (self *Facade) RemoveProxy(proxyName string) interfaces.IProxy { return self.model.RemoveProxy(proxyName) } /* - Check if a Proxy is registered +HasProxy Check if a Proxy is registered - - parameter proxyName: +- parameter proxyName: - - returns: whether a Proxy is currently registered with the given proxyName. +- returns: whether a Proxy is currently registered with the given proxyName. */ func (self *Facade) HasProxy(proxyName string) bool { return self.model.HasProxy(proxyName) } /* - Register a IMediator with the View. +RegisterMediator Register a IMediator with the View. - - parameter mediator: a reference to the IMediator +- parameter mediator: a reference to the IMediator */ func (self *Facade) RegisterMediator(mediator interfaces.IMediator) { self.view.RegisterMediator(mediator) } /* - Retrieve an IMediator from the View. +RetrieveMediator Retrieve an IMediator from the View. - - parameter mediatorName: +- parameter mediatorName: - - returns: the IMediator previously registered with the given mediatorName. +- returns: the IMediator previously registered with the given mediatorName. */ func (self *Facade) RetrieveMediator(mediatorName string) interfaces.IMediator { return self.view.RetrieveMediator(mediatorName) } /* - Remove an IMediator from the View. +RemoveMediator Remove an IMediator from the View. - - parameter mediatorName: name of the IMediator to be removed. +- parameter mediatorName: name of the IMediator to be removed. - - returns: the IMediator that was removed from the View +- returns: the IMediator that was removed from the View */ func (self *Facade) RemoveMediator(mediatorName string) interfaces.IMediator { return self.view.RemoveMediator(mediatorName) } /* - Check if a Mediator is registered or not +HasMediator Check if a Mediator is registered or not - - parameter mediatorName: +- parameter mediatorName: - - returns: whether a Mediator is registered with the given mediatorName. +- returns: whether a Mediator is registered with the given mediatorName. */ func (self *Facade) HasMediator(mediatorName string) bool { return self.view.HasMediator(mediatorName) } /* - Create and send an INotification. +SendNotification Create and send an INotification. - Keeps us from having to construct new notification - instances in our implementation code. +Keeps us from having to construct new notification +instances in our implementation code. - - parameter notificationName: the name of the notiification to send +- parameter notificationName: the name of the notiification to send - - parameter body: the body of the notification (optional) +- parameter body: the body of the notification (optional) - - parameter _type: the type of the notification +- parameter _type: the type of the notification */ func (self *Facade) SendNotification(notificationName string, body interface{}, _type string) { self.NotifyObservers(observer.NewNotification(notificationName, body, _type)) } /* - Notify Observers. +NotifyObservers Notify Observers. - This method is left mostly for backward - compatibility, and to allow you to send custom - notification classes using the facade. +This method is left mostly for backward +compatibility, and to allow you to send custom +notification classes using the facade. - Usually you should just call sendNotification - and pass the parameters, never having to - construct the notification yourself. +Usually you should just call sendNotification +and pass the parameters, never having to +construct the notification yourself. - - parameter notification: the INotification to have the View notify Observers of. +- parameter notification: the INotification to have the View notify Observers of. */ func (self *Facade) NotifyObservers(notification interfaces.INotification) { self.view.NotifyObservers(notification) } /* - Set the Singleton key for this facade instance. +InitializeNotifier Set the Singleton key for this facade instance. - Not called directly, but instead from the - GetInstance when it is is invoked. +Not called directly, but instead from the +GetInstance when it is invoked. */ func (self *Facade) InitializeNotifier() { -} \ No newline at end of file +} diff --git a/src/patterns/facade/Notifier.go b/src/patterns/facade/Notifier.go index c480bc5..f9271d5 100755 --- a/src/patterns/facade/Notifier.go +++ b/src/patterns/facade/Notifier.go @@ -11,7 +11,7 @@ package facade import "github.com/puremvc/puremvc-go-standard-framework/src/interfaces" /* -A Base INotifier implementation. +Notifier A Base INotifier implementation. MacroCommand, Command, Mediator and Proxy all have a need to send Notifications. @@ -22,7 +22,7 @@ the necessity to actually construct Notifications. The Notifier class, which all of the above mentioned classes extend, provides an initialized reference to the Facade -Singleton, which is required for the convienience method +Singleton, which is required for the convenience method for sending Notifications, but also eases implementation as these classes have frequent Facade interactions and usually require access to the facade anyway. @@ -32,35 +32,35 @@ type Notifier struct { } /* - Create and send an INotification. +SendNotification Create and send an INotification. - Keeps us from having to construct new INotification - instances in our implementation code. + Keeps us from having to construct new INotification + instances in our implementation code. - - parameter notificationName: the name of the notification to send + - parameter notificationName: the name of the notification to send - - parameter body: the body of the notification (optional) + - parameter body: the body of the notification (optional) - - parameter type: the _type of the notification + - parameter type: the _type of the notification */ func (self *Notifier) SendNotification(notificationName string, body interface{}, _type string) { self.Facade.SendNotification(notificationName, body, _type) } /* - Initialize this INotifier instance. +InitializeNotifier Initialize this INotifier instance. - This is how a Notifier get to Calls to - sendNotification or to access the - facade will fail until after this method - has been called. +This is how a Notifier get to Calls to +sendNotification or to access the +facade will fail until after this method +has been called. - Mediators, Commands or Proxies may override - this method in order to send notifications - or access the Facade instance as - soon as possible. They CANNOT access the facade - in their constructors, since this method will not - yet have been called. +Mediators, Commands or Proxies may override +this method in order to send notifications +or access the Facade instance as +soon as possible. They CANNOT access the facade +in their constructors, since this method will not +yet have been called. */ func (self *Notifier) InitializeNotifier() { self.Facade = GetInstance(func() interfaces.IFacade { return &Facade{} }) diff --git a/src/patterns/mediator/Mediator.go b/src/patterns/mediator/Mediator.go index 89a3098..2fd8190 100755 --- a/src/patterns/mediator/Mediator.go +++ b/src/patterns/mediator/Mediator.go @@ -16,7 +16,7 @@ import ( const NAME = "Mediator" // default name for the mediator /* -A base IMediator implementation. +Mediator A base IMediator implementation. */ type Mediator struct { facade.Notifier @@ -25,56 +25,56 @@ type Mediator struct { } /* - Get the name of the Mediator. - */ +GetMediatorName Get the name of the Mediator. +*/ func (self *Mediator) GetMediatorName() string { return self.Name } /* - Get the IMediator's view component. - */ +GetViewComponent Get the IMediator's view component. +*/ func (self *Mediator) GetViewComponent() interface{} { return self.ViewComponent } /* - Set the IMediator's view component. - */ +SetViewComponent Set the IMediator's view component. +*/ func (self *Mediator) SetViewComponent(viewComponent interface{}) { self.ViewComponent = viewComponent } /* - List the INotification names this - Mediator is interested in being notified of. +ListNotificationInterests List the INotification names this +Mediator is interested in being notified of. - - returns: Array the list of INotification names +- returns: Array the list of INotification names */ func (self *Mediator) ListNotificationInterests() []string { return []string{} } /* - Handle INotifications. +HandleNotification Handle INotifications. - Typically this will be handled in a switch statement, - with one 'case' entry per INotification - the Mediator is interested in. +Typically, this will be handled in a switch statement, +with one 'case' entry per INotification +the Mediator is interested in. */ func (self *Mediator) HandleNotification(notification interfaces.INotification) { } /* - Called by the View when the Mediator is registered +OnRegister Called by the View when the Mediator is registered */ func (self *Mediator) OnRegister() { } /* - Called by the View when the Mediator is removed +OnRemove Called by the View when the Mediator is removed */ func (self *Mediator) OnRemove() { diff --git a/src/patterns/observer/Notification.go b/src/patterns/observer/Notification.go index 36441fc..71f4ff3 100755 --- a/src/patterns/observer/Notification.go +++ b/src/patterns/observer/Notification.go @@ -9,7 +9,7 @@ package observer /* -A base INotification implementation. +Notification A base INotification implementation. PureMVC does not rely upon underlying event models such as the one provided with Flash, and ActionScript 3 does @@ -43,7 +43,7 @@ type Notification struct { } /* -Constructor. +NewNotification Constructor. - parameter name: name of the Notification instance. (required) @@ -56,44 +56,44 @@ func NewNotification(name string, body interface{}, _type string) *Notification } /* - Get the name of notification instance +Name Get the name of notification instance */ func (self *Notification) Name() string { return self.name } /* - Get the body of notification instance +Body Get the body of notification instance */ func (self *Notification) Body() interface{} { return self.body } /* - Set the body of notification instance +SetBody Set the body of notification instance */ func (self *Notification) SetBody(body interface{}) { self.body = body } /* - Get the type of notification instance +Type Get the type of notification instance */ func (self *Notification) Type() string { return self._type } /* - Set the type of notification instance +SetType Set the type of notification instance */ func (self *Notification) SetType(t string) { self._type = t } /* - Get the string representation of the Notification instance. +String Get the string representation of the Notification instance. - - returns: the string representation of the Notification instance. +- returns: the string representation of the Notification instance. */ func (self *Notification) String() string { msg := "Notification name: " + self.name diff --git a/src/patterns/observer/Observer.go b/src/patterns/observer/Observer.go index 0dc7847..f8524d1 100755 --- a/src/patterns/observer/Observer.go +++ b/src/patterns/observer/Observer.go @@ -11,7 +11,7 @@ package observer import "github.com/puremvc/puremvc-go-standard-framework/src/interfaces" /* -A base IObserver implementation. +Observer A base IObserver implementation. An Observer is an object that encapsulates information about an interested object with a method that should @@ -33,34 +33,34 @@ type Observer struct { } /* - Notify the interested object. +NotifyObserver Notify the interested object. - - parameter notification: the INotification to pass to the interested object's notification method. +- parameter notification: the INotification to pass to the interested object's notification method. */ func (self *Observer) NotifyObserver(notification interfaces.INotification) { self.Notify(notification) } /* - Compare an object to the notification context. +CompareNotifyContext Compare an object to the notification context. - - parameter object: the object to compare +- parameter object: the object to compare - - returns: boolean indicating if the object and the notification context are the same +- returns: boolean indicating if the object and the notification context are the same */ func (self *Observer) CompareNotifyContext(object interface{}) bool { return object == self.Context } /* - Set the notification method. +SetNotifyMethod Set the notification method. */ func (self *Observer) SetNotifyMethod(notifyMethod func(notification interfaces.INotification)) { self.Notify = notifyMethod } /* - Set the notification context. +SetNotifyContext Set the notification context. */ func (self *Observer) SetNotifyContext(notifyContext interface{}) { self.Context = notifyContext diff --git a/src/patterns/proxy/Proxy.go b/src/patterns/proxy/Proxy.go index 247e92b..5f75e05 100755 --- a/src/patterns/proxy/Proxy.go +++ b/src/patterns/proxy/Proxy.go @@ -13,7 +13,7 @@ import "github.com/puremvc/puremvc-go-standard-framework/src/patterns/facade" const NAME = "Proxy" // default name for the proxy /* -A base IProxy implementation. +Proxy A base IProxy implementation. In PureMVC, Proxy classes are used to manage parts of the application's data model. @@ -24,7 +24,7 @@ getting of its data in synchronous fashion. Proxy classes are also used to encapsulate the application's interaction with remote services to save or retrieve data, in which case, -we adopt an asyncronous idiom; setting data (or calling a method) on the +we adopt an asynchronous idiom; setting data (or calling a method) on the Proxy and listening for a Notification to be sent when the Proxy has retrieved the data from the service. */ @@ -35,35 +35,35 @@ type Proxy struct { } /* - Get the proxy name +GetProxyName Get the proxy name */ func (self *Proxy) GetProxyName() string { return self.Name } /* - Set the data object +SetData Set the data object */ func (self *Proxy) SetData(data interface{}) { self.Data = data } /* - Get the data object +GetData Get the data object */ func (self *Proxy) GetData() interface{} { return self.Data } /* - Called by the Model when the Proxy is registered +OnRegister Called by the Model when the Proxy is registered */ func (self *Proxy) OnRegister() { } /* - Called by the Model when the Proxy is removed +OnRemove Called by the Model when the Proxy is removed */ func (self *Proxy) OnRemove() { diff --git a/test/core/controller/ControllerTestCommand.go b/test/core/controller/ControllerTestCommand.go index d75349c..5022562 100755 --- a/test/core/controller/ControllerTestCommand.go +++ b/test/core/controller/ControllerTestCommand.go @@ -14,16 +14,16 @@ import ( ) /* - A SimpleCommand subclass used by ControllerTest. +ControllerTestCommand A SimpleCommand subclass used by ControllerTest. */ type ControllerTestCommand struct { command.SimpleCommand } /* - Fabricate a result by multiplying the input by 2 +Execute Fabricate a result by multiplying the input by 2 - - parameter note: the note carrying the ControllerTestVO +- parameter note: the note carrying the ControllerTestVO */ func (controller *ControllerTestCommand) Execute(notification interfaces.INotification) { var vo = notification.Body().(*ControllerTestVO) diff --git a/test/core/controller/ControllerTestCommand2.go b/test/core/controller/ControllerTestCommand2.go index 94430af..46a4dcd 100755 --- a/test/core/controller/ControllerTestCommand2.go +++ b/test/core/controller/ControllerTestCommand2.go @@ -14,18 +14,18 @@ import ( ) /* -A SimpleCommand subclass used by ControllerTest. +ControllerTestCommand2 A SimpleCommand subclass used by ControllerTest. */ type ControllerTestCommand2 struct { command.SimpleCommand } /* - Fabricate a result by multiplying the input by 2 and adding to the existing result +Execute Fabricate a result by multiplying the input by 2 and adding to the existing result - This tests accumulation effect that would show if the command were executed more than once. +This tests accumulation effect that would show if the command were executed more than once. - - parameter note: the note carrying the ControllerTestVO +- parameter note: the note carrying the ControllerTestVO */ func (controller *ControllerTestCommand2) Execute(notification interfaces.INotification) { var vo = notification.Body().(*ControllerTestVO) diff --git a/test/core/controller/ControllerTestVO.go b/test/core/controller/ControllerTestVO.go index 89a81c5..566c998 100755 --- a/test/core/controller/ControllerTestVO.go +++ b/test/core/controller/ControllerTestVO.go @@ -9,7 +9,7 @@ package controller /* -A utility class used by ControllerTest. +ControllerTestVO A utility class used by ControllerTest. */ type ControllerTestVO struct { Input int diff --git a/test/core/controller/Controller_test.go b/test/core/controller/Controller_test.go index ff42058..5a7eabe 100755 --- a/test/core/controller/Controller_test.go +++ b/test/core/controller/Controller_test.go @@ -21,33 +21,33 @@ Test the PureMVC Controller class. */ /* - Tests the Controller Singleton Factory Method +Tests the Controller Singleton Factory Method */ func TestGetInstance(t *testing.T) { - var controller = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) + var c = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) - if controller == nil { + if c == nil { t.Error("Expecting instance not nil") } } /* - Tests Command registration and execution. +Tests Command registration and execution. - This test gets a Singleton Controller instance - and registers the ControllerTestCommand class - to handle 'ControllerTest' Notifications. +This test gets a Singleton Controller instance +and registers the ControllerTestCommand class +to handle 'ControllerTest' Notifications. - It then constructs such a Notification and tells the - Controller to execute the associated Command. - Success is determined by evaluating a property - on an object passed to the Command, which will - be modified when the Command executes. +It then constructs such a Notification and tells the +Controller to execute the associated Command. +Success is determined by evaluating a property +on an object passed to the Command, which will +be modified when the Command executes. */ func TestRegisterAndExecuteCommand(t *testing.T) { // Create the controller, register the ControllerTestCommand to handle 'ControllerTest' notes - var controller = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) - controller.RegisterCommand("ControllerTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) + var c = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) + c.RegisterCommand("ControllerTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) // Create a 'ControllerTest' note var vo = ControllerTestVO{Input: 12} @@ -56,7 +56,7 @@ func TestRegisterAndExecuteCommand(t *testing.T) { // Tell the controller to execute the Command associated with the note // the ControllerTestCommand invoked will multiply the vo.input value // by 2 and set the result on vo.result - controller.ExecuteCommand(note) + c.ExecuteCommand(note) // test assertions if vo.Result != 24 { @@ -65,15 +65,15 @@ func TestRegisterAndExecuteCommand(t *testing.T) { } /* - Tests Command registration and removal. +Tests Command registration and removal. - Tests that once a Command is registered and verified - working, it can be removed from the Controller. +Tests that once a Command is registered and verified +working, it can be removed from the Controller. */ func TestRegisterAndRemoveCommand(t *testing.T) { // Create the controller, register the ControllerTestCommand to handle 'ControllerTest' notes - var controller = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) - controller.RegisterCommand("ControllerRemoveTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) + var c = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) + c.RegisterCommand("ControllerRemoveTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) // Create a 'ControllerTest' note var vo ControllerTestVO = ControllerTestVO{Input: 12} @@ -82,7 +82,7 @@ func TestRegisterAndRemoveCommand(t *testing.T) { // Tell the controller to execute the Command associated with the note // the ControllerTestCommand invoked will multiply the vo.input value // by 2 and set the result on vo.result - controller.ExecuteCommand(note) + c.ExecuteCommand(note) // test assertions if vo.Result != 24 { @@ -93,12 +93,12 @@ func TestRegisterAndRemoveCommand(t *testing.T) { vo.Result = 0 // Remove the Command from the Controller - controller.RemoveCommand("ControllerRemoveTest") + c.RemoveCommand("ControllerRemoveTest") // Tell the controller to execute the Command associated with the // note. This time, it should not be registered, and our vo result // will not change - controller.ExecuteCommand(note) + c.ExecuteCommand(note) // test assertions if vo.Result != 0 { @@ -107,56 +107,56 @@ func TestRegisterAndRemoveCommand(t *testing.T) { } /* - Test hasCommand method. +Test hasCommand method. */ func TestHasCommand(t *testing.T) { // register the ControllerTestCommand to handle 'hasCommandTest' notes - var controller = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) - controller.RegisterCommand("hasCommandTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) + var c = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) + c.RegisterCommand("hasCommandTest", func() interfaces.ICommand { return &ControllerTestCommand{} }) // test that hasCommand returns true for hasCommandTest notifications - if controller.HasCommand("hasCommandTest") == false { - t.Error("Expecting controller.HasCommand('hasCommandTest') == true") + if c.HasCommand("hasCommandTest") == false { + t.Error("Expecting c.HasCommand('hasCommandTest') == true") } // Remove the Command from the Controller - controller.RemoveCommand("hasCommandTest") + c.RemoveCommand("hasCommandTest") // test that hasCommand returns false for hasCommandTest notifications - if controller.HasCommand("hasCommandTest") == true { - t.Error("Expecting controller.HasCommand('hasCommandTest') == false") + if c.HasCommand("hasCommandTest") == true { + t.Error("Expecting c.HasCommand('hasCommandTest') == false") } } /* - Tests Removing and Reregistering a Command +Tests Removing and Reregistering a Command - Tests that when a Command is re-registered that it isn't fired twice. - This involves, minimally, registration with the controller but - notification via the View, rather than direct execution of - the Controller's executeCommand method as is done above in - testRegisterAndRemove. +Tests that when a Command is re-registered that it isn't fired twice. +This involves, minimally, registration with the controller but +notification via the View, rather than direct execution of +the Controller's executeCommand method as is done above in +testRegisterAndRemove. */ func TestReregisterAndExecuteCommand(t *testing.T) { // Fetch the controller, register the ControllerTestCommand2 to handle 'ControllerTest2' notes - var controller = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) - controller.RegisterCommand("ControllerTest2", func() interfaces.ICommand { return &ControllerTestCommand2{} }) + var c = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) + c.RegisterCommand("ControllerTest2", func() interfaces.ICommand { return &ControllerTestCommand2{} }) // Remove the Command from the Controller - controller.RemoveCommand("ControllerTest2") + c.RemoveCommand("ControllerTest2") // Re-register the Command with the Controller - controller.RegisterCommand("ControllerTest2", func() interfaces.ICommand { return &ControllerTestCommand2{} }) + c.RegisterCommand("ControllerTest2", func() interfaces.ICommand { return &ControllerTestCommand2{} }) // Create a 'ControllerTest2' note var vo *ControllerTestVO = &ControllerTestVO{Input: 12} var note interfaces.INotification = observer.NewNotification("ControllerTest2", vo, "") // retrieve a reference to the View from the same core. - var view interfaces.IView = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var v interfaces.IView = view.GetInstance(func() interfaces.IView { return &view.View{} }) // send the notification - view.NotifyObservers(note) + v.NotifyObservers(note) // test assertions // if the command is executed once the value will be 24 @@ -165,7 +165,7 @@ func TestReregisterAndExecuteCommand(t *testing.T) { } // Prove that accumulation works in the VO by sending the notification again - view.NotifyObservers(note) + v.NotifyObservers(note) // if the command is executed twice the value will be 48 if vo.Result != 48 { diff --git a/test/core/model/Model_test.go b/test/core/model/Model_test.go index 27d022b..a170e33 100755 --- a/test/core/model/Model_test.go +++ b/test/core/model/Model_test.go @@ -21,28 +21,28 @@ Test the PureMVC Model class. func TestGetInstance(t *testing.T) { // Test Factory Method - var model = model.GetInstance(func() interfaces.IModel { return &model.Model{} }) + var m = model.GetInstance(func() interfaces.IModel { return &model.Model{} }) // test assertions - if model == nil { + if m == nil { t.Error("Expecting instance not nil") } } /* - Tests the proxy registration and retrieval methods. +Tests the proxy registration and retrieval methods. - Tests registerProxy and retrieveProxy in the same test. - These methods cannot currently be tested separately - in any meaningful way other than to show that the - methods do not throw exception when called. +Tests registerProxy and retrieveProxy in the same test. +These methods cannot currently be tested separately +in any meaningful way other than to show that the +methods do not throw exception when called. */ func TestRegisterAndRetrieveProxy(t *testing.T) { // register a proxy and retrieve it. - var model = model.GetInstance(func() interfaces.IModel { return &model.Model{} }) - model.RegisterProxy(&proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}}) - var proxy = model.RetrieveProxy("colors") - var data = proxy.GetData().([]string) + var m = model.GetInstance(func() interfaces.IModel { return &model.Model{} }) + m.RegisterProxy(&proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}}) + var p = m.RetrieveProxy("colors") + var data = p.GetData().([]string) // test assertions if data == nil { @@ -63,77 +63,77 @@ func TestRegisterAndRetrieveProxy(t *testing.T) { } /* - Tests the proxy removal method. +Tests the proxy removal method. */ func TestRegisterAndRemoveProxy(t *testing.T) { // register a proxy, remove it, then try to retrieve it - var model = model.GetInstance(func() interfaces.IModel { return &model.Model{} }) - var proxy interfaces.IProxy = &proxy.Proxy{Name: "sizes", Data: []string{"7", "13", "21"}} - model.RegisterProxy(proxy) + var m = model.GetInstance(func() interfaces.IModel { return &model.Model{} }) + var p interfaces.IProxy = &proxy.Proxy{Name: "sizes", Data: []string{"7", "13", "21"}} + m.RegisterProxy(p) // remove the proxy - var removedProxy = model.RemoveProxy("sizes") + var removedProxy = m.RemoveProxy("sizes") // assert that we removed the appropriate proxy if removedProxy.GetProxyName() != "sizes" { t.Error("Expecting removedProxy.GetProxyName() == 'sizes'") } - // ensure that the proxy is no longer retrievable from the model - var nilProxy = model.RetrieveProxy("sizes") + // ensure that the proxy is no longer retrievable from the m + var nilProxy = m.RetrieveProxy("sizes") // test assertions if nilProxy != nil { - t.Error("Expecting proxy is nil") + t.Error("Expecting p is nil") } } /* - Tests the hasProxy Method +Tests the hasProxy Method */ func TestHasProxy(t *testing.T) { // register a proxy - var model = model.GetInstance(func() interfaces.IModel { return &model.Model{} }) - var proxy interfaces.IProxy = &proxy.Proxy{Name: "aces", Data: []string{"clubs", "spades", "hearts", "diamonds"}} - model.RegisterProxy(proxy) + var m = model.GetInstance(func() interfaces.IModel { return &model.Model{} }) + var p interfaces.IProxy = &proxy.Proxy{Name: "aces", Data: []string{"clubs", "spades", "hearts", "diamonds"}} + m.RegisterProxy(p) - // assert that the model.hasProxy method returns true + // assert that the m.hasProxy method returns true // for that proxy name - if model.HasProxy("aces") != true { - t.Error("Expecting model.HasProxy('aces') == true") + if m.HasProxy("aces") != true { + t.Error("Expecting m.HasProxy('aces') == true") } // remove the proxy - model.RemoveProxy("aces") + m.RemoveProxy("aces") - // assert that the model.hasProxy method returns false + // assert that the m.hasProxy method returns false // for that proxy name - if model.HasProxy("aces") != false { - t.Error("Expecting model.HasProxy('aces') == false") + if m.HasProxy("aces") != false { + t.Error("Expecting m.HasProxy('aces') == false") } } /* - Tests that the Model calls the onRegister and onRemove methods +Tests that the Model calls the onRegister and onRemove methods */ func TestOnRegisterAndOnRemove(t *testing.T) { // Get a Singleton View instance - var model = model.GetInstance(func() interfaces.IModel { return &model.Model{} }) + var m = model.GetInstance(func() interfaces.IModel { return &model.Model{} }) // Create and register the test mediator - var proxy interfaces.IProxy = &ModelTestProxy{proxy.Proxy{Name: MODEL_TEST_PROXY}} - model.RegisterProxy(proxy) + var p interfaces.IProxy = &ModelTestProxy{proxy.Proxy{Name: MODEL_TEST_PROXY}} + m.RegisterProxy(p) - // assert that onRegsiter was called, and the proxy responded by setting its data accordingly - if proxy.GetData() != ON_REGISTER_CALLED { - t.Error("Expecting proxy.GetData() == ON_REGISTER_CALLED") + // assert that onRegister was called, and the p responded by setting its data accordingly + if p.GetData() != ON_REGISTER_CALLED { + t.Error("Expecting p.GetData() == ON_REGISTER_CALLED") } // Remove the component - model.RemoveProxy(MODEL_TEST_PROXY) + m.RemoveProxy(MODEL_TEST_PROXY) - // assert that onRemove was called, and the proxy responded by setting its data accordingly - if proxy.GetData() != ON_REMOVE_CALLED { - t.Error("Expecting proxy.GetData() == ON_REMOVE_CALLED") + // assert that onRemove was called, and the p responded by setting its data accordingly + if p.GetData() != ON_REMOVE_CALLED { + t.Error("Expecting p.GetData() == ON_REMOVE_CALLED") } } diff --git a/test/core/view/ViewTestMediator.go b/test/core/view/ViewTestMediator.go index da7cd0a..187a1bf 100755 --- a/test/core/view/ViewTestMediator.go +++ b/test/core/view/ViewTestMediator.go @@ -13,7 +13,7 @@ import "github.com/puremvc/puremvc-go-standard-framework/src/patterns/mediator" const ViewTestMediator_NAME = "ViewTestMediator" /* -A Mediator class used by ViewTest. +ViewTestMediator A Mediator class used by ViewTest. */ type ViewTestMediator struct { mediator.Mediator diff --git a/test/core/view/ViewTestMediator2.go b/test/core/view/ViewTestMediator2.go index 47e04ed..9c54654 100755 --- a/test/core/view/ViewTestMediator2.go +++ b/test/core/view/ViewTestMediator2.go @@ -16,7 +16,7 @@ import ( const ViewTestMediator2_NAME = "viewTestMediator2" /* -A Mediator class used by ViewTest. +ViewTestMediator2 A Mediator class used by ViewTest. */ type ViewTestMediator2 struct { mediator.Mediator diff --git a/test/core/view/ViewTestMediator3.go b/test/core/view/ViewTestMediator3.go index caa1510..7389635 100755 --- a/test/core/view/ViewTestMediator3.go +++ b/test/core/view/ViewTestMediator3.go @@ -16,13 +16,13 @@ import ( const ViewTestMediator3_NAME = "viewTestMediator3" /* -A Mediator class used by ViewTest. +ViewTestMediator3 A Mediator class used by ViewTest. */ type ViewTestMediator3 struct { mediator.Mediator } -// be sure that the mediator has some Observers created +// ListNotificationInterests be sure that the mediator has some Observers created // in order to test removeMediator func (mediator *ViewTestMediator3) ListNotificationInterests() []string { return []string{VIEWTEST_NOTE3} diff --git a/test/core/view/ViewTestMediator4.go b/test/core/view/ViewTestMediator4.go index b48410d..486779c 100755 --- a/test/core/view/ViewTestMediator4.go +++ b/test/core/view/ViewTestMediator4.go @@ -13,7 +13,7 @@ import "github.com/puremvc/puremvc-go-standard-framework/src/patterns/mediator" const ViewTestMediator4_NAME = "ViewTestMediator4" /* -A Mediator class used by ViewTest. +ViewTestMediator4 A Mediator class used by ViewTest. */ type ViewTestMediator4 struct { mediator.Mediator diff --git a/test/core/view/ViewTestMediator5.go b/test/core/view/ViewTestMediator5.go index 18c0cc6..12775f1 100755 --- a/test/core/view/ViewTestMediator5.go +++ b/test/core/view/ViewTestMediator5.go @@ -16,7 +16,7 @@ import ( const ViewTestMediator5_NAME = "viewTestMediator5" /* -A Mediator class used by ViewTest. +ViewTestMediator5 A Mediator class used by ViewTest. */ type ViewTestMediator5 struct { mediator.Mediator diff --git a/test/core/view/ViewTestMediator6.go b/test/core/view/ViewTestMediator6.go index 5250cc6..2b8368b 100755 --- a/test/core/view/ViewTestMediator6.go +++ b/test/core/view/ViewTestMediator6.go @@ -16,7 +16,7 @@ import ( const ViewTestMediator6_NAME = "ViewTestMediator6" // The Mediator base name /* -A Mediator class used by ViewTest. +ViewTestMediator6 A Mediator class used by ViewTest. */ type ViewTestMediator6 struct { mediator.Mediator diff --git a/test/core/view/ViewTestNote.go b/test/core/view/ViewTestNote.go index 1669220..f4b09ed 100755 --- a/test/core/view/ViewTestNote.go +++ b/test/core/view/ViewTestNote.go @@ -21,21 +21,3 @@ type ViewTestNote struct { func ViewTestNoteNew(body interface{}) interfaces.INotification { return observer.NewNotification(ViewTestNote_NAME, body, "") } - -type ISuper interface{} - -type Super struct { - name string -} - -func NewSuper(name string) ISuper { - return &Super{name: name} -} - -type Sub struct { - Super -} - -func NewSub(name string) ISuper { - return Sub{Super{name}} -} diff --git a/test/core/view/View_test.go b/test/core/view/View_test.go index fc3f82d..985744d 100755 --- a/test/core/view/View_test.go +++ b/test/core/view/View_test.go @@ -21,46 +21,46 @@ Test the PureMVC View class. */ /* - Tests the View Singleton Factory Method +Tests the View Singleton Factory Method */ func TestGetInstance(t *testing.T) { // Test Factory Method - var view = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) // test assertions - if view == nil { + if v == nil { t.Error("Expecting instance not nil") } } /* - Tests registration and notification of Observers. - - An Observer is created to callback the viewTestMethod of - this ViewTest instance. This Observer is registered with - the View to be notified of 'ViewTestEvent' events. Such - an event is created, and a value set on its payload. Then - the View is told to notify interested observers of this - Event. - - The View calls the Observer's notifyObserver method - which calls the viewTestMethod on this instance - of the ViewTest class. The viewTestMethod method will set - an instance variable to the value passed in on the Event - payload. We evaluate the instance variable to be sure - it is the same as that passed out as the payload of the - original 'ViewTestEvent'. +Tests registration and notification of Observers. + +An Observer is created to callback the viewTestMethod of +this ViewTest instance. This Observer is registered with +the View to be notified of 'ViewTestEvent' events. Such +an event is created, and a value set on its payload. Then +the View is told to notify interested observers of this +Event. + +The View calls the Observer's notifyObserver method +which calls the viewTestMethod on this instance +of the ViewTest class. The viewTestMethod method will set +an instance variable to the value passed in on the Event +payload. We evaluate the instance variable to be sure +it is the same as that passed out as the payload of the +original 'ViewTestEvent'. */ func TestRegisterAndNotifyObserver(t *testing.T) { // Get the Singleton View instance - var view = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) // Create observer, passing in notification method and context var observerTest = ObserverTest{NotifyMethod: NotifyTestMethod} var obs = &observer.Observer{Notify: observerTest.NotifyMethod, Context: observerTest} // Register Observer's interest in a particulat Notification with the View - view.RegisterObserver(ViewTestNote_NAME, obs) + v.RegisterObserver(ViewTestNote_NAME, obs) // Create a ViewTestNote, setting // a body value, and tell the View to notify @@ -70,7 +70,7 @@ func TestRegisterAndNotifyObserver(t *testing.T) { // viewTestVar being set to the value we pass in // on the note body. var note = ViewTestNoteNew(10) - view.NotifyObservers(note) + v.NotifyObservers(note) // test assertions if ViewTestVar != 10 { @@ -79,67 +79,67 @@ func TestRegisterAndNotifyObserver(t *testing.T) { } /* - Tests registering and retrieving a mediator with - the View. +Tests registering and retrieving a mediator with +the View. */ func TestRegisterAndRetrieveMediator(t *testing.T) { // Get the Singleton View instance - var view = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) // Create and register the test mediator var viewTestMediator interfaces.IMediator = &ViewTestMediator{Mediator: mediator.Mediator{Name: ViewTestMediator_NAME, ViewComponent: nil}} - view.RegisterMediator(viewTestMediator) + v.RegisterMediator(viewTestMediator) // Retrieve the component - var mediator = view.RetrieveMediator(ViewTestMediator_NAME) + var mediator = v.RetrieveMediator(ViewTestMediator_NAME) // test assertions if mediator != viewTestMediator { t.Error("Expecting mediator is ViewTestMediator") } - view.RemoveMediator(ViewTestMediator_NAME) + v.RemoveMediator(ViewTestMediator_NAME) } /* - Tests the hasMediator Method +Tests the hasMediator Method */ func TestHasMediator(t *testing.T) { // register a Mediator - var view = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) - // Create and register the test mediator - var mediator interfaces.IMediator = &mediator.Mediator{Name: "hasMediatorTest", ViewComponent: nil} - view.RegisterMediator(mediator) + // Create and register the test n + var m interfaces.IMediator = &mediator.Mediator{Name: "hasMediatorTest", ViewComponent: nil} + v.RegisterMediator(m) - // assert that the view.hasMediator method returns true - // for that mediator name - if view.HasMediator("hasMediatorTest") != true { - t.Error("Expecting view.HasMediator('hasMediatorTest')") + // assert that the v.hasMediator method returns true + // for that n name + if v.HasMediator("hasMediatorTest") != true { + t.Error("Expecting v.HasMediator('hasMediatorTest')") } - view.RemoveMediator("hasMediatorTest") + v.RemoveMediator("hasMediatorTest") - // assert that the view.hasMediator method returns false - // for that mediator name - if view.HasMediator("hasMediatorTest") != false { - t.Error("Expecting view.HasMediator('hasMediatorTest') == false") + // assert that the v.hasMediator method returns false + // for that n name + if v.HasMediator("hasMediatorTest") != false { + t.Error("Expecting v.HasMediator('hasMediatorTest') == false") } } /* - Tests registering and removing a mediator +Tests registering and removing a mediator */ func TestRegisterAndRemoveMediator(t *testing.T) { // Get the Singleton View instance - var view = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) // Create and register the test mediator - var mediator interfaces.IMediator = &mediator.Mediator{Name: "testing", ViewComponent: nil} - view.RegisterMediator(mediator) + var m interfaces.IMediator = &mediator.Mediator{Name: "testing", ViewComponent: nil} + v.RegisterMediator(m) // Remove the component - var removedMediator = view.RemoveMediator("testing") + var removedMediator = v.RemoveMediator("testing") // assert that we have removed the appropriate mediator if removedMediator.GetMediatorName() != "testing" { @@ -147,22 +147,22 @@ func TestRegisterAndRemoveMediator(t *testing.T) { } // assert that the mediator is no longer retrievable - if view.RetrieveMediator("testing") != nil { + if v.RetrieveMediator("testing") != nil { t.Error("Expecting view.RetrieveMediator('testing') == nil") } } /* - Tests that the View callse the onRegister and onRemove methods +Tests that the View callse the onRegister and onRemove methods */ func TestOnRegisterAndOnRemove(t *testing.T) { // Get the Singleton View instance - var view = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) // Create and register the test mediator var data = Data{} - var mediator interfaces.IMediator = &ViewTestMediator4{mediator.Mediator{Name: ViewTestMediator4_NAME, ViewComponent: &data}} - view.RegisterMediator(mediator) + var m interfaces.IMediator = &ViewTestMediator4{mediator.Mediator{Name: ViewTestMediator4_NAME, ViewComponent: &data}} + v.RegisterMediator(m) // assert that onRegsiter was called, and the mediator responded by setting our boolean if data.onRegisterCalled != true { @@ -170,7 +170,7 @@ func TestOnRegisterAndOnRemove(t *testing.T) { } // Remove the component - view.RemoveMediator(ViewTestMediator4_NAME) + v.RemoveMediator(ViewTestMediator4_NAME) // assert that the mediator is no longer retrievable if data.onRemoveCalled != true { @@ -179,81 +179,81 @@ func TestOnRegisterAndOnRemove(t *testing.T) { } /* - Tests successive regster and remove of same mediator. +Tests successive register and remove of same mediator. */ func TestSuccessiveRegisterAndRemoveMediator(t *testing.T) { // Get the Singleton View instance - var view = view.GetInstance(func() interfaces.IView { return &view.View{}}) - var _mediator = &ViewTestMediator{Mediator: mediator.Mediator{Name: ViewTestMediator_NAME, ViewComponent: nil}} + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var m = &ViewTestMediator{Mediator: mediator.Mediator{Name: ViewTestMediator_NAME, ViewComponent: nil}} // Create and register the test mediator, // but not so we have a reference to it - view.RegisterMediator(_mediator) + v.RegisterMediator(m) // test that we can retrieve it - if view.RetrieveMediator(ViewTestMediator_NAME) != _mediator { + if v.RetrieveMediator(ViewTestMediator_NAME) != m { t.Error("Expecting view.RetrieveMediator(ViewTestMediatorNAME) == mediator") } //Remove the Mediator - view.RemoveMediator(ViewTestMediator_NAME) + v.RemoveMediator(ViewTestMediator_NAME) //test that retrieving it now returns nil - if view.RetrieveMediator(ViewTestMediator_NAME) != nil { + if v.RetrieveMediator(ViewTestMediator_NAME) != nil { t.Error("Expecting view.RetrieveMediator(ViewTestMediator.NAME) == nil") } // test that removing the mediator again once its gone doesn't cause crash - if view.RetrieveMediator(ViewTestMediator_NAME) != nil { + if v.RetrieveMediator(ViewTestMediator_NAME) != nil { t.Error("Expecting view.RetrieveMediator(ViewTestMediator.NAME) == nil") } // Create and register another instance of the test mediator, - view.RegisterMediator(&ViewTestMediator{Mediator: mediator.Mediator{Name: ViewTestMediator_NAME, ViewComponent: nil}}) + v.RegisterMediator(&ViewTestMediator{Mediator: mediator.Mediator{Name: ViewTestMediator_NAME, ViewComponent: nil}}) - if view.RetrieveMediator(ViewTestMediator_NAME) == nil { + if v.RetrieveMediator(ViewTestMediator_NAME) == nil { t.Error("Expecting view.RetrieveMediator(ViewTestMediator_NAME) != nil") } // Remove the Mediator - view.RemoveMediator(ViewTestMediator_NAME) + v.RemoveMediator(ViewTestMediator_NAME) // test that retrieving it now returns nil - if view.RetrieveMediator(ViewTestMediator_NAME) != nil { + if v.RetrieveMediator(ViewTestMediator_NAME) != nil { t.Error("Expecting view.RetrieveMediator(ViewTestMediator_NAME) == nil") } } /* - Tests registering a Mediator for 2 different notifications, removing the - Mediator from the View, and seeing that neither notification causes the - Mediator to be notified. +Tests registering a Mediator for 2 different notifications, removing the +Mediator from the View, and seeing that neither notification causes the +Mediator to be notified. */ func TestRemoveMediatorAndSubsequentNotify(t *testing.T) { // Get the Singleton View instance - var view = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) // Create and register the test mediator to be removed. var data = Data{} - view.RegisterMediator(&ViewTestMediator2{Mediator: mediator.Mediator{Name: ViewTestMediator2_NAME, ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator2{Mediator: mediator.Mediator{Name: ViewTestMediator2_NAME, ViewComponent: &data}}) // test that notifications work - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) if data.lastNotification != VIEWTEST_NOTE1 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE1") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) if data.lastNotification != VIEWTEST_NOTE2 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE2") } // Remove the Mediator - view.RemoveMediator(ViewTestMediator2_NAME) + v.RemoveMediator(ViewTestMediator2_NAME) // test that retrieving it now returns nil - if view.RetrieveMediator(ViewTestMediator2_NAME) != nil { - t.Error("Expecting view.RetrieveMediator(ViewTestMediator2.NAME) == nil") + if v.RetrieveMediator(ViewTestMediator2_NAME) != nil { + t.Error("Expecting v.RetrieveMediator(ViewTestMediator2.NAME) == nil") } // test that notifications no longer work @@ -261,148 +261,147 @@ func TestRemoveMediatorAndSubsequentNotify(t *testing.T) { // on this component, and ViewTestMediator) data.lastNotification = "" - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) if data.lastNotification != "" { t.Error("Expecting data.lastNotification == ''") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) if data.lastNotification != "" { t.Error("Expecting data.lastNotification == ''") } } /* - Tests registering one of two registered Mediators and seeing - that the remaining one still responds. +Tests registering one of two registered Mediators and seeing +that the remaining one still responds. */ func TestRemoveOneOfTwoMediatorsAndSubsequentNotify(t *testing.T) { // Get the Singleton View instance - var view = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) // Create and register that responds to notifications 1 and 2 var data = Data{} - view.RegisterMediator(&ViewTestMediator2{Mediator: mediator.Mediator{Name: ViewTestMediator2_NAME, ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator2{Mediator: mediator.Mediator{Name: ViewTestMediator2_NAME, ViewComponent: &data}}) // Create and register that responds to notification 3 - view.RegisterMediator(&ViewTestMediator3{Mediator: mediator.Mediator{Name: ViewTestMediator3_NAME, ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator3{Mediator: mediator.Mediator{Name: ViewTestMediator3_NAME, ViewComponent: &data}}) // test that all notifications work - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) if data.lastNotification != VIEWTEST_NOTE1 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE1") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) if data.lastNotification != VIEWTEST_NOTE2 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE2") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE3, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE3, "", "")) if data.lastNotification != VIEWTEST_NOTE3 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE3") } // Remove the Mediator that responds to 1 and 2 - view.RemoveMediator(ViewTestMediator2_NAME) + v.RemoveMediator(ViewTestMediator2_NAME) // test that retrieving it now returns nil - if view.RetrieveMediator(ViewTestMediator2_NAME) != nil { - t.Error("Expecting view.RetrieveMediator(ViewTestMediator2_NAME) == nil") + if v.RetrieveMediator(ViewTestMediator2_NAME) != nil { + t.Error("Expecting v.RetrieveMediator(ViewTestMediator2_NAME) == nil") } // test that notifications no longer work // for notifications 1 and 2, but still work for 3 data.lastNotification = "" - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE1, "", "")) if data.lastNotification == VIEWTEST_NOTE1 { t.Error("Expecting data.lastNotification != VIEWTEST_NOTE1") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE2, "", "")) if data.lastNotification == VIEWTEST_NOTE2 { t.Error("Expecting data.lastNotification != VIEWTEST_NOTE2") } - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE3, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE3, "", "")) if data.lastNotification != VIEWTEST_NOTE3 { t.Error("Expecting data.lastNotification == VIEWTEST_NOTE3") } } /* - Tests registering the same mediator twice. - A subsequent notification should only illicit - one response. Also, since reregistration - was causing 2 observers to be created, ensure - that after removal of the mediator there will - be no further response. +Tests registering the same mediator twice. +A subsequent notification should only illicit +one response. Also, since reregistration +was causing 2 observers to be created, ensure +that after removal of the mediator there will +be no further response. */ func TestMediatorReregistration(t *testing.T) { // Get the Singleton View instance - var view = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) // Create and register that responds to notification 5 var data = Data{} - view.RegisterMediator(&ViewTestMediator5{Mediator: mediator.Mediator{Name: ViewTestMediator5_NAME, ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator5{Mediator: mediator.Mediator{Name: ViewTestMediator5_NAME, ViewComponent: &data}}) // try to register another instance of that mediator (uses the same NAME constant). - view.RegisterMediator(&ViewTestMediator5{Mediator: mediator.Mediator{Name: ViewTestMediator5_NAME, ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator5{Mediator: mediator.Mediator{Name: ViewTestMediator5_NAME, ViewComponent: &data}}) // test that the counter is only incremented once (mediator 5's response) - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE5, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE5, "", "")) if data.counter != 1 { t.Error("Expecting counter == 1") } // Remove the Mediator - view.RemoveMediator(ViewTestMediator5_NAME) + v.RemoveMediator(ViewTestMediator5_NAME) // test that retrieving it now returns nil - if view.RetrieveMediator(ViewTestMediator5_NAME) != nil { - t.Error("Expecting view.RetrieveMediator(ViewTestMediator5_NAME) == nil") + if v.RetrieveMediator(ViewTestMediator5_NAME) != nil { + t.Error("Expecting v.RetrieveMediator(ViewTestMediator5_NAME) == nil") } // test that the counter is no longer incremented data.counter = 0 - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE5, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE5, "", "")) if data.counter != 0 { t.Error("Expecting counter == 0") } } /* - - Tests the ability for the observer list to - be modified during the process of notification, - and all observers be properly notified. This - happens most often when multiple Mediators - respond to the same notification by removing - themselves. +Tests the ability for the observer list to +be modified during the process of notification, +and all observers be properly notified. This +happens most often when multiple Mediators +respond to the same notification by removing +themselves. */ func TestModifyObserverListDuringNotification(t *testing.T) { // Get the Singleton View instance - var view = view.GetInstance(func() interfaces.IView { return &view.View{} }) + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) // Create and register several mediator instances that respond to notification 6 // by removing themselves, which will cause the observer list for that notification // to change. versions prior to MultiCore Version 2.0.5 will see every other mediator // fails to be notified. var data = Data{} - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/1", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/2", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/3", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/4", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/5", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/6", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/7", ViewComponent: &data}}) - view.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/8", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/1", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/2", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/3", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/4", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/5", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/6", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/7", ViewComponent: &data}}) + v.RegisterMediator(&ViewTestMediator6{Mediator: mediator.Mediator{Name: ViewTestMediator6_NAME + "/8", ViewComponent: &data}}) // send the notification. each of the above mediators will respond by removing // themselves and incrementing the counter by 1. This should leave us with a // count of 8, since 8 mediators will respond. - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE6, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE6, "", "")) // verify the count is correct if data.counter != 8 { @@ -411,7 +410,7 @@ func TestModifyObserverListDuringNotification(t *testing.T) { // clear the counter data.counter = 0 - view.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE6, "", "")) + v.NotifyObservers(observer.NewNotification(VIEWTEST_NOTE6, "", "")) // verify the count is 0 if data.counter != 0 { diff --git a/test/patterns/command/MacroCommandTestCommand.go b/test/patterns/command/MacroCommandTestCommand.go index 5521d14..5ce8576 100755 --- a/test/patterns/command/MacroCommandTestCommand.go +++ b/test/patterns/command/MacroCommandTestCommand.go @@ -14,22 +14,22 @@ import ( ) /* -A MacroCommand subclass used by MacroCommandTest. +MacroCommandTestCommand A MacroCommand subclass used by MacroCommandTest. */ type MacroCommandTestCommand struct { command.MacroCommand } /* - Initialize the MacroCommandTestCommand by adding - its 2 SubCommands. +InitializeMacroCommand Initialize the MacroCommandTestCommand by adding +its 2 SubCommands. */ -func (command *MacroCommandTestCommand) InitializeMacroCommand() { - command.AddSubCommand(func() interfaces.ICommand { return &MacroCommandTestSub1Command{} }) - command.AddSubCommand(func() interfaces.ICommand { return &MacroCommandTestSub2Command{} }) +func (self *MacroCommandTestCommand) InitializeMacroCommand() { + self.AddSubCommand(func() interfaces.ICommand { return &MacroCommandTestSub1Command{} }) + self.AddSubCommand(func() interfaces.ICommand { return &MacroCommandTestSub2Command{} }) } -func (command *MacroCommandTestCommand) Execute(notification interfaces.INotification) { - command.InitializeMacroCommand() // AddSubCommands - command.MacroCommand.Execute(notification) // Execute SubCommands +func (self *MacroCommandTestCommand) Execute(notification interfaces.INotification) { + self.InitializeMacroCommand() // AddSubCommands + self.MacroCommand.Execute(notification) // Execute SubCommands } diff --git a/test/patterns/command/MacroCommandTestSub1Command.go b/test/patterns/command/MacroCommandTestSub1Command.go index 1cb2fec..3b44381 100755 --- a/test/patterns/command/MacroCommandTestSub1Command.go +++ b/test/patterns/command/MacroCommandTestSub1Command.go @@ -18,11 +18,11 @@ type MacroCommandTestSub1Command struct { } /* - Fabricate a result by multiplying the input by 2 +Execute Fabricate a result by multiplying the input by 2 - - parameter event: the IEvent carrying the MacroCommandTestVO +- parameter event: the IEvent carrying the MacroCommandTestVO */ -func (command *MacroCommandTestSub1Command) Execute(notification interfaces.INotification) { +func (self *MacroCommandTestSub1Command) Execute(notification interfaces.INotification) { var vo = notification.Body().(*MacroCommandTestVO) // Fabricate a result diff --git a/test/patterns/command/MacroCommandTestSub2Command.go b/test/patterns/command/MacroCommandTestSub2Command.go index 0f88a0e..b70efee 100755 --- a/test/patterns/command/MacroCommandTestSub2Command.go +++ b/test/patterns/command/MacroCommandTestSub2Command.go @@ -18,11 +18,11 @@ type MacroCommandTestSub2Command struct { } /* - Fabricate a result by multiplying the input by itself +Execute Fabricate a result by multiplying the input by itself - - parameter event: the IEvent carrying the MacroCommandTestVO +- parameter event: the IEvent carrying the MacroCommandTestVO */ -func (command *MacroCommandTestSub2Command) Execute(notification interfaces.INotification) { +func (self *MacroCommandTestSub2Command) Execute(notification interfaces.INotification) { var vo = notification.Body().(*MacroCommandTestVO) // Fabricate a result diff --git a/test/patterns/command/MacroCommandTestVO.go b/test/patterns/command/MacroCommandTestVO.go index f1ffba9..ba3a5a5 100755 --- a/test/patterns/command/MacroCommandTestVO.go +++ b/test/patterns/command/MacroCommandTestVO.go @@ -9,7 +9,7 @@ package command /* -A utility class used by MacroCommandTest. +MacroCommandTestVO A utility class used by MacroCommandTest. */ type MacroCommandTestVO struct { Input int diff --git a/test/patterns/command/MacroCommand_test.go b/test/patterns/command/MacroCommand_test.go index 5675f1a..4a7f1ef 100755 --- a/test/patterns/command/MacroCommand_test.go +++ b/test/patterns/command/MacroCommand_test.go @@ -52,11 +52,11 @@ func TestMacroCommandExecute(t *testing.T) { var note = observer.NewNotification("MacroCommandTest", &vo, "") // Create the SimpleCommand - var command = MacroCommandTestCommand{MacroCommand: command.MacroCommand{}} - command.Notifier.InitializeNotifier() + var c = MacroCommandTestCommand{MacroCommand: command.MacroCommand{}} + c.Notifier.InitializeNotifier() // Execute the SimpleCommand - command.Execute(note) + c.Execute(note) // test assertions if vo.Result1 != 10 { @@ -68,17 +68,17 @@ func TestMacroCommandExecute(t *testing.T) { } /* - Testing MacroCommand via Controller and notify via View +Testing MacroCommand via Controller and notify via View */ func TestMacroCommandExecuteViaControllerView(t *testing.T) { - var controller = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) - var view = view.GetInstance(func() interfaces.IView { return &view.View{}}) + var c = controller.GetInstance(func() interfaces.IController { return &controller.Controller{} }) + var v = view.GetInstance(func() interfaces.IView { return &view.View{} }) - controller.RegisterCommand("MacroCommandTestViaControllerView", func() interfaces.ICommand { return &MacroCommandTestCommand{} }) + c.RegisterCommand("MacroCommandTestViaControllerView", func() interfaces.ICommand { return &MacroCommandTestCommand{} }) var vo = MacroCommandTestVO{Input: 5} var note = observer.NewNotification("MacroCommandTestViaControllerView", &vo, "") - view.NotifyObservers(note) + v.NotifyObservers(note) if vo.Result1 != 10 { t.Error("Expecting vo.Result1 == 10") diff --git a/test/patterns/command/SimpleCommandTestCommand.go b/test/patterns/command/SimpleCommandTestCommand.go index 6fb5166..358d9cd 100755 --- a/test/patterns/command/SimpleCommandTestCommand.go +++ b/test/patterns/command/SimpleCommandTestCommand.go @@ -11,17 +11,17 @@ package command import "github.com/puremvc/puremvc-go-standard-framework/src/interfaces" /* -A SimpleCommand subclass used by SimpleCommandTest. +SimpleCommandTestCommand A SimpleCommand subclass used by SimpleCommandTest. */ type SimpleCommandTestCommand struct { } /* - Fabricate a result by multiplying the input by 2 +Execute Fabricate a result by multiplying the input by 2 - - parameter event: the INotification carrying the SimpleCommandTestVO +- parameter event: the INotification carrying the SimpleCommandTestVO */ -func (command SimpleCommandTestCommand) execute(notification interfaces.INotification) { +func (self *SimpleCommandTestCommand) Execute(notification interfaces.INotification) { var vo = notification.Body().(*SimpleCommandTestVO) //Fabricate a result diff --git a/test/patterns/command/SimpleCommandTestVO.go b/test/patterns/command/SimpleCommandTestVO.go index e7834cd..5d423f0 100755 --- a/test/patterns/command/SimpleCommandTestVO.go +++ b/test/patterns/command/SimpleCommandTestVO.go @@ -9,7 +9,7 @@ package command /* -A utility class used by SimpleCommandTest. +SimpleCommandTestVO A utility class used by SimpleCommandTest. */ type SimpleCommandTestVO struct { Input int diff --git a/test/patterns/command/SimpleCommand_test.go b/test/patterns/command/SimpleCommand_test.go index 01c0d6d..34313a8 100755 --- a/test/patterns/command/SimpleCommand_test.go +++ b/test/patterns/command/SimpleCommand_test.go @@ -18,16 +18,16 @@ Test the PureMVC SimpleCommand class. */ /* - Tests the execute method of a SimpleCommand. +Tests the execute method of a SimpleCommand. - This test creates a new Notification, adding a - SimpleCommandTestVO as the body. - It then creates a SimpleCommandTestCommand and invokes - its execute method, passing in the note. +This test creates a new Notification, adding a +SimpleCommandTestVO as the body. +It then creates a SimpleCommandTestCommand and invokes +its execute method, passing in the note. - Success is determined by evaluating a property on the - object that was passed on the Notification body, which will - be modified by the SimpleCommand. +Success is determined by evaluating a property on the +object that was passed on the Notification body, which will +be modified by the SimpleCommand. */ func TestSimpleCommandExecute(t *testing.T) { // Create the VO @@ -40,7 +40,7 @@ func TestSimpleCommandExecute(t *testing.T) { var command = SimpleCommandTestCommand{} // Execute the SimpleCommand - command.execute(note) + command.Execute(note) // test assertions if vo.Result != 10 { diff --git a/test/patterns/facade/FacadeTestCommand.go b/test/patterns/facade/FacadeTestCommand.go index c59a856..4de87f3 100755 --- a/test/patterns/facade/FacadeTestCommand.go +++ b/test/patterns/facade/FacadeTestCommand.go @@ -14,18 +14,18 @@ import ( ) /* -A SimpleCommand subclass used by FacadeTest. +FacadeTestCommand A SimpleCommand subclass used by FacadeTest. */ type FacadeTestCommand struct { command.SimpleCommand } /* - Fabricate a result by multiplying the input by 2 +Execute Fabricate a result by multiplying the input by 2 - - parameter note: the Notification carrying the FacadeTestVO +- parameter note: the Notification carrying the FacadeTestVO */ -func (facade *FacadeTestCommand) Execute(notification interfaces.INotification) { +func (self *FacadeTestCommand) Execute(notification interfaces.INotification) { var vo = notification.Body().(*FacadeTestVO) // Fabricate a Result diff --git a/test/patterns/facade/FacadeTestVO.go b/test/patterns/facade/FacadeTestVO.go index 8a2ac68..cc5c95e 100755 --- a/test/patterns/facade/FacadeTestVO.go +++ b/test/patterns/facade/FacadeTestVO.go @@ -9,7 +9,7 @@ package facade /* -A utility class used by FacadeTest. +FacadeTestVO A utility class used by FacadeTest. */ type FacadeTestVO struct { Input int diff --git a/test/patterns/facade/Facade_test.go b/test/patterns/facade/Facade_test.go index f7998e9..7771edf 100755 --- a/test/patterns/facade/Facade_test.go +++ b/test/patterns/facade/Facade_test.go @@ -22,37 +22,37 @@ Test the PureMVC Facade class. func TestGetInstance(t *testing.T) { // Test Factory Method - var facade = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) + var f = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) // test assertions - if facade == nil { + if f == nil { t.Error("Expecting instance not nil") } } /* - Tests Command registration and execution via the Facade. +Tests Command registration and execution via the Facade. - This test gets a Singleton Facade instance - and registers the FacadeTestCommand class - to handle 'FacadeTest' Notifcations. +This test gets a Singleton Facade instance +and registers the FacadeTestCommand class +to handle 'FacadeTest' Notifications. - It then sends a notification using the Facade. - Success is determined by evaluating - a property on an object placed in the body of - the Notification, which will be modified by the Command. +It then sends a notification using the Facade. +Success is determined by evaluating +a property on an object placed in the body of +the Notification, which will be modified by the Command. */ func TestRegisterCommandAndSendNotification(t *testing.T) { // Create the Facade, register the FacadeTestCommand to // handle 'FacadeTest' notifications - var facade = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) - facade.RegisterCommand("FacadeTestNote", func() interfaces.ICommand { return &FacadeTestCommand{} }) + var f = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) + f.RegisterCommand("FacadeTestNote", func() interfaces.ICommand { return &FacadeTestCommand{} }) // Send notification. The Command associated with the event // (FacadeTestCommand) will be invoked, and will multiply // the vo.input value by 2 and set the result on vo.result var vo = FacadeTestVO{Input: 32} - facade.SendNotification("FacadeTestNote", &vo, "") + f.SendNotification("FacadeTestNote", &vo, "") // test assertions if vo.Result != 64 { @@ -61,29 +61,29 @@ func TestRegisterCommandAndSendNotification(t *testing.T) { } /* - Tests Command removal via the Facade. +Tests Command removal via the Facade. - This test gets a Singleton Facade instance - and registers the FacadeTestCommand class - to handle 'FacadeTest' Notifcations. Then it removes the command. +This test gets a Singleton Facade instance +and registers the FacadeTestCommand class +to handle 'FacadeTest' Notifications. Then it removes the command. - It then sends a Notification using the Facade. - Success is determined by evaluating - a property on an object placed in the body of - the Notification, which will NOT be modified by the Command. +It then sends a Notification using the Facade. +Success is determined by evaluating +a property on an object placed in the body of +the Notification, which will NOT be modified by the Command. */ func TestRegisterAndRemoveCommandAndSendNotification(t *testing.T) { // Create the Facade, register the FacadeTestCommand to // handle 'FacadeTest' events - var facade = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) - facade.RegisterCommand("FacadeTestNote", func() interfaces.ICommand { return &FacadeTestCommand{} }) - facade.RemoveCommand("FacadeTestNote") + var f = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) + f.RegisterCommand("FacadeTestNote", func() interfaces.ICommand { return &FacadeTestCommand{} }) + f.RemoveCommand("FacadeTestNote") // Send notification. The Command associated with the event // (FacadeTestCommand) will NOT be invoked, and will NOT multiply // the vo.input value by 2 var vo = FacadeTestVO{Input: 32} - facade.SendNotification("FacadeTestNote", &vo, "") + f.SendNotification("FacadeTestNote", &vo, "") // test assertions if vo.Result == 64 { @@ -92,23 +92,21 @@ func TestRegisterAndRemoveCommandAndSendNotification(t *testing.T) { } /* - Tests the regsitering and retrieving Model proxies via the Facade. +Tests the registering and retrieving Model proxies via the Facade. - Tests registerProxy and retrieveProxy in the same test. - These methods cannot currently be tested separately - in any meaningful way other than to show that the - methods do not throw exception when called. +Tests registerProxy and retrieveProxy in the same test. +These methods cannot currently be tested separately +in any meaningful way other than to show that the +methods do not throw exception when called. */ func TestRegisterAndRetrieveProxy(t *testing.T) { // register a proxy and retrieve it. - var facade = facade.GetInstance(func() interfaces.IFacade { - return &facade.Facade{} - }) - facade.RegisterProxy(&proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}}) - var proxy = facade.RetrieveProxy("colors").(*proxy.Proxy) + var f = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) + f.RegisterProxy(&proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}}) + var p = f.RetrieveProxy("colors").(*proxy.Proxy) // retrieve data from proxy - var data = proxy.Data.([]string) + var data = p.Data.([]string) // test assertions if data == nil { @@ -129,18 +127,18 @@ func TestRegisterAndRetrieveProxy(t *testing.T) { } /* - Tests the removing Proxies via the Facade. +Tests the removing Proxies via the Facade. */ func TestRegisterAndRemoveProxy(t *testing.T) { // register a proxy, remove it, then try to retrieve it - var facade = facade.GetInstance(func() interfaces.IFacade { + var f = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) - var proxy interfaces.IProxy = &proxy.Proxy{Name: "sizes", Data: []string{"7", "13", "21"}} - facade.RegisterProxy(proxy) + var p interfaces.IProxy = &proxy.Proxy{Name: "sizes", Data: []string{"7", "13", "21"}} + f.RegisterProxy(p) // remove the proxy - var removedProxy = facade.RemoveProxy("sizes") + var removedProxy = f.RemoveProxy("sizes") // assert that we removed the appropriate proxy if removedProxy.GetProxyName() != "sizes" { @@ -148,7 +146,7 @@ func TestRegisterAndRemoveProxy(t *testing.T) { } // make sure we can no longer retrieve the proxy from the model - var proxy2 = facade.RetrieveProxy("sizes") + var proxy2 = f.RetrieveProxy("sizes") // test assertions if proxy2 != nil { t.Error("Expecting proxy is nil") @@ -156,20 +154,20 @@ func TestRegisterAndRemoveProxy(t *testing.T) { } /* - Tests registering, retrieving and removing Mediators via the Facade. +Tests registering, retrieving and removing Mediators via the Facade. */ func TestRegisterRetrieveAndRemoveMediator(t *testing.T) { // register a mediator, remove it, then try to retrieve it - var facade = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) - facade.RegisterMediator(&mediator.Mediator{Name: mediator.NAME, ViewComponent: []string{}}) + var f = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) + f.RegisterMediator(&mediator.Mediator{Name: mediator.NAME, ViewComponent: []string{}}) // retrieve the mediator - if facade.RetrieveMediator(mediator.NAME) == nil { + if f.RetrieveMediator(mediator.NAME) == nil { t.Error("Expecting mediator is not nil") } // remove the mediator - removedMediator := facade.RemoveMediator(mediator.NAME) + removedMediator := f.RemoveMediator(mediator.NAME) // assert that we have removed the appropriate mediator if removedMediator.GetMediatorName() != mediator.NAME { @@ -177,69 +175,69 @@ func TestRegisterRetrieveAndRemoveMediator(t *testing.T) { } // assert that the mediator is no longer retrievable - if facade.RetrieveMediator(mediator.NAME) != nil { + if f.RetrieveMediator(mediator.NAME) != nil { t.Error("Expecting facade.RetrieveMediator( Mediator.NAME ) == nil") } } /* - Tests the hasProxy Method +Tests the hasProxy Method */ func TestHasProxy(t *testing.T) { // register a Proxy - var facade = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) - facade.RegisterProxy(&proxy.Proxy{Name: "hasProxyTest", Data: []int{1, 2, 3}}) + var f = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) + f.RegisterProxy(&proxy.Proxy{Name: "hasProxyTest", Data: []int{1, 2, 3}}) // assert that the model.hasProxy method returns true // for that proxy name - if facade.HasProxy("hasProxyTest") != true { + if f.HasProxy("hasProxyTest") != true { t.Error("Expecting facade.HasProxy('hasProxyTest') == true") } } /* - Tests the hasMediator Method +Tests the hasMediator Method */ func TestHasMediator(t *testing.T) { // register a Mediator - var facade = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) - facade.RegisterMediator(&mediator.Mediator{Name: "facadeHasMediatorTest", ViewComponent: []int{}}) + var f = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) + f.RegisterMediator(&mediator.Mediator{Name: "facadeHasMediatorTest", ViewComponent: []int{}}) // assert that the facade.hasMediator method returns true // for that mediator name - if facade.HasMediator("facadeHasMediatorTest") != true { + if f.HasMediator("facadeHasMediatorTest") != true { t.Error("Expecting facade.HasMediator('facadeHasMediatorTest') == true") } - facade.RemoveMediator("facadeHasMediatorTest") + f.RemoveMediator("facadeHasMediatorTest") // assert that the facade.hasMediator method returns false // for that mediator name - if facade.HasMediator("facadeHasMediatorTest") != false { + if f.HasMediator("facadeHasMediatorTest") != false { t.Error("Expecting facade.HasMediator('facadeHasMediatorTest') == false") } } /* - Test hasCommand method. +Test hasCommand method. */ func TestHasCommand(t *testing.T) { // register the ControllerTestCommand to handle 'hasCommandTest' notes - var facade = facade.GetInstance(func() interfaces.IFacade { + var f = facade.GetInstance(func() interfaces.IFacade { return &facade.Facade{} }) - facade.RegisterCommand("facadeHasCommandTest", func() interfaces.ICommand { return &FacadeTestCommand{} }) + f.RegisterCommand("facadeHasCommandTest", func() interfaces.ICommand { return &FacadeTestCommand{} }) // test that hasCommand returns true for hasCommandTest notifications - if facade.HasCommand("facadeHasCommandTest") != true { + if f.HasCommand("facadeHasCommandTest") != true { t.Error("Expecting facade.HasCommand('facadeHasCommandTest') == true") } // Remove the Command from the Controller - facade.RemoveCommand("facadeHasCommandTest") + f.RemoveCommand("facadeHasCommandTest") // test that hasCommand returns false for hasCommandTest notifications - if facade.HasCommand("facadeHasCommentTest") != false { + if f.HasCommand("facadeHasCommentTest") != false { t.Error("Expecting facade.HasCommand('facadeHasCommandTest') == false") } -} \ No newline at end of file +} diff --git a/test/patterns/proxy/Proxy_test.go b/test/patterns/proxy/Proxy_test.go index 8462199..c35e4e1 100755 --- a/test/patterns/proxy/Proxy_test.go +++ b/test/patterns/proxy/Proxy_test.go @@ -19,27 +19,27 @@ Test the PureMVC Proxy class. */ /* - Tests getting the name using Proxy class accessor method. Setting can only be done in constructor. +Tests getting the name using Proxy class accessor method. Setting can only be done in constructor. */ func TestNameAccessor(t *testing.T) { // Create a new Proxy and use accessors to set the proxy name - var proxy interfaces.IProxy = &proxy.Proxy{Name: "TestProxy", Data: nil} + var p interfaces.IProxy = &proxy.Proxy{Name: "TestProxy", Data: nil} // test assertions - if proxy.GetProxyName() != "TestProxy" { + if p.GetProxyName() != "TestProxy" { t.Error("Expecting proxy.GetProxyName() == 'TestProxy'") } } /* - Tests setting and getting the data using Proxy class accessor methods. +Tests setting and getting the data using Proxy class accessor methods. */ func TestDataAccessor(t *testing.T) { // Create a new Proxy and use accessors to set the data - var proxy interfaces.IProxy = &proxy.Proxy{Name: "colors"} - proxy.SetData([]string{"red", "green", "blue"}) + var p interfaces.IProxy = &proxy.Proxy{Name: "colors"} + p.SetData([]string{"red", "green", "blue"}) - var data = proxy.GetData().([]string) + var data = p.GetData().([]string) // test assertions if len(data) != 3 { @@ -57,19 +57,19 @@ func TestDataAccessor(t *testing.T) { } /* - Tests setting the name and body using the Notification class Constructor. +Tests setting the name and body using the Notification class Constructor. */ func TestConstructor(t *testing.T) { // Create a new Proxy using the Constructor to set the name and data - var proxy interfaces.IProxy = &proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}} + var p interfaces.IProxy = &proxy.Proxy{Name: "colors", Data: []string{"red", "green", "blue"}} - var data = proxy.GetData().([]string) + var data = p.GetData().([]string) // test assertions - if proxy == nil { + if p == nil { t.Error("Expecting proxy not nil") } - if proxy.GetProxyName() != "colors" { + if p.GetProxyName() != "colors" { t.Error("Expecting proxy.GetProxyName() == 'colors'") } if len(data) != 3 {