@Override public void setAsText(String text) throws IllegalArgumentException { Assert.isTrue(this.target instanceof ValueBean, "Target must be available"); super.setAsText(text); }
@Test public void testParseShortGreaterThanMaxValueWithoutNumberFormat() { try { CustomNumberEditor editor = new CustomNumberEditor(Short.class, true); editor.setAsText(String.valueOf(Short.MAX_VALUE + 1)); fail(Short.MAX_VALUE + 1 + " is greater than max value"); } catch (NumberFormatException ex) { // expected } }
@Test public void testCustomNumberEditorWithHex() { CustomNumberEditor editor = new CustomNumberEditor(Integer.class, false); editor.setAsText("0x" + Integer.toHexString(64)); assertEquals(new Integer(64), editor.getValue()); }
@Test public void testCustomNumberEditorWithEmptyAsNull() { CustomNumberEditor editor = new CustomNumberEditor(Integer.class, true); editor.setAsText("5"); assertEquals(new Integer(5), editor.getValue()); assertEquals("5", editor.getAsText()); editor.setAsText(""); assertEquals(null, editor.getValue()); assertEquals("", editor.getAsText()); editor.setValue(null); assertEquals(null, editor.getValue()); assertEquals("", editor.getAsText()); }
@Test public void testCustomNumberEditor() { CustomNumberEditor editor = new CustomNumberEditor(Integer.class, false); editor.setAsText("5"); assertEquals(new Integer(5), editor.getValue()); assertEquals("5", editor.getAsText()); editor.setValue(null); assertEquals(null, editor.getValue()); assertEquals("", editor.getAsText()); }