Instructions Jenkins Doxygen

[Added] More unit tests for the Lua jedi managers. 55/855/2
authorLoshult <loshult@swgemu.com>
Sun, 29 Sep 2013 15:51:01 +0000 (15:51 +0000)
committerLoshult <loshult@swgemu.com>
Sun, 29 Sep 2013 15:51:01 +0000 (15:51 +0000)
[Updated] usage of . and : in the jedi manager lua files.

Change-Id: Ia7b7fbb09bf920a1a955b4f4e27e81aa19070e3e

MMOCoreORB/bin/scripts/managers/holocron_jedi_manager.lua
MMOCoreORB/bin/scripts/managers/jedi_manager.lua
MMOCoreORB/bin/scripts/managers/tests/holocron_jedi_manager_Test.lua
MMOCoreORB/bin/scripts/managers/tests/jedi_manager_Test.lua

index b160a47..4c22b2d 100644 (file)
@@ -1,5 +1,5 @@
 package.path = package.path .. ";scripts/managers/?.lua"
-require("jedi_manager")
+JediManager = require("jedi_manager")
 
 jediManagerName = "HolocronJediManager"
 
@@ -62,9 +62,8 @@ function HolocronJediManager:getGrindableProfessionList()
 end
 
 function HolocronJediManager:onPlayerCreation(pCreatureObject)
