Java Doc for MockMethod.java in  » Testing » Surrogate » net » sf » surrogate » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » Surrogate » net.sf.surrogate.core 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   net.sf.surrogate.core.MockMethod

MockMethod
public class MockMethod implements SurrogateManager.MockExecutor(Code)
General mock class to mock a specific method. Useful to mock "final" methods where it is impossible to override the actual class with a Mock implementation.

Example:

 SurrogateManager manager = SurrogateManager.getInstance();
 manager.reset();
 MockMethod mockTime = new MockMethod(java.lang.System.class,"currentTimeMillis");
 manager.addMockMethod(mockTime);
 mockTime.addReturnValue(new Long(2000));
 mockTime.addReturnValue(new Long(4000));
 mockTime.setExpectedCalls(4);
 ...
 ...
 mockTime.verify();
 

Registers a mock method for the java.lang.System.currentTimeMillis method and specifies that the method should be called exactly four times, or else an error is generated. The first call returns "2000" and the next three calls return "4000"
See Also:   SurrogateManager.addMockMethod(MockMethod)
author:
   Per S Hustad




Constructor Summary
public  MockMethod(Class theClass, String method, Class[] parameterTypes)
     Mocks a method.
public  MockMethod(Class theClass, String method)
     Mocks a method.
public  MockMethod(Class theClass, Class[] parameterTypes)
     Mocks a constructor.

This method is useful when it has been impossible to generate a mock object for a class, e.g.


Method Summary
public  voidaddExpectedParameters(Object[] args)
     Sets up the next excpected arguments for the method.
public  voidaddReturnValue(Object o)
     Sets up the next return value of the mock method.
public  voidaddThrowableReturnValue(Throwable arg)
     Adds an errror to the list of return values.
Parameters:
  arg - the throwable to throw on the next call.
public  Objectexecute(Object[] args)
     Performs the actual method call.
 AccessibleObjectgetAccessibleObject()
    
public  voidreset()
     Resets the mock method counters, expectation values and stored actual values.
public  voidsetExpectedCalls(int expectedCalls)
     Sets the number of expected calls to this method.
public  StringtoString()
    
public  voidverify()
    


Constructor Detail
MockMethod
public MockMethod(Class theClass, String method, Class[] parameterTypes) throws NoSuchMethodException(Code)
Mocks a method. Useful if it has been impossible to generate a mock object for a class, e.g. the class contains final methods or we want to mock a static method.

Note that for methods to be substituted with their mock implementation, there must have been defined a pointcut intercepting the method call or method execution. Otherwise, the mock method will never be called, even if it has been registered. See net.sf.surrogate.core.SurrogateCalls for pointcut definition details.


Parameters:
  theClass - the class containing the method to mock.
Parameters:
  method - name of the method to mock. Must exist in the class.
Parameters:
  parameterTypes - the formal parameters to the method. E.g. if the method isdeclared asint foo(int count,Context ccx,Integer obj) theformal parameters will be{Integer.TYPE,Context.class,Integer.class}
throws:
  NoSuchMethodException - if the method cannot be found
See Also:   SurrogateManager.addMockMethod(MockMethod)




MockMethod
public MockMethod(Class theClass, String method) throws NoSuchMethodException(Code)
Mocks a method. This method is useful in the case where it has been impossible to generate a mock object for a class, e.g. the class contains final methods or we want to mock a static method.

Note that for methods to be substituted with their mock implementation, there must have been defined a pointcut intercepting the method call or method execution. Otherwise, the mock method will never be called, even if it has been registered. See SurrogateCalls for pointcut definition details.


Parameters:
  theClass - the class containing the method to mock.
Parameters:
  method - name of the method to mock. Must exist in the class andonly one method with that name must exist . If severaloverloaded methods exists with the same name, useMockMethod.MockMethod(Class,String,Class[])
throws:
  NoSuchMethodException - if the method cannot be found
throws:
  IllegalArgumentException - if more than one method exists with the name.
