0% found this document useful (0 votes)
6 views3 pages

(Aspectj-Users) Using AspectJ and Mock Objects

Uploaded by

ZhendongHe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

(Aspectj-Users) Using AspectJ and Mock Objects

Uploaded by

ZhendongHe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

[aspectj-users] Using AspectJ and mock objects https://www.eclipse.org/lists/aspectj-users/msg00863.

html

(https://www.eclipse.org/)

[Date Prev (msg00862.html)][Date Next (msg00864.html)][Thread Prev (msg00861.html)][Thread Next (msg00866.html)][Date Index (mail146.html#00863)]
[Thread Index (thrd145.html#00863)] [List Home (https://www.eclipse.org/mailman/listinfo/aspectj-users)]
[aspectj-users] Using AspectJ and mock objects
• From: "SADER, KEITH D (Contractor)" <KEITH.D.SADER@xxxxxxxx (mailto:[email protected])>
• Date: Thu, 31 Jul 2003 14:25:40 -0500
• Delivered-to: aspectj-users@xxxxxxxxxxx (mailto:[email protected])
• List-archive: <http://dev.eclipse.org/pipermail/aspectj-users/ (http://dev.eclipse.org/pipermail/aspectj-users/)>
• List-help: <mailto:[email protected]?subject=help (mailto:[email protected]?subject=help)>
• List-subscribe: <http://dev.eclipse.org/mailman/listinfo/aspectj-users (http://dev.eclipse.org/mailman/listinfo/aspectj-users)>, <mailto:aspectj-users-
[email protected]?subject=subscribe (mailto:[email protected]?subject=subscribe)>
• List-unsubscribe: <http://dev.eclipse.org/mailman/listinfo/aspectj-users (http://dev.eclipse.org/mailman/listinfo/aspectj-users)>, <mailto:aspectj-users-
[email protected]?subject=unsubscribe (mailto:[email protected]?subject=unsubscribe)>
• Thread-index: AcNXmX6AzcW8B3b/QEaPpClQO3zWcw==
• Thread-topic: Using AspectJ and mock objects

1/3 2022/10/09 10:55


[aspectj-users] Using AspectJ and mock objects https://www.eclipse.org/lists/aspectj-users/msg00863.html

Hi, I'm trying to use aspects to mock 'on the fly' a domain layer class. I've tried to follow Nicholas Leseicki's great article at http://www-106.i

My aspect looks like this - real names replaced to protect the innocent.

import java.util.Collection;
// import other stuff

public aspect DAOAspect


{
pointcut inTest() : execution(public void MyTestCase.*());
pointcut findThings(String searchStr) :
cflow(inTest()) &&
call(Collection MyDAO.find*(*)) && // MyDAO is a concrete class, not an interface.
!call(Collection MockMyDAO.find*(*)) &&
args(searchStr);

Collection around(String searchStr) : findThings(searchStr)


{
System.out.println("In the aspect");
System.out.println("searchStr is : " + searchStr);
return new MockMyDAO().findStuff(searchStr);
}
}

First bit of unexpected behavior:


I see that my aspect is called twice via the System.out.println()s
"In the aspect"
"search"
"In the aspect"
"search"
...

Why would this happen? I believe I'm only calling into the mocked DAO once.
// test case
public void testFind()
{
assertTrue(0 < daoCollaborator.find("search"));
}

// code under test in DAOCollaborator


public Collection find(String searchStr)
{
return new MyDAO().findStuff(searchStr);
}

// MyMockDAO over-ride
public Collection findStuff(String searchStr)
{
return mockStuff;
}

Second question/behavior.
Is it possible for me to just return the MockDAO whenever the DAO is invoked/used? It would make it easier for me to just return the mock object re

thanks,
---
Keith Sader
Nash Resources Group sub-contracting for Computer Sciences Corporation
IAD:TFAS
Email:keith.d.sader@xxxxxxxx
We've got a blind date with destiny, and it looks like she ordered the lobster.

• Follow-Ups:
◦ Re: [aspectj-users] Using AspectJ and mock objects--again (msg00867.html)
▪ From: Nicholas Lesiecki
◦ Re: [aspectj-users] Using AspectJ and mock objects (msg00866.html)
▪ From: Nicholas Lesiecki

• Prev by Date: RE: [aspectj-users] ajdoc lite (msg00862.html)


• Next by Date: AW: [aspectj-users] How to build a Dirty Flag ? (msg00864.html)

2/3 2022/10/09 10:55


[aspectj-users] Using AspectJ and mock objects https://www.eclipse.org/lists/aspectj-users/msg00863.html

• Previous by thread: Re: [aspectj-users] How to build a Dirty Flag ? (msg00861.html)


• Next by thread: Re: [aspectj-users] Using AspectJ and mock objects (msg00866.html)
• Index(es):
◦ Date (mail146.html#00863)
◦ Thread (thrd145.html#00863)

Back to the top

Copyright © Eclipse Foundation, Inc. All Rights Reserved.

   
(https://twitter.com
 (https://www.facebook.com
 (https://www.youtube.com
 (https://www.linkedin.com

/EclipseFdn)
/eclipse.org)
/user/EclipseFdn)
/company
/eclipse-
foundation)

3/3 2022/10/09 10:55

You might also like