Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for indirect dependant invocations #9

Open
mkotsbak opened this issue Jun 7, 2010 · 4 comments
Open

Support for indirect dependant invocations #9

mkotsbak opened this issue Jun 7, 2010 · 4 comments
Labels

Comments

@mkotsbak
Copy link
Contributor

mkotsbak commented Jun 7, 2010

I looked at some code that could be useful for using this tool on, and discovered a problem. Typically in EJB session/entity beans code in the logic methods you call some variation of:

getAnEntityBeanUtil.getLocalhome().findSomethingInDB(aParameter);

I think it is the same as this feature in JMock tries to solve. See question "Can I stub chained getters?" in: http://code.google.com/p/mockito/wiki/FAQ
and
http://mockito.googlecode.com/svn/tags/latest/javadoc/org/mockito/Mockito.html#RETURNS_DEEP_STUBS

Without any special care, if you place the dependency annotation in the class containing getAnEntityBeanUtil(), you will record a return value with a halfway living object that wants to do jndi lookup, which will fail in the test run. So you want to mock 2 layers before getting and playing back real return values. We then maybe need a third annotation to indicate this, something like "mockthrough, bypass, mock, chained".

How is this working in the .NET version? Is it supported, and if not, is it not a relevant case for usual programming patterns there?

@oc
Copy link
Member

oc commented Jun 7, 2010

Yeah, that will be a problem for us too some time. Perhaps we could scope the dependency to do something like @dependency(scope=DependencyScope.[FOLLOW,THROUGH,BYPASS,CHAIN,etc]) or something?

@mkotsbak
Copy link
Contributor Author

mkotsbak commented Jun 7, 2010

Hehe, can you explain what you mean by each of that scopes, if it wasn't just example buzz words.

@follesoe
Copy link

follesoe commented Jun 7, 2010

For legacy code projects in .NET I don't think this a common pattern. There are cases when people use nHibernate and IoC containers it may be tricky to know when to record the dependency. In the example above the actual dependency you want to record is the call to "findSomethingInDB", so in that case I would simply put the dependency on the type returned by getLocalHome(), and not on getAnEntityBeanUtil.

@mkotsbak
Copy link
Contributor Author

mkotsbak commented Jun 7, 2010

Sure, but getLocalHome() also need special treatment, as running the real code inside it will only work when an application server is running (i.e. lookup in JNDI server), so it need to be replaced by e.g. a mock during playback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants