Skip to content

Commit

Permalink
Merge pull request #137 from simonbingham/refactor-tests
Browse files Browse the repository at this point in the history
General refactoring
  • Loading branch information
Simon Bingham committed Mar 20, 2015
2 parents c255b88 + 3fe9790 commit 18dbf25
Show file tree
Hide file tree
Showing 79 changed files with 2,503 additions and 1,550 deletions.
244 changes: 137 additions & 107 deletions Application.cfc

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _tests/automation/Tests.cfc
Expand Up @@ -3,7 +3,7 @@
http://localhost/xindi/_tests/automation/Tests.cfc?method=runRemote
*/

component extends="testbox.system.BaseSpec" {
component extends = "testbox.system.BaseSpec" {

// Testcase Lifecycle Methods

Expand Down
2 changes: 1 addition & 1 deletion _tests/xunit/BaseTest.cfc
@@ -1,4 +1,4 @@
component extends="testbox.system.BaseSpec" {
component extends = "testbox.system.BaseSpec" {

variables.mockbox = new testbox.system.MockBox();

Expand Down
72 changes: 40 additions & 32 deletions _tests/xunit/model/abstract/BaseServiceTests.cfc
@@ -1,4 +1,4 @@
component extends="tests.xunit.BaseTest" {
component extends = "tests.xunit.BaseTest" {

// Testcase Lifecycle Methods

Expand All @@ -17,70 +17,78 @@ component extends="tests.xunit.BaseTest" {

// Tests

function test_getValidator_calls_getValidator_once() {
// getValidator() tests

private struct function getMocksForGetValidatorTests() {
local.mocked = {};
variables.mocked.validationFactoryObj.$("getValidator");
return local.mocked;
}

function test_getValidator_calls_getValidator_once() {
local.mocked = getMocksForGetValidatorTests();
variables.CUT.getValidator(Entity = "");
$assert.isTrue(variables.mocked.validationFactoryObj.$once("getValidator"));
}

function test_populate_sets_property_when_key_is_included_and_setter_exists() {
// populate() tests

private struct function getMocksForPopulateTests() {
local.mocked = {};
local.mocked.entity = variables.mockbox.createStub().$("setTest");
return local.mocked;
}

function test_populate_sets_property_when_key_is_included_and_setter_exists() {
local.mocked = getMocksForPopulateTests();
variables.CUT.populate(Entity = local.mocked.entity, memento = {test = ""}, include = "test");
$assert.isTrue(local.mocked.entity.$once("setTest"));
}

function test_populate_does_not_set_property_when_key_is_excluded() {
local.mocked.entity = variables.mockbox.createStub().$("setTest");
local.mocked = getMocksForPopulateTests();
variables.CUT.populate(Entity = local.mocked.entity, memento = {test = ""}, exclude = "test");
$assert.isTrue(local.mocked.entity.$never("setTest"));
}

function test_populateMetaData_sets_meta_title_when_isMetaGenerated_is_true() {
// populateMetaData() tests

private struct function getMocksForPopulateMetaDataTests() {
local.mocked = {};
variables.mocked.metaDataObj
.$("generateMetaDescription")
.$("generateMetaKeywords");
.$("generateMetaDescription", "")
.$("generateMetaKeywords", "");
local.mocked.entity = variables.mockbox.createStub()
.$("isMetaGenerated", TRUE)
.$("getTitle")
.$("setMetaTitle");
.$("getContent", "")
.$("getTitle", "")
.$("setMetaTitle")
.$("setMetaDescription")
.$("setMetaKeywords");
return local.mocked;
}

function test_populateMetaData_sets_meta_title_when_isMetaGenerated_is_true() {
local.mocked = getMocksForPopulateMetaDataTests();
variables.CUT.populateMetaData(Entity = local.mocked.entity);
$assert.isTrue(local.mocked.entity.$once("setMetaTitle"));
}

function test_populateMetaData_sets_meta_description_when_isMetaGenerated_is_true() {
variables.mocked.metaDataObj
.$("generateMetaDescription")
.$("generateMetaKeywords");
local.mocked.entity = variables.mockbox.createStub()
.$("isMetaGenerated", TRUE)
.$("getContent")
.$("setMetaDescription");
local.mocked = getMocksForPopulateMetaDataTests();
variables.CUT.populateMetaData(Entity = local.mocked.entity);
$assert.isTrue(local.mocked.entity.$once("setMetaDescription"));
}

function test_populateMetaData_sets_meta_keywords_when_isMetaGenerated_is_true() {
variables.mocked.metaDataObj
.$("generateMetaDescription")
.$("generateMetaKeywords");
local.mocked.entity = variables.mockbox.createStub()
.$("isMetaGenerated", TRUE)
.$("getContent")
.$("setMetaKeywords");
local.mocked = getMocksForPopulateMetaDataTests();
variables.CUT.populateMetaData(Entity = local.mocked.entity);
$assert.isTrue(local.mocked.entity.$once("setMetaKeywords"));
}

function test_populateMetaData_does_not_set_meta_data_when_isMetaGenerated_is_false() {
variables.mocked.metaDataObj
.$("generateMetaDescription")
.$("generateMetaKeywords");
local.mocked.entity = variables.mockbox.createStub()
.$("isMetaGenerated", FALSE)
.$("getContent")
.$("setMetaDescription")
.$("setMetaKeywords")
.$("setMetaTitle");
local.mocked = getMocksForPopulateMetaDataTests();
local.mocked.entity.$("isMetaGenerated", FALSE);
variables.CUT.populateMetaData(Entity = local.mocked.entity);
$assert.isTrue(local.mocked.entity.$never("setMetaDescription"));
$assert.isTrue(local.mocked.entity.$never("setMetaKeywords"));
Expand Down
26 changes: 22 additions & 4 deletions _tests/xunit/model/aop/GlobalEventHandlerTests.cfc
@@ -1,4 +1,4 @@
component extends="tests.xunit.BaseTest" {
component extends = "tests.xunit.BaseTest" {

// Testcase Lifecycle Methods

Expand All @@ -8,20 +8,38 @@ component extends="tests.xunit.BaseTest" {

// Tests

// preInsert() tests

private struct function getMocksForPreInsertTests() {
local.mocked = {};
local.mocked.entity = variables.mockbox.createStub()
.$("setCreated")
.$("setUpdated");
return local.mocked;
}

function test_preInsert_calls_setCreated_when_method_exists() {
local.mocked.entity = variables.mockbox.createStub().$("setCreated");
local.mocked = getMocksForPreInsertTests();
variables.CUT.preInsert(entity = local.mocked.entity);
$assert.isTrue(local.mocked.entity.$once("setCreated"));
}

function test_preInsert_calls_setUpdated_when_method_exists() {
local.mocked.entity = variables.mockbox.createStub().$("setUpdated");
local.mocked = getMocksForPreInsertTests();
variables.CUT.preInsert(entity = local.mocked.entity);
$assert.isTrue(local.mocked.entity.$once("setUpdated"));
}

function test_preUpdate_calls_setUpdated_when_method_exists() {
// preUpdate() tests

private struct function getMocksForPreUpdateTests() {
local.mocked = {};
local.mocked.entity = variables.mockbox.createStub().$("setUpdated");
return local.mocked;
}

function test_preUpdate_calls_setUpdated_when_method_exists() {
local.mocked = getMocksForPreUpdateTests();
variables.CUT.preUpdate(entity = local.mocked.entity);
$assert.isTrue(local.mocked.entity.$once("setUpdated"));
}
Expand Down

0 comments on commit 18dbf25

Please sign in to comment.