I think you have this mocking backwards. Mock myRepostory, then set up the myRepository mock to return a Criteria object and to return a project list when that Criteria object is passed to findList.
Task, Order and Project can probably just be instantiated.
Now, instance.getProjects(task) will return something. You can check to make sure that thing that got returned is the same thing you said should be returned from findList. Now you've actually tested something, albeit nothing particularly interesting.
You probably want to validate that the criteria object was set up correctly before it was passed to findList. To do that, you either have to make criteria a mock, then you can set up your expectations for what methods are called. The tricky part here is that Hibernate Restriction classes do not have a non-default equals implementation, so you have to write your own matcher to check that the Restrictions being passed to the criteria are the same (functionally) as the Restrictions you expect.
Another possibility is to set up criteria as an actual Criteria object. (You still set up your myRepository mock to return it.) Then, after the function is called, you can check the contents with some substring matching on the toString() method or any other ways you know to inspect the Criteria object.
A final (unit test) possibility is to not use a mocking framework for the Criteria object, but some hand-coded one that you write that allows you to inspect all of the Restrictions that were added to it.
All of this makes a good case for this method actually being tested with integration testing instead. You wind up doing a lot of work to verify some not very interesting things and your tests can become quite brittle if you try to refactor the code. (I've done it myself, so I speak from experience.)
Thanks a lot for your time. But the thing that I don't understand is that, if I mock the repository object and tell it to return these projects upon findList call. Then it would return what I have told it. So what should I compare it with when I have told it return what I want so it would return what I want whether the criteria works or not. The only thing is that I can initial projects and then just check if the criteria is correct or not. But can I also check whether it returns the correct thing with mocking repository as well?
the problem that I have with mocking here is that in general if I mock the repository and tell it what I expect as the return type then how can I test whether it returns the correct data? Am I missing something?
The point of the unit test (as opposed to integration testing) is that you don't want to test CreateMyRepositoryWrapper. You assume that that class is going to work correctly (based on other tests, you hope). In mocking, you say, "Suppose myRepository does this - does this method work as I expect?" In this way, you could easily test other scenarios, such as myRepository.findList returns null - do I want to return null or an empty list from this method? Suppose myRepository.findList throws an exception - do I want to handle that exception or just let it cascade?