Package javango.forms.fields

Examples of javango.forms.fields.DoubleField


import javango.forms.tests.InjectedTestCaseBase;

public class DoubleFieldTest extends InjectedTestCaseBase {

  public void testRequired() throws Exception {
    DoubleField field = injector.getInstance(DoubleField.class);
    field.setName("fieldName");

    Map<String, String> errors = new HashMap<String, String>();
   
    Double value = field.clean(new String[]{""}, errors);
    assertFalse(errors.isEmpty());
    assertTrue(errors.containsKey(field.getName()));
    assertEquals(AbstractField.REQUIRED_ERROR, errors.get(field.getName()));
  }
View Full Code Here


    assertTrue(errors.containsKey(field.getName()));
    assertEquals(AbstractField.REQUIRED_ERROR, errors.get(field.getName()));
  }
 
  public void testNotRequired() throws Exception {
    DoubleField field = injector.getInstance(DoubleField.class);
    field.setName("fieldName");
    field.setRequired(false);
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Double value = field.clean(new String[]{""}, errors);
    assertTrue(errors.isEmpty());
  }
View Full Code Here

    Double value = field.clean(new String[]{""}, errors);
    assertTrue(errors.isEmpty());
  }

  public void testInvalid() throws Exception {
    DoubleField field = injector.getInstance(DoubleField.class);
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Double value = field.clean(new String[]{"qwert"}, errors);
    assertFalse(errors.isEmpty());
    assertTrue(errors.containsKey("fieldName"));
    assertEquals(DoubleField.ERROR_NUMBER_NOT_VALID, errors.get("fieldName"));
  }
View Full Code Here

    assertTrue(errors.containsKey("fieldName"));
    assertEquals(DoubleField.ERROR_NUMBER_NOT_VALID, errors.get("fieldName"));
  }

  public void testValid() throws Exception {
    DoubleField field = injector.getInstance(DoubleField.class);
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Double value = field.clean(new String[]{"1234.56"}, errors);
    assertTrue(errors.isEmpty());
    assertEquals(new Double(1234.56), value);
  }
View Full Code Here

    assertTrue(errors.isEmpty());
    assertEquals(new Double(1234.56), value);
  }

  public void testDecimalPlaces() throws Exception {
    DoubleField field = injector.getInstance(DoubleField.class);
    field.setDecimalPlaces(2);
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Double value = field.clean(new String[]{"1234.56"}, errors);
    assertTrue(errors.isEmpty());
  }
View Full Code Here

    Double value = field.clean(new String[]{"1234.56"}, errors);
    assertTrue(errors.isEmpty());
  }

  public void testTooFewDecimalPlaces() throws Exception {
    DoubleField field = injector.getInstance(DoubleField.class);
    field.setDecimalPlaces(2);
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Double value = field.clean(new String[]{"1234.5"}, errors);
    assertTrue(errors.isEmpty());
  }
View Full Code Here

    Double value = field.clean(new String[]{"1234.5"}, errors);
    assertTrue(errors.isEmpty());
  }
 
  public void testTooManyDecimalPlaces() throws Exception {
    DoubleField field = injector.getInstance(DoubleField.class);
    field.setDecimalPlaces(2);
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Double value = field.clean(new String[]{"1234.567"}, errors);
    assertFalse(errors.isEmpty());
    assertEquals(String.format(DoubleField.ERROR_MAX_DECIMAL_PLACES, 2), errors.get("fieldName"));
  }
View Full Code Here

    assertFalse(errors.isEmpty());
    assertEquals(String.format(DoubleField.ERROR_MAX_DECIMAL_PLACES, 2), errors.get("fieldName"));
  }

  public void testNoDecimalEntered() throws Exception {
    DoubleField field = injector.getInstance(DoubleField.class);
    field.setDecimalPlaces(2);
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Double value = field.clean(new String[]{"1234"}, errors);
    assertTrue(errors.isEmpty());
    assertEquals(new Double(1234), value)}
View Full Code Here

    Double value = field.clean(new String[]{"1234"}, errors);
    assertTrue(errors.isEmpty());
    assertEquals(new Double(1234), value)}
 
  public void testAnyDecimalPlaces() throws Exception {
    DoubleField field = injector.getInstance(DoubleField.class);
    field.setName("fieldName");
   
    Map<String, String> errors = new HashMap<String, String>();
   
    Double value = field.clean(new String[]{"1234.567"}, errors);
    assertTrue(errors.isEmpty());
    assertEquals(new Double(1234.567), value);
  }
View Full Code Here

TOP

Related Classes of javango.forms.fields.DoubleField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.