From: Keith Q. <ke...@qm...> - 2004-01-15 09:05:27
|
Hi Further to my post I have tracked down the reason for the initial Assertion failure which was due to setting the tablename to "person" rather than "Person". However, I still had the problem of verifying that the requests were executed in the a certain order within the method under test. From examining parts of the source code (ExpectationSet) it was obvious that what was being checked was whether the object was present in the HashSet and no ordering is associated with this. I have managed to get the test to succeed however, I cannot assert the order in which the statements are executed. Is there any way to achieve this? Regards Keith Ps: the modified testcase: - public void testInsertNewRegistration(){ setExpectationsForNextVal("Person"); setExpectationsForInsertRegistration(); person.setLogger(logger); person.setId(0); //forces insert ie: id only assigned on insert person.persist(mockConnection, today); verifyJDBC(); } private void setExpectationsForInsertRegistration(){ mockConnection.setupAddPreparedStatement(PersonImpl.INSERT_NEW_REGISTRATION_ SQL,mockPreparedStatement); mockConnection.setupStatement(mockStatement); mockPreparedStatement.addExpectedSetParameters(INSERT_NEW_REGISTRATION_ROW); //todo: only add set expectations once. Factor out mockPreparedStatement.addUpdateCount(1); mockPreparedStatement.setExpectedCloseCalls(2); mockConnection.setExpectedRollbackCalls(0); mockConnection.setExpectedCommitCalls(0); } private void setExpectationsForNextVal(String tableName){ mockConnection.setupAddPreparedStatement(SELECT_NEXTVAL_SQL,mockPreparedStat ement); mockConnection.setupStatement(mockStatement); mockPreparedStatement.addExpectedSetParameter(1,tableName); //set resultset to return value of PERSON_ID == 1 //todo: check if there is a better way of doing this! Object[][] rs = new Object[][] {{Integer.valueOf("1")},{}}; mockResultset.setupRows(rs); mockPreparedStatement.addResultSet(mockResultset); } |