Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Mocking typically works well if you use inversion of control and dependency injection to wire up your services. So your person should look like </p> <pre><code>public class Person() { WebService ws = null; // or use setters instead of constructor injection Persion(WebService ws) { this.ws = ws; } public Person find(int id) { return ws.getPersonById(id); } } </code></pre> <p>hopefully it is clear that with this change, you can now create a mock and mock control for WebService and just plug it in in your test, because when you create the Person to test, you can pass in the mock to the constructor (or setter if you go that route).</p> <p>In your real environment, the IoC container will inject the real web service in.</p> <p>Now, if you don't want to deal with all this IoC stuff, what you need to do is decouple your webservice from your Person (which should be call PersonService or something, not just Person, which denotes entity). In other words, the way the code is written you can only use one type of WebService. You need to make it so the Person just needs <em>some</em> type of WebService, not the specific one you have hard-coded in.</p> <p>Finally, in the code as written, WebService is a class, not an interface. The WebService should be an interface, and you should put in some sort of implementation. EasyMock works well with interfaces; it might be able to mock concrete classes (been a while since I actually used it), but as a design principle you should specify the required interface, not the concrete class.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload