Issue 154: assertSame and assertNotSame report incorrect assertions on Open BD when comparing simple values
Status:  Deprecated
Owner: ----
Closed:  Nov 2009
Reported by petermac...@gmail.com, Jul 12, 2009
assertSame and assertNotSame report incorrect assertions on Open BD when
comparing simple values.  This is because on Open BD it appears that the
identity hash codes for the two simple values do not match (whereas on
Adobe CF they do).

The following code works on Adobe CF8 whereas it fails the test case on
Open BD:
	<cffunction name="testSetBeanFields" access="public" returntype="void"
output="false"
		hint="Tests seting bean fields.">
	
		<cfset var bean =
variables.beanUtil.createBean("MachII.tests.util.BeanUtilTestBean") />
		<cfset var testData = StructNew() />
		
		<!--- Setup test data --->
		<cfset testData.firstName = "Mach-II" />
		<cfset testData.lastName = "Framework" />
		<cfset testData.dummy = false />

		<!--- Set only the firstName --->
		<cfset variables.beanUtil.setBeanFields(bean, "firstName", testData) />
		
		<!--- Assert that only firstName was populated --->
		<cfset assertSame(bean.getFirstName(), "Mach-II", "The value from
'getFirstName()' is '#bean.getFirstName()#' which does not match expected
'Mach-II'.") />
		<cfset assertSame(bean.getLastName(), "", "The value from 'getLastName()'
is '#bean.getLastName()#' which does not match expected ''.") />
	</cffunction>

This can be fixed by changing assertSame to do a direct comparison on
simple values instead of relying on identity hash code:

      //Arrays are passed by value in CF ...
      if(isArray(arguments.expected) or isArray(arguments.actual)){
      
throwWrapper("mxunit.exception.CannotCompareArrayReferenceException","Cannot compare
array references in ColdFusion","Arrays in ColdFusion are passed by value.
To compare instances, you may wrap the array in a struct and compare those.");
      }
      if(isSimpleValue(arguments.expected) and
isSimpleValue(arguments.actual) and arguments.expected EQ arguments.actual) {
      	return;
      }
      if(expect eq act){
        return;
      }

The same can be used for assertNotSame but the arguments.expected operator
needs to be changed to NEQ instead of EQ (the opposite of assertSame).
Nov 11, 2009
Project Member #1 virtix
<cfset assertSame(bean.getFirstName(), "Mach-II", "The value from
'getFirstName()' is '#bean.getFirstName()#' which does not match expected
'Mach-II'.") />
 
The above "should" fail because the instance of "Mach-II" should be a different
object than bean.getFirstName(), though the values are the same. I think that
comparing instances of String objects within CF contexts may be problematic in
general. Maybe comparing values using assertEquals is a better test for Strings and
reserve assertSame for complex object comparison. It should behave the same as (in
java) like s.equals(s2) vs. s == s2. I sense the problem needs to be defined better
and I'd like to discuss. Keeping open, but not taking any immediate action.


"...operator needs to be changed to NEQ instead of EQ (the opposite of assertSame). "
The existing expression is valid as if(not expect eq act) which is the negation of
if(expect eq act)
Status: In
Jun 30, 2010
Project Member #2 virtix
Moving some, but not all, of these to jira.mxunit.org
Status: Deprecated