From: <Vin...@ge...> - 2003-01-31 19:05:42
|
If I undertand correctly, you're trying to test that your string message is being set as the text of your TextMessage object. You might want to change your test like this: // Junit test public void testJmsMessageCreation() { SomeDataObject data = new SomeDataObject(); data.fillWithSomeExtremelyImportantInformation(); MockQueueSession mqs = new MockQueueSession(); MockTextMessage mockMessage = new MockTextMessage(); mockMessage.setExpectedText(putYourExpectedValueHere); mqs.setupTextMessage(mockMessage); TextMessage tm = createJmsMessage(data, mqs); // What to do here? getText() returns null :-( // Don't actually have to do anything here in this case, // although it's good practise to call verify on mockobjects that have expectations, so: mockMessage.verify(); } The nice thing is that the test assertion is inside the MockTextMessage class and it will break immediatly if the value fed to setText() is not the expected value. Keep in mind though that it's not always the case for other test assertions so you should call verify() at the end of the test. Vincent -----Original Message----- From: Hlodver Tomasson [mailto:hto...@ba...] Sent: Friday, January 31, 2003 11:49 To: 'Vincent Tencé' Subject: RE: [MO-java-users] JMS MockTextMessage.getText() doesn't return the value set in setText(s) Hi Vincent and thanks for a quick response. (I didn't see your reply on the message thread so I'm backfiring this to you :) Here's a raw version of what I'm trying to do: // Method under test public javax.jms.Message createJmsMessage(SomeDataObject data, javax.jms.QueueSession qs) { String message = data.getDesiredMessage(); javax.jms.TextMessage tm = qs.createTextMessage( message ); return tm; } // Junit test public void testJmsMessageCreation() { SomeDataObject data = new SomeDataObject(); data.fillWithSomeExtremelyImportantInformation(); MockQueueSession mqs = new MockQueueSession(); TextMessage tm = createJmsMessage(data, mqs); // What to do here? getText() returns null :-( } Am I missing something? The problem is probably that I don't have access to the MockTextMessage before I call the domain code, and that's maybe not the way MockObjects are used in general. (I'm a newbie by the way, but used JUnit for quite a while now and I like the MO idea a lot). Kindest regards, Hlodver -----Original Message----- From: Vincent Tencé [mailto:Vin...@ge...] Sent: 31. janúar 2003 15:03 To: 'Hlodver Tomasson' Subject: RE: [MO-java-users] JMS MockTextMessage.getText() doesn't return the value set in setText(s) Hi Hlodver, The idea when testing your code against MockTextMessage is that you want to make sure that value fed to setText() by the code under test is the value you expect to receive. On the other hand, the value returned by the getText() method is used to test the behaviour of your code when it calls getText(). Use that value to simulate different text values in your TextMessage and see how the code under test reacts to these values. So it's not a classic getter/setter pattern. As for your problem, could you give more explanations on what you're trying to test and maybe post some code snippets. We'll try to work it out then. Vincent -----Original Message----- From: moc...@li... [mailto:moc...@li...]On Behalf Of Hlodver Tomasson Sent: Friday, January 31, 2003 08:36 To: 'moc...@li...' Subject: [MO-java-users] JMS MockTextMessage.getText() doesn't return the value set in setText(s) Hi, Why doesn't JMS MockTextMessage.getText() return the value set in MockTextMessage.setText()? (I'm using a factory method which returns a new TextMessage using QueueSession.createTextMessage(), and I can't call setExpectedText before I call setText() on the message) Regards, Hlodver |