Java Doc for InjectModule.java in  » Testing » unitils » org » unitils » inject » 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 » unitils » org.unitils.inject 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.unitils.inject.InjectModule

InjectModule
public class InjectModule implements Module(Code)
Module for injecting annotated objects into other objects. The intended usage is to inject mock objects, but it can be used for regular objects too.

Both explicit injection and automatic injection by type are supported. An object annotated with InjectInto is explicitly injected into a target object. An object annotated with InjectIntoByType is automatically injected into a target property with the same type as the declared type of the annotated object.

Explicit and automatic injection into static fields is also supported, by means of the InjectIntoStatic and InjectIntoStaticByType annotations.

The target object can either be specified explicitly, or implicitly by annotating an object with TestedObject
author:
   Filip Neven
author:
   Tim Ducheyne


Inner Class :protected class InjectTestListener extends TestListener



Method Summary
protected  voidcreateObjectForField(Object testObject, Field testedObjectField)
    
public  TestListenercreateTestListener()
    
public  voidcreateTestedObjectsIfNull(Object testObject)
     For all fields annotated with TestedObject that are still null after the test fixture, an object is created of the field's declared type and assigned to the field.
protected  StringgetSituatedErrorMessage(Class<? extends Annotation> annotationClass, Field annotatedField, String errorDescription)
     Given the errorDescription, returns a situated error message, i.e.
protected  List<Object>getTargets(Class<? extends Annotation> annotationClass, Field annotatedField, String targetName, Object test)
     Returns the target(s) for the injection, given the specified name of the target and the test object.
public  voidinit(Properties configuration)
     Initializes this module using the given configuration.
protected  voidinject(Object test, Field fieldToInject)
     Injects the fieldToInject.
public  voidinjectAll(Object test)
     Injects all fields that are annotated with InjectInto .
public  voidinjectAllByType(Object test)
    
public  voidinjectAllStatic(Object test)
     Injects all fields that are annotated with InjectIntoStatic .
public  voidinjectAllStaticByType(Object test)
    
protected  voidinjectByType(Object test, Field fieldToInject)
     Auto-injects the fieldToInject by trying to match the fields declared type with a property of the target.
public  voidinjectObjects(Object test)
    
protected  voidinjectStatic(Object test, Field fieldToInjectStatic)
     Injects the fieldToAutoInjectStatic into the specified target class.
protected  voidinjectStaticByType(Object test, Field fieldToAutoInjectStatic)
     Auto-injects the fieldToInject by trying to match the fields declared type with a property of the target class.
protected  voidrestore(ValueToRestore valueToRestore)
     Restores the given value.
public  voidrestoreStaticInjectedObjects()
     Restores the values that were stored using InjectModule.storeValueToRestoreAfterTest .
protected  voidstoreValueToRestoreAfterTest(Class targetClass, String property, Class fieldType, PropertyAccess propertyAccess, Object oldValue, Restore restore)
     Stores the old value that was replaced during the injection so that it can be restored after the test was performed.



Method Detail
createObjectForField
protected void createObjectForField(Object testObject, Field testedObjectField)(Code)
Creates an objects of the given fields' declared type and assigns it to this field on the given testObject
Parameters:
  testObject - The test instance, not null
Parameters:
  testedObjectField - The tested object field, not null



createTestListener
public TestListener createTestListener()(Code)
The TestListener for this module



createTestedObjectsIfNull
public void createTestedObjectsIfNull(Object testObject)(Code)
For all fields annotated with TestedObject that are still null after the test fixture, an object is created of the field's declared type and assigned to the field. If the field's declared type is an interface or abstract class, or if the type doesn't have a default constructor, a warning is produced.
Parameters:
  testObject - The test instance, not null



getSituatedErrorMessage
protected String getSituatedErrorMessage(Class<? extends Annotation> annotationClass, Field annotatedField, String errorDescription)(Code)
Given the errorDescription, returns a situated error message, i.e. specifying the annotated field and the annotation type that was used.
Parameters:
  annotationClass - The injection annotation, not null
Parameters:
  annotatedField - The annotated field, not null
Parameters:
  errorDescription - A custom description, not null A situated error message



