Skip to content

Commit

Permalink
Using InputComponent to unwrapper and added more assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jan 24, 2014
1 parent 9a936af commit 7e93dd4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.lang.reflect.Type;

import org.hibernate.validator.spi.valuehandling.ValidatedValueUnwrapper;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.input.InputComponent;

import com.fasterxml.classmate.ResolvedType;
import com.fasterxml.classmate.TypeResolver;
Expand All @@ -19,12 +19,12 @@
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public class InputComponentValueUnwrapper extends ValidatedValueUnwrapper<UIInput<?>>
public class InputComponentValueUnwrapper extends ValidatedValueUnwrapper<InputComponent<?,?>>
{
private final TypeResolver typeResolver = new TypeResolver();

@Override
public Object handleValidatedValue(UIInput<?> value)
public Object handleValidatedValue(InputComponent<?,?> value)
{
return value.getValue();
}
Expand All @@ -33,7 +33,7 @@ public Object handleValidatedValue(UIInput<?> value)
public Type getValidatedValueType(Type valueType)
{
ResolvedType resolvedType = typeResolver.resolve(valueType);
return resolvedType.typeParametersFor(UIInput.class).get(0).getErasedType();
return resolvedType.typeParametersFor(InputComponent.class).get(1).getErasedType();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public void testValidation() throws Exception
controller.setValueFor("name", "A Very Long String");
Assert.assertFalse("Controller should not be valid", controller.isValid());
List<UIMessage> messages = controller.validate();
Assert.assertFalse("An error should have been captured", messages.isEmpty());
Assert.assertEquals("An error should have been captured", 1, messages.size());
Assert.assertEquals("size must be between 1 and 5", messages.get(0).getDescription());
}
}
}

0 comments on commit 7e93dd4

Please sign in to comment.