|
From: SMITH N. <nei...@un...> - 2007-06-11 14:26:45
|
Thanks for your rapid response!
I'm sorry, I didn't give you enough information... But it's solved!
In fact, the getCourse() is to create another object (it's a bit
complicated...). If a course is full, it creates a
RegistrationWaitingList object (which is quite similar to a
registration). This is then used to keep a waiting list of
registrations. This object is always created, because I test if the
person is already registered to the course (in waiting list or not). So
this should not interfere with my tests.
I when wrong with the setCourse(course1)... It was there because I was
trying to set my course to my course mock... That should be done by
using the bit of code you provided, I understand that now.
Thanks again!!!
Best regards
Neil.
-----Original Message-----
From: joa...@gm... [mailto:joa...@gm...] On
Behalf Of Joakim Ohlrogge
Sent: lundi, 11. juin 2007 13:57
To: SMITH Neil
Cc: rmo...@li...
Subject: Re: [Rmock-users] A mock as an attribute of another mock
There is a way to do this. In your case I'm not sure, I would have to
see the testcase and perhaps some source but from your error it looks
like you've got an automatically created mock back from one of the two
getCourse calls and that one is used instead of your manually created
"course1" mock.
>From your expected setCourse(course1) invocation I suspect that you
might have expected the value to actually be set as a property and not
only expected but there is no way I can be sure.
If I'm right you could solve it in one of two ways:
1)
Course course1 =3D (Course)mock(Course.class);
Registration registration =3D (Registration)mock(Registration.class);
registration.getCourse();
modify().returnValue(course1);
startVerification();
2)
Registration registration =3D (Registration)mock(Registration.class);
Course course1 =3D registration.getCourse();
startVerification();
Both are equivalent. In the second case RMock automates
mock(Course.class) and modify().returnValue(course1);
This a bit of a stab in the dark since I lack some information but I
hope it helps. /Joakim Ohlrogge
On 6/11/07, SMITH Neil <nei...@un...> wrote:
> Hello!
>
> I'm having a little trouble working this one out and I don't know if=20
> it is possible.
>
> Here is what I have:
> 3 classes, Person, Registration and Course
>
> Registration concerns a Course (1 and only 1)
> Person has a set of Registrations
>
>
> When I test my Person class, I want to have a mock of my Registration=20
> classe to isolate it properly, but to do that, I also have to mock my=20
> Course classe, so I have a mock (mockReg) that has a property of=20
> Course type that contains a mock.
>
> I hope this is all clear up to now...
>
> When I test my Person class, I'm having touble setting up the=20
> expectations on my Course mock. For example
>
> mockCourse.countRegistrations();
> modify().returnValue(0);
>
> And when I run the program, I get the error
>
> com.agical.rmock.core.exception.UnexpectedInvocationException:
> UNEXPECTED!
> No expectation matched: course1$.countRegistrations()
> -----------------------------------------------------------------
> 3 expectation(s) have not yet been matched
> (indicated by '->' in the listing below)
> -----------------------------------------------------------------
> Unordered section:root {
> Unordered section:main {
> 1(1)=20
> registrationInt1.setRegsistered(eq(<ch.unifr.sdis.isweb.business.Sport
> sm
> an@5cfa9339>))
> 1(1) registrationInt1.setCourse(eq(<course1>))
> -> 0(1) course1.getMaximumParticipants()
> -> 0(1) course1.countRegistrations()
> -> 0(1) course1.addRegistration(eq(<registrationInt1>))
> 1(1) registrationInt1.getRegsistered()
> 1(1) registrationInt1.getRegistrationDate()
> 1(1) registrationInt1.getRegistrator()
> 2(2) registrationInt1.getCourse()
> 1(1) registrationInt1.getCourseDetail()
> 1(1) registrationInt1.getPhone()
> 1(1) registrationInt1.getEmail()
> 1(1) registrationInt1.getNote()
> 1(1) registrationInt1.getRentedEquipment()
> 1(1)
registrationInt1.getRegistrationDisciplineLevel()
> }
> Unordered section:defaults {
> }
> }
>
> As you can see, my course1.countRegistrations() is not matched, and=20
> the
> course1$.countRegistration() is an unexpected invocation...
>
> How can I setup the expectations for my mock in the mock? Is there a=20
> way to do this or not?
>
>
> Thanks in advance!
>
> Take care
> Neil.
>
> ----------------------------------------------------------------------
> ---
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Rmock-users mailing list
> Rmo...@li...
> https://lists.sourceforge.net/lists/listinfo/rmock-users
>
|