See Also:   MockMethod.MockMethod(Class,String,Class[])
See Also:   MockMethod.MockMethod(Class,Class[])
See Also:   SurrogateManager.addMockMethod(MockMethod)




MockMethod
public MockMethod(Class theClass, Class[] parameterTypes) throws NoSuchMethodException(Code)
Mocks a constructor.

This method is useful when it has been impossible to generate a mock object for a class, e.g. the class is final or the "real" constructor makes some unwanted procssing.

Note that for constructors to be substituted with their mock implementation, there must have been defined a pointcut intercepting the constructor call or execution. Otherwise, the mock method will never be called, even if it has been registered. See SurrogateCalls for pointcut definition details.

Note, that for mock constructors, the corresponding pointcut should be a call type pointcut if the corresponding MockMethod is to return some values. If the pointcut is "execution", the return values from the MockMethod will disappear somewhere in the VM ....
Parameters:
  theClass - the class containing the constructor to mock.
Parameters:
  parameterTypes - the formal parameters to the constructor. E.g. if theconstructor is declared asFoo(int count,Context ccx,Integer obj) theformal parameters will be{Integer.TYPE,Context.class,Integer.class}
throws:
  NoSuchMethodException - if the constructor cannot be found
See Also:   SurrogateManager.addMockMethod(MockMethod)





Method Detail
addExpectedParameters
public void addExpectedParameters(Object[] args)(Code)
Sets up the next excpected arguments for the method. The actual arguments are verified against the expected arguments when the actual method call is performed. If they mismatch, an Exception will be thrown.
Parameters:
  args - array of Object values. NB: must correspond to theformal parameter types of the method or else a runtimeexception will be thrown. Primitive types should beencapsulated in their corresponding Object representation,e.g. int corresponds to Integer
throws:
  IllegalArgumentException - if the number of aruments in args differs fromthe number of arguments in the underlying method orconstructor.



addReturnValue
public void addReturnValue(Object o)(Code)
Sets up the next return value of the mock method. If the method is called more times than the calls to this method, the last specified return value is used.
Parameters:
  o - the next return value. Primitive types are specified withtheir corresponding Object representation, e.g. an "int"corresponds to "Integer".
throws:
  IllegalArgumentException - if the underlying AccessibleObject is a method returningvoid
See Also:   MockMethod.addThrowableReturnValue(Throwable)



addThrowableReturnValue
public void addThrowableReturnValue(Throwable arg)(Code)
Adds an errror to the list of return values.
Parameters:
  arg - the throwable to throw on the next call. The mock method willthrow this throwable even if the actual method does notdeclare it ...
See Also:   MockMethod.addReturnValue(Object)



execute
public Object execute(Object[] args) throws Throwable(Code)
Performs the actual method call. This method should normally not be called from test harnesses. It is called from the Surrogate core framework
Parameters:
  args - the aruments to the method. Will be compared to the expectedvalues if such values have been specified. the return value given in MockMethod.addReturnValue(Object)unlessthe next return value has been set with theMockMethod.addThrowableReturnValue(Throwable)call. In this case,an Exception is thrown
throws:
  Throwable - if an exception has been set up inMockMethod.addThrowableReturnValue(Throwable) or if the number of parameters inargs does not match the number of parametersin the method signature



getAccessibleObject
AccessibleObject getAccessibleObject()(Code)
Gets the java reflection method or constructor the accessible object as specified in the constructor



reset
public void reset()(Code)
Resets the mock method counters, expectation values and stored actual values.



setExpectedCalls
public void setExpectedCalls(int expectedCalls)(Code)
Sets the number of expected calls to this method. The MockMethod.verify() method verifies the calls. Note that if you don't call this method after a reset or creation, the verify method will not check the actual calls.
Parameters:
  expectedCalls - the number of expected calls.
See Also:   MockMethod.verify()



toString
public String toString()(Code)
Gets a textual representation of this MockMethod the underlying method or constructor's toString



verify
public void verify()(Code)
Verifies that the method has been called as many times as specified in MockMethod.setExpectedCalls(int)
See Also:   MockMethod.setExpectedCalls(int)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.