org.unitils.io.annotation.handler
Class FileContentAnnotationHandler

java.lang.Object
  extended by org.unitils.core.TestListener
      extended by org.unitils.io.annotation.handler.FileContentAnnotationHandler

public class FileContentAnnotationHandler
extends TestListener

Implements the behavior of the FileContent annotation.
See annotation javadoc for more info.

Since:
3.3
Author:
Jeroen Horemans, Tim Ducheyne, Thomas De Rycke

Constructor Summary
FileContentAnnotationHandler(FileContentReader fileContentReader)
           
 
Method Summary
 void beforeTestSetUp(Object testObject, Method testMethod)
          All fields that have an FileContent annotation will be handled before the setup of the test.
protected  String determineEncoding(FileContent fileContentAnnotation)
           
protected  String determineFileName(FileContent fileContentAnnotation)
           
protected  void readFileContentForField(Object testObject, Field field)
          Does the actual content reading and injection for the given field.
 
Methods inherited from class org.unitils.core.TestListener
afterCreateTestObject, afterTestMethod, afterTestTearDown, beforeTestClass, beforeTestMethod
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileContentAnnotationHandler

public FileContentAnnotationHandler(FileContentReader fileContentReader)
Parameters:
fileContentReader - The content reader implementation, not null
Method Detail

beforeTestSetUp

public void beforeTestSetUp(Object testObject,
                            Method testMethod)
All fields that have an FileContent annotation will be handled before the setup of the test. This will convert the content of the requested file to the target type of the field and inject the result into the field.

Overrides:
beforeTestSetUp in class TestListener
Parameters:
testObject - The test instance, not null
testMethod - The test method, not null

readFileContentForField

protected void readFileContentForField(Object testObject,
                                       Field field)
Does the actual content reading and injection for the given field.

Parameters:
testObject - The test instance, not null
field - The field with the FileContent annotation, not null

determineEncoding

protected String determineEncoding(FileContent fileContentAnnotation)
Parameters:
fileContentAnnotation - The annotation, not null
Returns:
the encoding specified in the annotation, null if no encoding was specified

determineFileName

protected String determineFileName(FileContent fileContentAnnotation)
Parameters:
fileContentAnnotation - The annotation, not null
Returns:
the file name specified in the annotation, null if no file name was specified


Copyright © 2011. All Rights Reserved.