Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 64 lines (49 sloc) 2.428 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
<cfcomponent displayname="MockFactoryFactory" output="false" hint="Fetches mock frameworks for tests. Test writers should not have to deal with this object directly. Use mock(...) instead">

<cfset variables.componentUtils = createObject("component","ComponentUtils") />
<cfset variables.Factory = 'mxunit.framework.mightymock.MightyMock' />
<cfset variables.mockFactoryInfo = chr(0) />

<cffunction name="MockFactoryFactory">
<cfargument name="frameworkName" required="false" default="" />
<cfset variables.mockFactoryInfo = findMockFactory(arguments.frameworkName) />
<cfset setFactory(variables.mockFactoryInfo.factoryPath) />
<cfif Len(variables.mockFactoryInfo.constructorName)>
<cfif StructCount(variables.mockFactoryInfo.constructorArgs)>
<cfinvoke component="#variables.Factory#" method="#variables.mockFactoryInfo.constructorName#" argumentcollection="#variables.mockFactoryInfo.constructorArgs#" />
<cfelse>
<cfinvoke component="#variables.Factory#" method="#variables.mockFactoryInfo.constructorName#" />
</cfif>
</cfif>
<cfreturn this />
</cffunction>

<cfscript>

function findMockFactory(frameworkName){
var fw_inf = chr(0);
try{
fw_inf = variables.componentUtils.getMockFactoryInfo(arguments.frameworkName);
} catch(expression e){
_$throw("org.mxunit.exception.MockFrameworkNotRegisteredException", "Mock framework '#arguments.frameworkName#' appears not to be registered.", "Make sure '#arguments.frameworkName#' is installed and registered in mxunit-config.xml.");
}
return fw_inf;
}


//injectable for cleaner design and testing
function setFactory( mockPath ){
try {
variables.Factory = createObject("component", mockPath );
} catch(Any e){ //bug. not catching any exception for createObject
_$throw("org.mxunit.exception.MockFrameworkNotInstalledException", "Mock framework '#arguments.mockPath#' appears not to be installed.", "Make sure '#arguments.mockPath#' is installed and registered correctly in mxunit-config.xml.");
}
}


function getFactory() {
return variables.Factory;
}


function getConfig(name) {
return variables.mockFactoryInfo[name];
}

</cfscript>



<cffunction name="_$throw">
  <cfargument name="type">
  <cfargument name="message">
  <cfargument name="detail">
  <cfthrow type="#type#" message="#message#" detail="#detail#" />
</cffunction>

</cfcomponent>
Something went wrong with that request. Please try again.