Package de.cuioss.test.jsf.converter
Class AbstractConverterTest<C extends Converter,T>
- java.lang.Object
-
- de.cuioss.test.jsf.junit5.JsfEnabledTestEnvironment
-
- de.cuioss.test.jsf.converter.AbstractConverterTest<C,T>
-
- Type Parameters:
C- identifying the concreteConverterto be tested.T- identifying the type of elements to be used for values to be given to theConverter
- All Implemented Interfaces:
ComponentConfigurator,JsfTestContextConfigurator,JsfEnvironmentConsumer,de.cuioss.test.valueobjects.objects.ConfigurationCallBackHandler<C>
- Direct Known Subclasses:
AbstractSanitizingConverterTest
public abstract class AbstractConverterTest<C extends Converter,T> extends JsfEnabledTestEnvironment implements de.cuioss.test.valueobjects.objects.ConfigurationCallBackHandler<C>, ComponentConfigurator
Base class for testing implementations ofConverterwithin a Junit 5 contextSetup
The actual test must provide
EnableJsfEnvironment, for the basic test-infrastructure. See the class-documentation for details.initConverter(): Instantiates the concreteConverterusing reflection. After this the method callsConfigurationCallBackHandler.configure(Object)that can be used for further configuration of theConverterIn case you want you want to create the
Converteryourself you can overwritegetConverter()In case you want a pass another
UIComponentas parameter to theConverteryou can overwritegetComponent()Test-Methods
The core test-methods are:shouldFailOnInvalidObjects()shouldFailOnInvalidStrings()shouldPassOnValidObjects()shouldPassOnValidStrings()shouldRoundTripValidData()
populate(TestItems)in oder to create corresponding test-data. The implementation is in the actual test-class.API-Test
The api as defined withinConverteris tested with the methodsshouldFailOnNullComponentOnGetAsObject()shouldFailOnNullComponentOnGetAsString()shouldFailOnNullFacesContextOnGetAsObject()shouldFailOnNullFacesContextOnGetAsString()shouldReturnEmptyStringOnNullValue()
Example
Shows all variants of dealing withTestItems@EnableJsfEnvironment class IntegerConverterTest extends AbstractConverterTest<IntegerConverter, Integer> { @Override public void populate(final TestItems<Integer> testItems) { testItems.addRoundtripValues("1", "122", "2132121").addInvalidString("a") .addInvalidStringWithMessage("a", "javax.faces.converter.IntegerConverter.INTEGER") .addInvalidObject(Boolean.TRUE) .addInvalidObjectWithMessage(Boolean.FALSE, "javax.faces.converter.STRING") .addValidString("13").addValidStringWithObjectResult("17", Integer.valueOf(17)) .addValidObject(Integer.valueOf(2)) .addValidObjectWithStringResult(Integer.valueOf(14), "14"); }- Author:
- Oliver Wolff
-
-
Constructor Summary
Constructors Constructor Description AbstractConverterTest()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidconfigureComponents(ComponentConfigDecorator decorator)Callback method for interacting with theComponentConfigDecoratorat the correct time.
This method provide extension point to prepare needed test environment for your converter test.UIComponentgetComponent()CgetConverter()protected TestItems<T>getTestItems()protected voidinitConverter()Instantiates and initially configures a concreteConverterabstract voidpopulate(TestItems<T> testItems)Populates the test-itemsvoidsetComponent(UIComponent component)-
Methods inherited from class de.cuioss.test.jsf.junit5.JsfEnabledTestEnvironment
getEnvironmentHolder, setEnvironmentHolder
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.cuioss.test.valueobjects.objects.ConfigurationCallBackHandler
configure
-
Methods inherited from interface de.cuioss.test.jsf.util.JsfEnvironmentConsumer
assertNavigatedWithOutcome, assertRedirect, getApplication, getApplicationConfigDecorator, getBeanConfigDecorator, getComponentConfigDecorator, getExternalContext, getFacesContext, getRequestConfigDecorator, getResponse
-
-
-
-
Constructor Detail
-
AbstractConverterTest
public AbstractConverterTest()
-
-
Method Detail
-
initConverter
@BeforeEach protected void initConverter()
Instantiates and initially configures a concreteConverter
-
populate
public abstract void populate(TestItems<T> testItems)
Populates the test-items- Parameters:
testItems- to be populated, is never null
-
configureComponents
public void configureComponents(ComponentConfigDecorator decorator)
Callback method for interacting with theComponentConfigDecoratorat the correct time.
This method provide extension point to prepare needed test environment for your converter test. For example :// register some converter decorator.registerConverter(MyRequiredConverter.class); // register UIComponent ...- Specified by:
configureComponentsin interfaceComponentConfigurator- Parameters:
decorator-ComponentConfigDecoratoris never null
-
getComponent
public UIComponent getComponent()
-
setComponent
public void setComponent(UIComponent component)
-
getConverter
public C getConverter()
-
getTestItems
protected TestItems<T> getTestItems()
-
-