Search in sources :

Example 11 with AvailableValues

use of org.apache.tapestry5.commons.util.AvailableValues in project tapestry-5 by apache.

the class EnumValueEncoderTest method valid_values_can_be_retrieved_from_exception.

@Test
public // TAP5-1331
void valid_values_can_be_retrieved_from_exception() {
    TypeCoercer typeCoercer = getService(TypeCoercer.class);
    EnumValueEncoder<Stooge> encoder = new EnumValueEncoder<Stooge>(typeCoercer, Stooge.class);
    try {
        encoder.toValue("Foo");
        fail();
    } catch (RuntimeException e) {
        assertTrue(e.getCause() instanceof UnknownValueException);
        UnknownValueException cause = (UnknownValueException) e.getCause();
        List<String> availableValues = cause.getAvailableValues().getValues();
        assertTrue(availableValues.contains("MOE"));
        assertTrue(availableValues.contains("LARRY"));
        assertTrue(availableValues.contains("CURLY_JOE"));
    }
}
Also used : TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) List(java.util.List) Test(org.testng.annotations.Test)

Aggregations

UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)10 AvailableValues (org.apache.tapestry5.commons.util.AvailableValues)9 Binding (org.apache.tapestry5.Binding)2 LiteralBinding (org.apache.tapestry5.internal.bindings.LiteralBinding)2 List (java.util.List)1 MarkupWriter (org.apache.tapestry5.MarkupWriter)1 Location (org.apache.tapestry5.commons.Location)1 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)1 Mapper (org.apache.tapestry5.func.Mapper)1 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)1 AvailableValuesRenderer (org.apache.tapestry5.internal.renderers.AvailableValuesRenderer)1 JSONObject (org.apache.tapestry5.json.JSONObject)1 ComponentModel (org.apache.tapestry5.model.ComponentModel)1 EmbeddedComponentModel (org.apache.tapestry5.model.EmbeddedComponentModel)1 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)1 AssetAlias (org.apache.tapestry5.services.AssetAlias)1 DefaultObjectRenderer (org.apache.tapestry5.services.DefaultObjectRenderer)1 ObjectRenderer (org.apache.tapestry5.services.ObjectRenderer)1 Test (org.testng.annotations.Test)1