getTargets
protected List<Object> getTargets(Class<? extends Annotation> annotationClass, Field annotatedField, String targetName, Object test)(Code)
Returns the target(s) for the injection, given the specified name of the target and the test object. If targetName is not equal to an empty string, the targets are the testObject's fields that are annotated with TestedObject .
Parameters:
  annotationClass - The class of the annotation, not null
Parameters:
  annotatedField - The annotated field, not null
Parameters:
  targetName - The explicit target name or empty string for TestedObject targets
Parameters:
  test - The test instance The target(s) for the injection



init
public void init(Properties configuration)(Code)
Initializes this module using the given configuration.
Parameters:
  configuration - The configuration, not null



inject
protected void inject(Object test, Field fieldToInject)(Code)
Injects the fieldToInject. The target is either an explicitly specified target field of the test, or into the field(s) that is/are annotated with TestedObject
Parameters:
  test - The instance to inject into, not null
Parameters:
  fieldToInject - The field from which the value is injected into the target, not null



injectAll
public void injectAll(Object test)(Code)
Injects all fields that are annotated with InjectInto .
Parameters:
  test - The instance to inject into, not null



injectAllByType
public void injectAllByType(Object test)(Code)
Auto-injects all fields that are annotated with InjectIntoByType
Parameters:
  test - The instance to inject into, not null



injectAllStatic
public void injectAllStatic(Object test)(Code)
Injects all fields that are annotated with InjectIntoStatic .
Parameters:
  test - The instance to inject into, not null



injectAllStaticByType
public void injectAllStaticByType(Object test)(Code)
Auto-injects all fields that are annotated with InjectIntoStaticByType
Parameters:
  test - The instance to inject into, not null



injectByType
protected void injectByType(Object test, Field fieldToInject)(Code)
Auto-injects the fieldToInject by trying to match the fields declared type with a property of the target. The target is either an explicitly specified target field of the test, or the field(s) that is/are annotated with TestedObject
Parameters:
  test - The instance to inject into, not null
Parameters:
  fieldToInject - The field from which the value is injected into the target, not null



injectObjects
public void injectObjects(Object test)(Code)
Performs all supported kinds of injection on the given object's fields
Parameters:
  test - The instance to inject into, not null



injectStatic
protected void injectStatic(Object test, Field fieldToInjectStatic)(Code)
Injects the fieldToAutoInjectStatic into the specified target class.
Parameters:
  test - Instance to inject into, not null
Parameters:
  fieldToInjectStatic - The field from which the value is injected into the target, not null



injectStaticByType
protected void injectStaticByType(Object test, Field fieldToAutoInjectStatic)(Code)
Auto-injects the fieldToInject by trying to match the fields declared type with a property of the target class. The target is either an explicitly specified target field of the test, or the field that is annotated with TestedObject
Parameters:
  test - The instance to inject into, not null
Parameters:
  fieldToAutoInjectStatic - The field from which the value is injected into the target, not null



restore
protected void restore(ValueToRestore valueToRestore)(Code)
Restores the given value.
Parameters:
  valueToRestore - the value, not null



restoreStaticInjectedObjects
public void restoreStaticInjectedObjects()(Code)
Restores the values that were stored using InjectModule.storeValueToRestoreAfterTest .



storeValueToRestoreAfterTest
protected void storeValueToRestoreAfterTest(Class targetClass, String property, Class fieldType, PropertyAccess propertyAccess, Object oldValue, Restore restore)(Code)
Stores the old value that was replaced during the injection so that it can be restored after the test was performed. The value that is stored depends on the restore value: OLD_VALUE will store the value that was replaced, NULL_OR_0_VALUE will store 0 or null depeding whether it is a primitive or not, NO_RESTORE stores nothing.
Parameters:
  targetClass - The target class, not null
Parameters:
  property - The OGNL expression that defines where the object will be injected, null for auto inject
Parameters:
  fieldType - The type, not null
Parameters:
  propertyAccess - The access type in case auto injection is used
Parameters:
  oldValue - The value that was replaced during the injection
Parameters:
  restore - The type of reset, not DEFAULT



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.