org.springframework.tests.sample.beans.NumberTestBean Java Examples
The following examples show how to use
org.springframework.tests.sample.beans.NumberTestBean.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomEditorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testCustomNumberEditorWithFrenchBigDecimal() throws Exception { NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH); NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, nf, true)); bw.setPropertyValue("bigDecimal", "1000"); assertEquals(1000.0f, tb.getBigDecimal().floatValue(), 0f); bw.setPropertyValue("bigDecimal", "1000,5"); assertEquals(1000.5f, tb.getBigDecimal().floatValue(), 0f); bw.setPropertyValue("bigDecimal", "1 000,5"); assertEquals(1000.5f, tb.getBigDecimal().floatValue(), 0f); }
Example #2
Source File: AbstractPropertyAccessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void setNumberPropertiesWithCoercion() { NumberTestBean target = new NumberTestBean(); AbstractPropertyAccessor accessor = createAccessor(target); try { accessor.setPropertyValue("short2", new Integer(2)); accessor.setPropertyValue("int2", new Long(8)); accessor.setPropertyValue("long2", new BigInteger("6")); accessor.setPropertyValue("bigInteger", new Integer(3)); accessor.setPropertyValue("float2", new Double(8.1)); accessor.setPropertyValue("double2", new BigDecimal(6.1)); accessor.setPropertyValue("bigDecimal", new Float(4.0)); } catch (BeansException ex) { fail("Should not throw BeansException: " + ex.getMessage()); } assertTrue("Correct short2 value", new Short("2").equals(accessor.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(target.getShort2())); assertTrue("Correct int2 value", new Integer("8").equals(accessor.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(target.getInt2())); assertTrue("Correct long2 value", new Long("6").equals(accessor.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(target.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(accessor.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(target.getBigInteger())); assertTrue("Correct float2 value", new Float("8.1").equals(accessor.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(target.getFloat2())); assertTrue("Correct double2 value", new Double("6.1").equals(accessor.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(target.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(target.getBigDecimal())); }
Example #3
Source File: AbstractPropertyAccessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void setNumberProperties() { NumberTestBean target = new NumberTestBean(); AbstractPropertyAccessor accessor = createAccessor(target); try { accessor.setPropertyValue("short2", "2"); accessor.setPropertyValue("int2", "8"); accessor.setPropertyValue("long2", "6"); accessor.setPropertyValue("bigInteger", "3"); accessor.setPropertyValue("float2", "8.1"); accessor.setPropertyValue("double2", "6.1"); accessor.setPropertyValue("bigDecimal", "4.0"); } catch (BeansException ex) { fail("Should not throw BeansException: " + ex.getMessage()); } assertTrue("Correct short2 value", new Short("2").equals(accessor.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(target.getShort2())); assertTrue("Correct int2 value", new Integer("8").equals(accessor.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(target.getInt2())); assertTrue("Correct long2 value", new Long("6").equals(accessor.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(target.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(accessor.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(target.getBigInteger())); assertTrue("Correct float2 value", new Float("8.1").equals(accessor.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(target.getFloat2())); assertTrue("Correct double2 value", new Double("6.1").equals(accessor.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(target.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(target.getBigDecimal())); }
Example #4
Source File: CustomEditorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testCustomNumberEditorWithFrenchBigDecimal() throws Exception { NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH); NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, nf, true)); bw.setPropertyValue("bigDecimal", "1000"); assertEquals(1000.0f, tb.getBigDecimal().floatValue(), 0f); bw.setPropertyValue("bigDecimal", "1000,5"); assertEquals(1000.5f, tb.getBigDecimal().floatValue(), 0f); bw.setPropertyValue("bigDecimal", "1 000,5"); assertEquals(1000.5f, tb.getBigDecimal().floatValue(), 0f); }
Example #5
Source File: CustomEditorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testCustomNumberEditorWithAllowEmpty() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN); NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(long.class, new CustomNumberEditor(Long.class, nf, true)); bw.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, true)); bw.setPropertyValue("long1", "5"); bw.setPropertyValue("long2", "6"); assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2())); bw.setPropertyValue("long2", ""); assertTrue("Correct long2 value", bw.getPropertyValue("long2") == null); assertTrue("Correct long2 value", tb.getLong2() == null); try { bw.setPropertyValue("long1", ""); fail("Should have thrown BeansException"); } catch (BeansException ex) { // expected assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); } }
Example #6
Source File: AbstractPropertyAccessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void setNumberPropertiesWithCoercion() { NumberTestBean target = new NumberTestBean(); AbstractPropertyAccessor accessor = createAccessor(target); try { accessor.setPropertyValue("short2", new Integer(2)); accessor.setPropertyValue("int2", new Long(8)); accessor.setPropertyValue("long2", new BigInteger("6")); accessor.setPropertyValue("bigInteger", new Integer(3)); accessor.setPropertyValue("float2", new Double(8.1)); accessor.setPropertyValue("double2", new BigDecimal(6.1)); accessor.setPropertyValue("bigDecimal", new Float(4.0)); } catch (BeansException ex) { fail("Should not throw BeansException: " + ex.getMessage()); } assertTrue("Correct short2 value", new Short("2").equals(accessor.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(target.getShort2())); assertTrue("Correct int2 value", new Integer("8").equals(accessor.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(target.getInt2())); assertTrue("Correct long2 value", new Long("6").equals(accessor.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(target.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(accessor.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(target.getBigInteger())); assertTrue("Correct float2 value", new Float("8.1").equals(accessor.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(target.getFloat2())); assertTrue("Correct double2 value", new Double("6.1").equals(accessor.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(target.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(target.getBigDecimal())); }
Example #7
Source File: AbstractPropertyAccessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void setNumberProperties() { NumberTestBean target = new NumberTestBean(); AbstractPropertyAccessor accessor = createAccessor(target); try { accessor.setPropertyValue("short2", "2"); accessor.setPropertyValue("int2", "8"); accessor.setPropertyValue("long2", "6"); accessor.setPropertyValue("bigInteger", "3"); accessor.setPropertyValue("float2", "8.1"); accessor.setPropertyValue("double2", "6.1"); accessor.setPropertyValue("bigDecimal", "4.0"); } catch (BeansException ex) { fail("Should not throw BeansException: " + ex.getMessage()); } assertTrue("Correct short2 value", new Short("2").equals(accessor.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(target.getShort2())); assertTrue("Correct int2 value", new Integer("8").equals(accessor.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(target.getInt2())); assertTrue("Correct long2 value", new Long("6").equals(accessor.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(target.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(accessor.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(target.getBigInteger())); assertTrue("Correct float2 value", new Float("8.1").equals(accessor.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(target.getFloat2())); assertTrue("Correct double2 value", new Double("6.1").equals(accessor.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(target.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(target.getBigDecimal())); }
Example #8
Source File: CustomEditorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testCustomNumberEditorWithAllowEmpty() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN); NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(long.class, new CustomNumberEditor(Long.class, nf, true)); bw.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, true)); bw.setPropertyValue("long1", "5"); bw.setPropertyValue("long2", "6"); assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2())); bw.setPropertyValue("long2", ""); assertTrue("Correct long2 value", bw.getPropertyValue("long2") == null); assertTrue("Correct long2 value", tb.getLong2() == null); try { bw.setPropertyValue("long1", ""); fail("Should have thrown BeansException"); } catch (BeansException ex) { // expected assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); } }
Example #9
Source File: AbstractPropertyAccessorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void setNumberPropertiesWithCoercion() { NumberTestBean target = new NumberTestBean(); AbstractPropertyAccessor accessor = createAccessor(target); try { accessor.setPropertyValue("short2", new Integer(2)); accessor.setPropertyValue("int2", new Long(8)); accessor.setPropertyValue("long2", new BigInteger("6")); accessor.setPropertyValue("bigInteger", new Integer(3)); accessor.setPropertyValue("float2", new Double(8.1)); accessor.setPropertyValue("double2", new BigDecimal(6.1)); accessor.setPropertyValue("bigDecimal", new Float(4.0)); } catch (BeansException ex) { fail("Should not throw BeansException: " + ex.getMessage()); } assertTrue("Correct short2 value", new Short("2").equals(accessor.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(target.getShort2())); assertTrue("Correct int2 value", new Integer("8").equals(accessor.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(target.getInt2())); assertTrue("Correct long2 value", new Long("6").equals(accessor.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(target.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(accessor.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(target.getBigInteger())); assertTrue("Correct float2 value", new Float("8.1").equals(accessor.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(target.getFloat2())); assertTrue("Correct double2 value", new Double("6.1").equals(accessor.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(target.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(target.getBigDecimal())); }
Example #10
Source File: AbstractPropertyAccessorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void setNumberProperties() { NumberTestBean target = new NumberTestBean(); AbstractPropertyAccessor accessor = createAccessor(target); try { accessor.setPropertyValue("short2", "2"); accessor.setPropertyValue("int2", "8"); accessor.setPropertyValue("long2", "6"); accessor.setPropertyValue("bigInteger", "3"); accessor.setPropertyValue("float2", "8.1"); accessor.setPropertyValue("double2", "6.1"); accessor.setPropertyValue("bigDecimal", "4.0"); } catch (BeansException ex) { fail("Should not throw BeansException: " + ex.getMessage()); } assertTrue("Correct short2 value", new Short("2").equals(accessor.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(target.getShort2())); assertTrue("Correct int2 value", new Integer("8").equals(accessor.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(target.getInt2())); assertTrue("Correct long2 value", new Long("6").equals(accessor.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(target.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(accessor.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(target.getBigInteger())); assertTrue("Correct float2 value", new Float("8.1").equals(accessor.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(target.getFloat2())); assertTrue("Correct double2 value", new Double("6.1").equals(accessor.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(target.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(accessor.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.0").equals(target.getBigDecimal())); }
Example #11
Source File: CustomEditorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testCustomNumberEditorWithFrenchBigDecimal() throws Exception { NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH); NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, nf, true)); bw.setPropertyValue("bigDecimal", "1000"); assertEquals(1000.0f, tb.getBigDecimal().floatValue(), 0f); bw.setPropertyValue("bigDecimal", "1000,5"); assertEquals(1000.5f, tb.getBigDecimal().floatValue(), 0f); bw.setPropertyValue("bigDecimal", "1 000,5"); assertEquals(1000.5f, tb.getBigDecimal().floatValue(), 0f); }
Example #12
Source File: CustomEditorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testCustomNumberEditorWithAllowEmpty() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN); NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(long.class, new CustomNumberEditor(Long.class, nf, true)); bw.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, true)); bw.setPropertyValue("long1", "5"); bw.setPropertyValue("long2", "6"); assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2())); bw.setPropertyValue("long2", ""); assertTrue("Correct long2 value", bw.getPropertyValue("long2") == null); assertTrue("Correct long2 value", tb.getLong2() == null); try { bw.setPropertyValue("long1", ""); fail("Should have thrown BeansException"); } catch (BeansException ex) { // expected assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); } }
Example #13
Source File: CustomEditorTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void testCustomNumberEditorWithoutAllowEmpty() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN); NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(short.class, new CustomNumberEditor(Short.class, nf, false)); bw.registerCustomEditor(Short.class, new CustomNumberEditor(Short.class, nf, false)); bw.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, nf, false)); bw.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, nf, false)); bw.registerCustomEditor(long.class, new CustomNumberEditor(Long.class, nf, false)); bw.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, false)); bw.registerCustomEditor(BigInteger.class, new CustomNumberEditor(BigInteger.class, nf, false)); bw.registerCustomEditor(float.class, new CustomNumberEditor(Float.class, nf, false)); bw.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, false)); bw.registerCustomEditor(double.class, new CustomNumberEditor(Double.class, nf, false)); bw.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, nf, false)); bw.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, nf, false)); bw.setPropertyValue("short1", "1"); bw.setPropertyValue("short2", "2"); bw.setPropertyValue("int1", "7"); bw.setPropertyValue("int2", "8"); bw.setPropertyValue("long1", "5"); bw.setPropertyValue("long2", "6"); bw.setPropertyValue("bigInteger", "3"); bw.setPropertyValue("float1", "7,1"); bw.setPropertyValue("float2", "8,1"); bw.setPropertyValue("double1", "5,1"); bw.setPropertyValue("double2", "6,1"); bw.setPropertyValue("bigDecimal", "4,5"); assertTrue("Correct short1 value", new Short("1").equals(bw.getPropertyValue("short1"))); assertTrue("Correct short1 value", tb.getShort1() == 1); assertTrue("Correct short2 value", new Short("2").equals(bw.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(tb.getShort2())); assertTrue("Correct int1 value", new Integer("7").equals(bw.getPropertyValue("int1"))); assertTrue("Correct int1 value", tb.getInt1() == 7); assertTrue("Correct int2 value", new Integer("8").equals(bw.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(tb.getInt2())); assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(tb.getBigInteger())); assertTrue("Correct float1 value", new Float("7.1").equals(bw.getPropertyValue("float1"))); assertTrue("Correct float1 value", new Float("7.1").equals(new Float(tb.getFloat1()))); assertTrue("Correct float2 value", new Float("8.1").equals(bw.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(tb.getFloat2())); assertTrue("Correct double1 value", new Double("5.1").equals(bw.getPropertyValue("double1"))); assertTrue("Correct double1 value", tb.getDouble1() == 5.1); assertTrue("Correct double2 value", new Double("6.1").equals(bw.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(tb.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(tb.getBigDecimal())); }
Example #14
Source File: CustomEditorTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void testDefaultNumberEditor() { NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.setPropertyValue("short1", "1"); bw.setPropertyValue("short2", "2"); bw.setPropertyValue("int1", "7"); bw.setPropertyValue("int2", "8"); bw.setPropertyValue("long1", "5"); bw.setPropertyValue("long2", "6"); bw.setPropertyValue("bigInteger", "3"); bw.setPropertyValue("float1", "7.1"); bw.setPropertyValue("float2", "8.1"); bw.setPropertyValue("double1", "5.1"); bw.setPropertyValue("double2", "6.1"); bw.setPropertyValue("bigDecimal", "4.5"); assertTrue("Correct short1 value", new Short("1").equals(bw.getPropertyValue("short1"))); assertTrue("Correct short1 value", tb.getShort1() == 1); assertTrue("Correct short2 value", new Short("2").equals(bw.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(tb.getShort2())); assertTrue("Correct int1 value", new Integer("7").equals(bw.getPropertyValue("int1"))); assertTrue("Correct int1 value", tb.getInt1() == 7); assertTrue("Correct int2 value", new Integer("8").equals(bw.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(tb.getInt2())); assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(tb.getBigInteger())); assertTrue("Correct float1 value", new Float("7.1").equals(bw.getPropertyValue("float1"))); assertTrue("Correct float1 value", new Float("7.1").equals(new Float(tb.getFloat1()))); assertTrue("Correct float2 value", new Float("8.1").equals(bw.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(tb.getFloat2())); assertTrue("Correct double1 value", new Double("5.1").equals(bw.getPropertyValue("double1"))); assertTrue("Correct double1 value", tb.getDouble1() == 5.1); assertTrue("Correct double2 value", new Double("6.1").equals(bw.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(tb.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(tb.getBigDecimal())); }
Example #15
Source File: CustomEditorTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void testDefaultNumberEditor() { NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.setPropertyValue("short1", "1"); bw.setPropertyValue("short2", "2"); bw.setPropertyValue("int1", "7"); bw.setPropertyValue("int2", "8"); bw.setPropertyValue("long1", "5"); bw.setPropertyValue("long2", "6"); bw.setPropertyValue("bigInteger", "3"); bw.setPropertyValue("float1", "7.1"); bw.setPropertyValue("float2", "8.1"); bw.setPropertyValue("double1", "5.1"); bw.setPropertyValue("double2", "6.1"); bw.setPropertyValue("bigDecimal", "4.5"); assertTrue("Correct short1 value", new Short("1").equals(bw.getPropertyValue("short1"))); assertTrue("Correct short1 value", tb.getShort1() == 1); assertTrue("Correct short2 value", new Short("2").equals(bw.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(tb.getShort2())); assertTrue("Correct int1 value", new Integer("7").equals(bw.getPropertyValue("int1"))); assertTrue("Correct int1 value", tb.getInt1() == 7); assertTrue("Correct int2 value", new Integer("8").equals(bw.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(tb.getInt2())); assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(tb.getBigInteger())); assertTrue("Correct float1 value", new Float("7.1").equals(bw.getPropertyValue("float1"))); assertTrue("Correct float1 value", new Float("7.1").equals(new Float(tb.getFloat1()))); assertTrue("Correct float2 value", new Float("8.1").equals(bw.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(tb.getFloat2())); assertTrue("Correct double1 value", new Double("5.1").equals(bw.getPropertyValue("double1"))); assertTrue("Correct double1 value", tb.getDouble1() == 5.1); assertTrue("Correct double2 value", new Double("6.1").equals(bw.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(tb.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(tb.getBigDecimal())); }
Example #16
Source File: CustomEditorTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void testDefaultNumberEditor() { NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.setPropertyValue("short1", "1"); bw.setPropertyValue("short2", "2"); bw.setPropertyValue("int1", "7"); bw.setPropertyValue("int2", "8"); bw.setPropertyValue("long1", "5"); bw.setPropertyValue("long2", "6"); bw.setPropertyValue("bigInteger", "3"); bw.setPropertyValue("float1", "7.1"); bw.setPropertyValue("float2", "8.1"); bw.setPropertyValue("double1", "5.1"); bw.setPropertyValue("double2", "6.1"); bw.setPropertyValue("bigDecimal", "4.5"); assertTrue("Correct short1 value", new Short("1").equals(bw.getPropertyValue("short1"))); assertTrue("Correct short1 value", tb.getShort1() == 1); assertTrue("Correct short2 value", new Short("2").equals(bw.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(tb.getShort2())); assertTrue("Correct int1 value", new Integer("7").equals(bw.getPropertyValue("int1"))); assertTrue("Correct int1 value", tb.getInt1() == 7); assertTrue("Correct int2 value", new Integer("8").equals(bw.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(tb.getInt2())); assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(tb.getBigInteger())); assertTrue("Correct float1 value", new Float("7.1").equals(bw.getPropertyValue("float1"))); assertTrue("Correct float1 value", new Float("7.1").equals(new Float(tb.getFloat1()))); assertTrue("Correct float2 value", new Float("8.1").equals(bw.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(tb.getFloat2())); assertTrue("Correct double1 value", new Double("5.1").equals(bw.getPropertyValue("double1"))); assertTrue("Correct double1 value", tb.getDouble1() == 5.1); assertTrue("Correct double2 value", new Double("6.1").equals(bw.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(tb.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(tb.getBigDecimal())); }
Example #17
Source File: CustomEditorTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void testCustomNumberEditorWithoutAllowEmpty() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN); NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(short.class, new CustomNumberEditor(Short.class, nf, false)); bw.registerCustomEditor(Short.class, new CustomNumberEditor(Short.class, nf, false)); bw.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, nf, false)); bw.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, nf, false)); bw.registerCustomEditor(long.class, new CustomNumberEditor(Long.class, nf, false)); bw.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, false)); bw.registerCustomEditor(BigInteger.class, new CustomNumberEditor(BigInteger.class, nf, false)); bw.registerCustomEditor(float.class, new CustomNumberEditor(Float.class, nf, false)); bw.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, false)); bw.registerCustomEditor(double.class, new CustomNumberEditor(Double.class, nf, false)); bw.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, nf, false)); bw.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, nf, false)); bw.setPropertyValue("short1", "1"); bw.setPropertyValue("short2", "2"); bw.setPropertyValue("int1", "7"); bw.setPropertyValue("int2", "8"); bw.setPropertyValue("long1", "5"); bw.setPropertyValue("long2", "6"); bw.setPropertyValue("bigInteger", "3"); bw.setPropertyValue("float1", "7,1"); bw.setPropertyValue("float2", "8,1"); bw.setPropertyValue("double1", "5,1"); bw.setPropertyValue("double2", "6,1"); bw.setPropertyValue("bigDecimal", "4,5"); assertTrue("Correct short1 value", new Short("1").equals(bw.getPropertyValue("short1"))); assertTrue("Correct short1 value", tb.getShort1() == 1); assertTrue("Correct short2 value", new Short("2").equals(bw.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(tb.getShort2())); assertTrue("Correct int1 value", new Integer("7").equals(bw.getPropertyValue("int1"))); assertTrue("Correct int1 value", tb.getInt1() == 7); assertTrue("Correct int2 value", new Integer("8").equals(bw.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(tb.getInt2())); assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(tb.getBigInteger())); assertTrue("Correct float1 value", new Float("7.1").equals(bw.getPropertyValue("float1"))); assertTrue("Correct float1 value", new Float("7.1").equals(new Float(tb.getFloat1()))); assertTrue("Correct float2 value", new Float("8.1").equals(bw.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(tb.getFloat2())); assertTrue("Correct double1 value", new Double("5.1").equals(bw.getPropertyValue("double1"))); assertTrue("Correct double1 value", tb.getDouble1() == 5.1); assertTrue("Correct double2 value", new Double("6.1").equals(bw.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(tb.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(tb.getBigDecimal())); }
Example #18
Source File: CustomEditorTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void testCustomNumberEditorWithoutAllowEmpty() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN); NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(short.class, new CustomNumberEditor(Short.class, nf, false)); bw.registerCustomEditor(Short.class, new CustomNumberEditor(Short.class, nf, false)); bw.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, nf, false)); bw.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, nf, false)); bw.registerCustomEditor(long.class, new CustomNumberEditor(Long.class, nf, false)); bw.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, false)); bw.registerCustomEditor(BigInteger.class, new CustomNumberEditor(BigInteger.class, nf, false)); bw.registerCustomEditor(float.class, new CustomNumberEditor(Float.class, nf, false)); bw.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, false)); bw.registerCustomEditor(double.class, new CustomNumberEditor(Double.class, nf, false)); bw.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, nf, false)); bw.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, nf, false)); bw.setPropertyValue("short1", "1"); bw.setPropertyValue("short2", "2"); bw.setPropertyValue("int1", "7"); bw.setPropertyValue("int2", "8"); bw.setPropertyValue("long1", "5"); bw.setPropertyValue("long2", "6"); bw.setPropertyValue("bigInteger", "3"); bw.setPropertyValue("float1", "7,1"); bw.setPropertyValue("float2", "8,1"); bw.setPropertyValue("double1", "5,1"); bw.setPropertyValue("double2", "6,1"); bw.setPropertyValue("bigDecimal", "4,5"); assertTrue("Correct short1 value", new Short("1").equals(bw.getPropertyValue("short1"))); assertTrue("Correct short1 value", tb.getShort1() == 1); assertTrue("Correct short2 value", new Short("2").equals(bw.getPropertyValue("short2"))); assertTrue("Correct short2 value", new Short("2").equals(tb.getShort2())); assertTrue("Correct int1 value", new Integer("7").equals(bw.getPropertyValue("int1"))); assertTrue("Correct int1 value", tb.getInt1() == 7); assertTrue("Correct int2 value", new Integer("8").equals(bw.getPropertyValue("int2"))); assertTrue("Correct int2 value", new Integer("8").equals(tb.getInt2())); assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1"))); assertTrue("Correct long1 value", tb.getLong1() == 5); assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2"))); assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2())); assertTrue("Correct bigInteger value", new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))); assertTrue("Correct bigInteger value", new BigInteger("3").equals(tb.getBigInteger())); assertTrue("Correct float1 value", new Float("7.1").equals(bw.getPropertyValue("float1"))); assertTrue("Correct float1 value", new Float("7.1").equals(new Float(tb.getFloat1()))); assertTrue("Correct float2 value", new Float("8.1").equals(bw.getPropertyValue("float2"))); assertTrue("Correct float2 value", new Float("8.1").equals(tb.getFloat2())); assertTrue("Correct double1 value", new Double("5.1").equals(bw.getPropertyValue("double1"))); assertTrue("Correct double1 value", tb.getDouble1() == 5.1); assertTrue("Correct double2 value", new Double("6.1").equals(bw.getPropertyValue("double2"))); assertTrue("Correct double2 value", new Double("6.1").equals(tb.getDouble2())); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))); assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(tb.getBigDecimal())); }