-       local skillList = self:getGrindableProfessionList()
-
-       self:withCreaturePlayerObject(pCreatureObject, function(playerObject)
+       local skillList = HolocronJediManager.getGrindableProfessionList()
+       HolocronJediManager.withCreaturePlayerObject(pCreatureObject, function(playerObject)
                for i = 1, NUMBEROFPROFESSIONSTOMASTER, 1 do
                        local numberOfSkillsInList = table.getn(skillList)
                        local skillNumber = math.random(1, numberOfSkillsInList)
@@ -74,8 +73,8 @@ function HolocronJediManager:onPlayerCreation(pCreatureObject)
        end)
 end
 
-function HolocronJediManager:getProfessionNameFromBadgeNumber(badgeNumber)
-       local skillList = self:getGrindableProfessionList()
+function HolocronJediManager.getProfessionNameFromBadgeNumber(badgeNumber)
+       local skillList = HolocronJediManager.getGrindableProfessionList()
        for i = 1, table.getn(skillList), 1 do
                if skillList[i][2] == badgeNumber then
                        return skillList[i][3]
@@ -85,12 +84,14 @@ function HolocronJediManager:getProfessionNameFromBadgeNumber(badgeNumber)
 end
 
 function HolocronJediManager:checkForceStatusCommand(pCreatureObject)
-       self:withCreatureAndPlayerObject(pCreatureObject, function(creatureObject, playerObject)
+       HolocronJediManager.withCreatureAndPlayerObject(pCreatureObject, function(creatureObject, playerObject)
                creatureObject:sendSystemMessage("Debug information for the holocron jedi progression system.")
                creatureObject:sendSystemMessage("Professions selected for this player:")
                local professions = playerObject:getHologrindProfessions()
                for i = 1, table.getn(professions), 1 do
-                       creatureObject:sendSystemMessage(self:getProfessionNameFromBadgeNumber(professions[i]))
+                       creatureObject:sendSystemMessage(HolocronJediManager.getProfessionNameFromBadgeNumber(professions[i]))
                end
        end)
 end
+
+return HolocronJediManager
index 9faee7a..c4f22f7 100644 (file)
@@ -29,7 +29,7 @@ JediManager = Object:new {
 -- @param pCreatureObject a pointer to a creature object.
 -- @param performThisFunction a function that takes a creature object as its argument.
 -- @return whatever performThisFunction returns or nil if the pCreatureObject pointer is nil.
-function JediManager:withCreatureObject(pCreatureObject, performThisFunction)
+function JediManager.withCreatureObject(pCreatureObject, performThisFunction)
        if pCreatureObject == nil then
                return nil
        end
@@ -41,7 +41,7 @@ end
 -- @param pPlayerObject a pointer to a player object.
 -- @param performThisFunction a function that takes a player object as its argument.
 -- @return whatever performThisFunction returns or nil if the pPlayerObject pointer is nil.
-function JediManager:withPlayerObject(pPlayerObject, performThisFunction)
+function JediManager.withPlayerObject(pPlayerObject, performThisFunction)
        if pPlayerObject == nil then
                return nil
        end
@@ -53,9 +53,9 @@ end
 -- @param pCreatureObject a pointer to a creature object.
 -- @param performThisFunction a function that takes a player object as its argument.
 -- @return whatever performThisFunction returns or nil if the pCreatureObject pointer is nil or does not have a player object.
-function JediManager:withCreaturePlayerObject(pCreatureObject, performThisFunction)
-       return self:withCreatureObject(pCreatureObject, function(creatureObject)
-               return self:withPlayerObject(creatureObject:getPlayerObject(), performThisFunction)
+function JediManager.withCreaturePlayerObject(pCreatureObject, performThisFunction)
+       return JediManager.withCreatureObject(pCreatureObject, function(creatureObject)
+               return JediManager.withPlayerObject(creatureObject:getPlayerObject(), performThisFunction)
        end)
 end
 
@@ -63,9 +63,9 @@ end
 -- @param pCreatureObject a pointer to a creature object.
 -- @param performThisFunction a function that takes a creature object and a player object as its argument.
 -- @return whatever performThisFunction returns or nil if the pCreatureObject pointer is nil or does not have a player object.
-function JediManager:withCreatureAndPlayerObject(pCreatureObject, performThisFunction)
-       return self:withCreatureObject(pCreatureObject, function(creatureObject)
-               return self:withPlayerObject(creatureObject:getPlayerObject(), function(playerObject)
+function JediManager.withCreatureAndPlayerObject(pCreatureObject, performThisFunction)
+       return JediManager.withCreatureObject(pCreatureObject, function(creatureObject)
+               return JediManager.withPlayerObject(creatureObject:getPlayerObject(), function(playerObject)
                        return performThisFunction(creatureObject, playerObject)
                end)
        end)
@@ -87,7 +87,9 @@ function JediManager:onPlayerLogout(pCreatureObject)
        -- Default behaviour for the onPlayerLogout event, do nothing.
 end
 
-function JediManager:checkForceStatusCommand(pCreatureObject)
+function JediManager.checkForceStatusCommand(pCreatureObject)
        -- Default behaviour for the checkForceStatus command, do nothing.
 end
 
+return JediManager
+
index 655a988..6dd88bb 100644 (file)
@@ -9,58 +9,31 @@ describe("Holocron Jedi Manager", function()
        end)
 
        it("Get grindable profession list returns a list of at least the number of professions that has to be mastered", function()
-               assert.is_true(EXPECTEDNUMBEROFPROFESSIONSTOGRIND <= table.getn(HolocronJediManager:getGrindableProfessionList()))
+               assert.is_true(EXPECTEDNUMBEROFPROFESSIONSTOGRIND <= table.getn(HolocronJediManager.getGrindableProfessionList()))
        end)
 
        it("The size of the grindable profession list is not affected when items are removed from it locally", function()
-               local theList = HolocronJediManager:getGrindableProfessionList()
+               local theList = HolocronJediManager.getGrindableProfessionList()
                local firstSize = table.getn(theList)
                table.remove(theList, 1)
-               assert.are.equal(firstSize, table.getn(HolocronJediManager:getGrindableProfessionList()))
+               assert.are.equal(firstSize, table.getn(HolocronJediManager.getGrindableProfessionList()))
        end)
 
        it("Shall on call to onPlayerCreation call the add hologrind profession method of the lua player object the defined number of times", function()
                local creaturePointer = {}
                local playerPointer = {}
-               local addHologrindProfessionSpy = spy.new(function() end)
+               addHologrindProfessionSpy = spy.new(function() end)
                local getPlayerObjectSpy = spy.new(function() return playerPointer end)
-               LuaPlayerObject =  spy.new(function() return { addHologrindProfession = addHologrindProfessionSpy } end)
-               LuaCreatureObject = spy.new(function() return { getPlayerObject = getPlayerObjectSpy } end)
-               HolocronJediManager:onPlayerCreation(creaturePointer)
+               local oldWithCreaturePlayerObject = HolocronJediManager.withCreaturePlayerObject
+               HolocronJediManager.withCreaturePlayerObject = spy.new(function(pCreatureObject, performThisFunction)
+                       return performThisFunction({ addHologrindProfession = addHologrindProfessionSpy }) 
+               end)
 
-               assert.spy(LuaCreatureObject).was.called_with(creaturePointer)
-               assert.spy(getPlayerObjectSpy).was.called(1)
-               assert.spy(LuaPlayerObject).was.called_with(playerPointer)
-               assert.spy(addHologrindProfessionSpy).was.called(EXPECTEDNUMBEROFPROFESSIONSTOGRIND)            
-       end)
-
-       it("Shall on call to onPlayerCreation if the creature pointer is equal to nil return without adding any hologrind professions", function()
-               local creaturePointer = nil
-               local playerPointer = {}
-               local addHologrindProfessionSpy = spy.new(function() end)
-               local getPlayerObjectSpy = spy.new(function() return playerPointer end)
-               LuaPlayerObject =  spy.new(function() return { addHologrindProfession = addHologrindProfessionSpy } end)
-               LuaCreatureObject = spy.new(function() return { getPlayerObject = getPlayerObjectSpy } end)
-               HolocronJediManager:onPlayerCreation(creaturePointer)
+               HolocronJediManager.onPlayerCreation(creaturePointer)
 
-               assert.spy(LuaCreatureObject).was_not_called()
-               assert.spy(getPlayerObjectSpy).was_not_called()
-               assert.spy(LuaPlayerObject).was_not_called()
-               assert.spy(addHologrindProfessionSpy).was_not_called()          
-       end)
-
-       it("Shall on call to onPlayerCreation if the player returned from getPlayerObject is equal to nil return without adding any hologrind professions", function()
-               local creaturePointer = {}
-               local playerPointer = nil
-               local addHologrindProfessionSpy = spy.new(function() end)
-               local getPlayerObjectSpy = spy.new(function() return playerPointer end)
-               LuaPlayerObject =  spy.new(function() return { addHologrindProfession = addHologrindProfessionSpy } end)
-               LuaCreatureObject = spy.new(function() return { getPlayerObject = getPlayerObjectSpy } end)
-               HolocronJediManager:onPlayerCreation(creaturePointer)
+               assert.spy(HolocronJediManager.withCreaturePlayerObject).was.called(1)
+               assert.spy(addHologrindProfessionSpy).was.called(EXPECTEDNUMBEROFPROFESSIONSTOGRIND)
 
-               assert.spy(LuaCreatureObject).was.called_with(creaturePointer)
-               assert.spy(getPlayerObjectSpy).was.called(1)
-               assert.spy(LuaPlayerObject).was_not_called()
-               assert.spy(addHologrindProfessionSpy).was_not_called()          
+               HolocronJediManager.withCreaturePlayerObject = oldWithCreaturePlayerObject
        end)
 end)
index 6a047ab..2144137 100644 (file)
@@ -3,19 +3,19 @@ require("jedi_manager")
 
 describe("Jedi Manager", function()
        it("Shall return nil if the creature object pointer is nil to the withCreatureObject function.", function()
-               assert.is.Nil(JediManager:withCreatureObject(nil, function(creatureObject) end))
+               assert.is.Nil(JediManager.withCreatureObject(nil, function(creatureObject) end))
        end)
 
        it("Shall return nil if the creature object pointer is nil to the withCreaturePlayerObject function.", function()
-               assert.is.Nil(JediManager:withCreaturePlayerObject(nil, function(playerObject) end))
+               assert.is.Nil(JediManager.withCreaturePlayerObject(nil, function(playerObject) end))
        end)
 
        it("Shall return nil if the player object pointer is nil to the withPlayerObject function.", function()
-               assert.is.Nil(JediManager:withPlayerObject(nil, function(playerObject) end))
+               assert.is.Nil(JediManager.withPlayerObject(nil, function(playerObject) end))
        end)
 
        it("Shall return nil if the creature object pointer is nil to the withCreatureAndPlayerObject function.", function()
-               assert.is.Nil(JediManager:withCreatureAndPlayerObject(nil, function(creatureObject, playerObject) end))
+               assert.is.Nil(JediManager.withCreatureAndPlayerObject(nil, function(creatureObject, playerObject) end))
        end)
 
        it("Shall call the supplied lambda expression with the CreatureObject when calling the withCreatureObject function.", function()
@@ -24,7 +24,7 @@ describe("Jedi Manager", function()
                local creatureObjectArgument = nil
                LuaCreatureObject = spy.new(function() return creatureObjectCreated end)
 
-               JediManager:withCreatureObject(creaturePointer, function(creatureObject) creatureObjectArgument = creatureObject end)
+               JediManager.withCreatureObject(creaturePointer, function(creatureObject) creatureObjectArgument = creatureObject end)
                assert.same(creatureObjectArgument, creatureObjectCreated)
        end)
 
@@ -34,7 +34,7 @@ describe("Jedi Manager", function()
                local playerObjectArgument = nil
                LuaPlayerObject = spy.new(function() return playerObjectCreated end)
 
-               JediManager:withPlayerObject(playerPointer, function(playerObject) playerObjectArgument = playerObject end)
+               JediManager.withPlayerObject(playerPointer, function(playerObject) playerObjectArgument = playerObject end)
                assert.same(playerObjectArgument, playerObjectCreated)
        end)
 
@@ -43,7 +43,7 @@ describe("Jedi Manager", function()
                local getPlayerObjectSpy = spy.new(function() return nil end)
                LuaCreatureObject = spy.new(function() return { getPlayerObject = getPlayerObjectSpy } end)
 
-               assert.is.Nil(JediManager:withCreaturePlayerObject(creaturePointer, function(playerObject) end))
+               assert.is.Nil(JediManager.withCreaturePlayerObject(creaturePointer, function(playerObject) end))
        end)
 
        it("Shall return nil if the creature object has a nil pointer to the player object when calling the withCreatureAndPlayerObject function.", function()
@@ -51,7 +51,7 @@ describe("Jedi Manager", function()
                local getPlayerObjectSpy = spy.new(function() return nil end)
                LuaCreatureObject = spy.new(function() return { getPlayerObject = getPlayerObjectSpy } end)
 
-               assert.is.Nil(JediManager:withCreatureAndPlayerObject(creaturePointer, function(playerObject) end))
+               assert.is.Nil(JediManager.withCreatureAndPlayerObject(creaturePointer, function(playerObject) end))
        end)
 
        it("Shall call the supplied lambda expression with the PlayerObject when calling the withCreaturePlayerObject function.", function()
@@ -63,7 +63,7 @@ describe("Jedi Manager", function()
                LuaCreatureObject = spy.new(function() return { getPlayerObject = getPlayerObjectSpy } end)
                LuaPlayerObject = spy.new(function() return playerObjectCreated end)
 
-               JediManager:withCreaturePlayerObject(creaturePointer, function(playerObject) playerObjectArgument = playerObject end)
+               JediManager.withCreaturePlayerObject(creaturePointer, function(playerObject) playerObjectArgument = playerObject end)
                assert.same(playerObjectArgument, playerObjectCreated)
        end)
 
@@ -78,7 +78,7 @@ describe("Jedi Manager", function()
                LuaCreatureObject = spy.new(function() return creatureObjectCreated end)
                LuaPlayerObject = spy.new(function() return playerObjectCreated end)
 
-               JediManager:withCreatureAndPlayerObject(creaturePointer, function(creatureObject, playerObject) 
+               JediManager.withCreatureAndPlayerObject(creaturePointer, function(creatureObject, playerObject) 
                        creatureObjectArgument = creatureObject
                        playerObjectArgument = playerObject
                end)