12 Jan 2011 13:52
Re: [jira] Commented: (JMOCK-247) Scripted action absent?
Ivan Yatskevich (JIRA <jira <at> ...> writes: > > > [ > http://jira.codehaus.org/browse/JMOCK-247? page=com.atlassian.jira.plugin.system.issuetabpanels:comment- tabpanel&focusedCommentId=251295#action_251295 > ] > > Ivan Yatskevich commented on JMOCK-247: > --------------------------------------- > > Hi Shay, > > > First, you need to add the following JARs to your classpath: > > > > * jmock-script-2.5.1.jar > > * bsh-core-2.0b4.jar Thanks :) That solved it. Now I can... > > import static org.jmock.lib.script.ScriptedAction.perform; ..and use... will(perform("[myscript]")); ...However after playing around a bit,(and because I'm not very experienced with BeanShell scripting), I found that for my needs there was a better solution using the abstract class org.jmock.lib.action.CustomAction: I wanted to test a component running in a thread launched by the test. What I needed was a means to get an early signal when some expectation was met. Before this I was sleeping the main thread for some time and then assert, but I found that the time needed, to satisfy the expectations, was not even near constant(from 1ms to 2sec). Anyway... FYI as I could not find a similar example, here is what I chose to do: ---in the test class private boolean flag=false; ---in the expectations oneOf (input).read(); will(new CustomAction("Set Test Point Flag") { public Object invoke(Invocation invocation) throws Throwable { flag=true; return null; } }); ---where input is mocked, and the component under test expects the read() method to return an Object or null, AND the test needs to know fast when this expectation has been met. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
RSS Feed