Noam Ledany | 30 Jan 08:09
Gravatar

user@...

Hello,

I'm currently studying the jMock framework using your site.
I run into the following example ( about overrding expectations ) and it seems to me there is a mistake in the code:

<at> RunWith(JMock.class) public class ChildTest { Mockery context = new JUnit4Mockery(); States test = mockery.states("test"); Parent parent = context.mock(Parent.class); // This is created in setUp Child child; <at> Before public void createChildOfParent() { mockery.checking(new Expectations() {{ ignoring (parent).addChild(child); when(test.isNot("fully-set-up")); }}); // Creating the child adds it to the parent child = new Child(parent); test.become("fully-set-up"); } <at> Test public void removesItselfFromOldParentWhenAssignedNewParent() { Parent newParent = context.mock(Parent.class, "newParent"); context.checking(new Expectations() {{ oneOf (parent).removeChild(child); oneOf (newParent).addChild(child); }}); child.reparent(newParent); } }What is mockery  variable? Did you mean context and it's a misprint? or I'm getting it the wrong way?

Thanks,

Noam.



---------- Forwarded message ----------
From: <xircles-yCVjj/EcxBJg9hUCZPvPmw@public.gmane.org>
Date: Mon, Jan 30, 2012 at 8:52 AM
Subject: [Codehaus] Subscription confirmation for user-sXN/XchZ9OeVLWF/CSt7OA@public.gmane.org.org
To: noam <at> fashion-traffic.com


Hello noam <at> fashion-traffic.com

You have successfully subscribed to user-sXN/XchZ9OexIXFVlbCvtR2eb7JE58TQ@public.gmane.org using this email address.

Thanks,

Codehaus


Julian Bassett | 23 Jan 20:55
Picon
Gravatar

Due datefor 2.6.0

Is there a due date for 2.6.0?

Thanks in advance.

-Julian

meSubho | 12 Jan 11:18
Picon

How to mock test method with multi level dependency call


Hi,
I am writing mock junit tests for our existing application. The main class
is a Facade for which I am writing tests currently. In some cases methods of
this class has calls to multi level dependency. For example in method that I
am testing, there is a call like -

      dependency1.get2ndLevelDependency().getXyz();

In this case I am not able to use mock for 2ndLevelDependency and not able
to use expectation on the getXyz() call.

Please suggest what is the best way to handle such scenario.

Thanks,
Subho
--

-- 
View this message in context: http://old.nabble.com/How-to-mock-test-method-with-multi-level-dependency-call-tp33126850p33126850.html
Sent from the jMock - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Aram | 30 Nov 00:21
Picon

using DeterministicScheduler as an ExecutorService

I would like a suggestion/feedback for getting around the issue of getting an 
UnsupportedSynchronousOperationException when using DeterministicScheduler.  

Is there a workaround?  Or a suggestion of how I can proceed?

Also, I am kind of confused about what the following means: "The scheduler does 
not implement the synchronous methods of the SchedulerExecutorService interface. 
If a test attempts to do a blocking wait for a scheduled task to complete".  Can 
someone help me understand this.

I am trying to do some T-D-D using JMock in creating tests/class that support 
asynchronous code.  My design uses the Producer-Consumer pattern and my story 
requirements are that my processes in my consumer class run on their own 
"worker" thread.  

What I am really trying to do is use DeterministicScheduler, simply for it's 
implementation of ExecutorService, which will can return to me a Future<T> that 
my class can process and can do something with upon a 
DeterministicScheduler.submit(Callable<T>).

I have been relying heavily on the CookBook pages 
(http://www.jmock.org/threading-scheduler.html, 
http://www.jmock.org/threads.html). 

So, I have been using DeterministicScheduler as an ExecutorService in my test 
class:

public someTestClass {
  private DeterministicScheduler _executorService = new 
DeterministicScheduler();
  private OperationConsumer _operationConsumer = new OperationConsumer();
  private BlockingQueue<PackageResourceOperation> _mockOperationsQueue;

....

}

And in my testMethod, I am doing soemthing like:

        Expectations expectations = new Expectations() {
		{
            oneOf(_mockOperationsQueue).take();
        		will(returnValue(mockResourceOperation)); 
inSequence(readSequence);
        	oneOf(_mockConsumerReadResourceTask).call();
        		will(returnValue(mockResourceCollection)); 
inSequence(readSequence);
        }};

      _mockContext.checking(expectations);
      _operationConsumer.start(_executorService, _mockOperationsQueue);

My implementation Code for OperationConsumer does something like:
  void doSomeCoolOperations() {

  //note: params in ConsumerReadResourceTask are really populated by member 
content in resourceOperation
    resourceOperation = _operationsQueue.take();
    if (_consumerReadResourcesTask == null)
	_consumerReadResourcesTask = new ConsumerReadResourceTask(
			null, false, null, null, false);
    Future<Collection<Resource>> future =  
_worker.submit(_consumerReadResourcesTask);
  }

Everything was working smooth & dandy...Until, I added in the following code to 
doSomeCoolOperations():

	try {
	    Collection<Resource> resources = future.get();
	} catch (InterruptedException e) {
	    logger.warn("This Read Task was interupted " + e);
	} catch (ExecutionException e) {
	    throw new ResourceServiceException(e);
	}

At that point my test started returning the 
UnsupportedSynchronousOperationException:

org.jmock.lib.concurrent.UnsupportedSynchronousOperationException: cannot 
perform blocking wait on a task scheduled on a 
org.jmock.lib.concurrent.DeterministicScheduler
	at 
org.jmock.lib.concurrent.DeterministicScheduler.blockingOperationsNotSupported(D
eterministicScheduler.java:265)
	at 
org.jmock.lib.concurrent.DeterministicScheduler.access$100(DeterministicSchedule
r.java:28)
	at 
org.jmock.lib.concurrent.DeterministicScheduler$ScheduledTask.get(DeterministicS
cheduler.java:227)
	at 
com.rockwellautomation.resources.server.packaging.OperationConsumer.readAndRetur
nResources(OperationConsumer.java:86)
	at 
com.rockwellautomation.resources.server.packaging.OperationConsumer.chooseAndDoO
peration(OperationConsumer.java:72)
	at 
com.rockwellautomation.resources.server.packaging.OperationConsumer.start(Operat
ionConsumer.java:54)
	at 
com.rockwellautomation.resources.server.packaging.OperationConsumerTest.itShould
PollTheQueueAndExecuteReadResourceRequest(OperationConsumerTest.java:146)

This I assume is where I am trying to do a blocking wait for my task to 
complete.  

Any suggestions?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

DispatchMediaGroup | 15 Nov 21:08
Favicon

How to Spy a Method


Hey all, need a little help here.

I've been writing unit tests now for about a month or so, retroactively. 
That is, we are trying to get to a test-driven development paradigm, but for
now, we need to cover our existing code base.  We are using JUnit 3 and
JMock 2.5.1.

The issue is as such:

I have a method of a class that I wish to test.  It does certain things
depending on parameter state, like any good ole method.  However, at the end
of this method's execution, it daisy-chains to another method.  This second
method is not one that we wish to test, especially as its code just creates
an HTTP connection to a URL and posts a message there.  I want to write my
tests and expectations in such a way that I can expect the method
invocation, but not actually execute the code in that method.

Now, having done quite a bit of reading and Googling about this, I have not
been able to find the answer I need, but what I want to do is apparently
called 'method spying'.  Any idea how to do this?  This is a scenario where
I must stay within the constraints of the existing environment (no new jars,
no new frameworks - just JUnit and JMock).

Example:

public class SomeClass
{
     private static final SomeClass INSTANCE = new SomeClass();

     private SomeClass()
     {}

     public static SomeClass getInstance()
     {
          return INSTANCE;
     }

     protected void methodOne(Object objects...)
     {
          // do some stuff

          if (somethingIsTrue)
          {
               // This is the method invocation I want to expect, but not
execute
               methodTwo();
          }

          // do more stuff
     }

     protected void methodTwo(Object objects...)
     {
          // Here's my crappy workaround for the time-being:
          if (!System.getProperty("isTestCase").equals("true"))
          {
               // make a bunch of calls that shouldn't be tested
               // if executed, timeout and break test(s)

               // now i've broken some encapsulation
               // i've also introduced bad coding/testing practices
               // writing code just to be able to test is not okay (as
opposed to writing testable code)
          }
     }
}
--

-- 
View this message in context: http://old.nabble.com/How-to-Spy-a-Method-tp32850127p32850127.html
Sent from the jMock - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Ashutosh Kumar | 13 Sep 07:16
Picon

RE: expects returns a default value for void return type

I am using 2.5.1 . It does not create any thread. Implementation classes use spring for dependency injection.

 

Thanks

Ashutosh

 

From: Fedor Bobin [mailto:fuudtorrentsru-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org]
Sent: Tuesday, September 13, 2011 10:45 AM
To: user-sXN/XchZ9OexIXFVlbCvtR2eb7JE58TQ@public.gmane.org
Subject: Re: [jmock-user] expects returns a default value for void return type

 

What jmock version do you use?
Is userService.saveUser() create or use threads?

 

2011/9/13 Ashutosh Kumar <Ashutosh.Kumar-YELz9hDmLZ5yjigaA7mwwQ@public.gmane.org>

I have a method which returns void . However when I run the test I get error stating

 

java.lang.AssertionError: unexpected invocation: brmUserBo.saveUser(<com.arisglobal.agBRM.user.entity.BrmUser <at> 16672d6>)

expectations:

  allowed, never invoked: brmUserBo.saveUser(<com.arisglobal.agBRM.user.entity.BrmUser <at> 16672d6>); returns a default value

 

Here is my test :

 

public void testsaveUsers() {

            try {

                  final  Mockery context = new  JUnit4Mockery()  {{

                    setImposteriser(ClassImposteriser.INSTANCE);

                }};

                  final BrmUserBoImpl userBo = context.mock(BrmUserBoImpl.class);

                  final BrmUser user = new BrmUser();

                  BrmUserServiceImpl userService = new BrmUserServiceImpl();

                  userService.setBrmUserBo(userBo);

                  context.checking(new Expectations() {

                        {

                              allowing(userBo).saveUser(user);

                             

                        }

                  });

                  userService.saveUser(user);

            } catch (Exception e) {

                  fail();

            }

      }

 


Disclaimer: This transmission, including attachments, is confidential, proprietary, and may be privileged. It is intended solely for the intended recipient. If you are not the intended recipient, you have received this transmission in error and you are hereby advised that any review, disclosure, copying, distribution, or use of this transmission, or any of the information included therein, is unauthorized and strictly prohibited. If you have received this transmission in error, please immediately notify the sender by reply and permanently delete all copies of this transmission and its attachments.

 



Disclaimer: This transmission, including attachments, is confidential, proprietary, and may be privileged. It is intended solely for the intended recipient. If you are not the intended recipient, you have received this transmission in error and you are hereby advised that any review, disclosure, copying, distribution, or use of this transmission, or any of the information included therein, is unauthorized and strictly prohibited. If you have received this transmission in error, please immediately notify the sender by reply and permanently delete all copies of this transmission and its attachments.

Ashutosh Kumar | 13 Sep 06:46
Picon

expects returns a default value for void return type

I have a method which returns void . However when I run the test I get error stating

 

java.lang.AssertionError: unexpected invocation: brmUserBo.saveUser(<com.arisglobal.agBRM.user.entity.BrmUser <at> 16672d6>)

expectations:

  allowed, never invoked: brmUserBo.saveUser(<com.arisglobal.agBRM.user.entity.BrmUser <at> 16672d6>); returns a default value

 

Here is my test :

 

public void testsaveUsers() {

            try {

                  final  Mockery context = new  JUnit4Mockery()  {{

                    setImposteriser(ClassImposteriser.INSTANCE);

                }};

                  final BrmUserBoImpl userBo = context.mock(BrmUserBoImpl.class);

                  final BrmUser user = new BrmUser();

                  BrmUserServiceImpl userService = new BrmUserServiceImpl();

                  userService.setBrmUserBo(userBo);

                  context.checking(new Expectations() {

                        {

                              allowing(userBo).saveUser(user);

                             

                        }

                  });

                  userService.saveUser(user);

            } catch (Exception e) {

                  fail();

            }

      }



Disclaimer: This transmission, including attachments, is confidential, proprietary, and may be privileged. It is intended solely for the intended recipient. If you are not the intended recipient, you have received this transmission in error and you are hereby advised that any review, disclosure, copying, distribution, or use of this transmission, or any of the information included therein, is unauthorized and strictly prohibited. If you have received this transmission in error, please immediately notify the sender by reply and permanently delete all copies of this transmission and its attachments.

Fred Trimble | 8 Jul 15:15
Favicon

Release Candidate 2 - Plans To Make a Stable Release

Does anyone know if there are any plans to move release 2.6.0-RC2 to a stable 
release in the near future? Thanks!

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Ashish | 17 Jun 02:59
Picon
Favicon
Gravatar

How to mock different returns between the first and the second invocations?

Hi,
  I have a method that I want to mock that has recursive call to itself. If the
method is called first (From my test) it should return say null but as the
method internally calls itself internally (the second call) it should return a
specific value. 
public class A {
  private Service service;
  public Object lookup() {
     if (service == null) {
        service = new Service();
     }
*1:     Object o = service.getValue();

     while (o == null) {
        Thread.sleep (100);
*2:        o = service.getValue();
     }
     return o;
   }
}

Testing this class I used reflection to replace the service with a Mocked value.
Have set the expection that *1 returns null. But I want *2 to return some
other value. Is it possible?

Appreciate your help.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Ron Courtright | 13 Jun 19:27
Favicon

Getting the thread safe version via ivy

Is there a POM or dependency file that will allow me to update to the
latest and greatest (and reasonably stable) thread-safe version of jmock
using ivy?
--

-- 
Regards,

Ron Courtright
mailto:rcourtright@...

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Paul Hanrahan | 8 Jun 10:38
Favicon

jmock - unfinal classes

Hi 

Sorry to repost this question,  I know there was already a thread on this issue
in 2010. It is just to ask if anybody has had any success in using the
unfinalizer workaround from jdave.org to mock a third party final class.

Also does anymore know where to download that JAR, it doesnt seem to be on
jdave.org anymore

thanks

Paul

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane