From: Vincent M. <vm...@pi...> - 2003-05-15 09:08:52
|
Hi, I have the following 2 tests: public void testCreateOrderOk() throws Exception { mockQueueConnectionFactory.expectAndReturn( "createQueueConnection", queueConnection); int orderId = petstore.createOrder(new Date(), "item1"); assertEquals(1234, orderId); } public void testCreateThrowsOrderException() throws Exception { mockQueueConnectionFactory.expectAndThrow( "createQueueConnection", new JMSException("error")); try { petstore.createOrder(new Date(), "item1"); fail("Should have thrown an EJBException"); } catch (EJBException expected) { assertEquals("error", expected.getCausedByException().getMessage()); } } The second test (testCreateThrowsOrderException()) fails with the following error: junit.framework.AssertionFailedError: mockQueueConnectionFactory: Unexpected call: createQueueConnection() Expected one of: createQueueConnection() [called] [...] If I comment out the testCreateOrderOk() method it works... It seems that the 2 tests are overstepping each other and that the second mock expectAndThrow() is not taken into account because the mock has already been set up by the first test! Glurps.... Any idea? Do we have a test case for this scenario in our test suite? Thanks -Vincent |