Package jodd.typeconverter.impl

Examples of jodd.typeconverter.impl.ByteConverter


    LongConverter longConverter = new LongConverter();
    register(Long.class, longConverter);
    register(long.class, longConverter);
    register(MutableLong.class, new MutableLongConverter(this));

    ByteConverter byteConverter = new ByteConverter();
    register(Byte.class, byteConverter);
    register(byte.class, byteConverter);
    register(MutableByte.class, new MutableByteConverter(this));

    FloatConverter floatConverter = new FloatConverter();
View Full Code Here


public class ByteConverterTest {

  @Test
  public void testConversion() {
    ByteConverter byteConverter = new ByteConverter();

    assertNull(byteConverter.convert(null));

    assertEquals(Byte.valueOf((byte) 1), byteConverter.convert(Integer.valueOf(1)));
    assertEquals(Byte.valueOf((byte) 1), byteConverter.convert(Short.valueOf((short) 1)));
    assertEquals(Byte.valueOf((byte) 1), byteConverter.convert(Double.valueOf(1.5D)));
    assertEquals(Byte.valueOf((byte) 1), byteConverter.convert("1"));
    assertEquals(Byte.valueOf((byte) 1), byteConverter.convert("  1  "));
    assertEquals(Byte.valueOf((byte) 1), byteConverter.convert("  +1  "));
    assertEquals(Byte.valueOf((byte) 127), byteConverter.convert("  +127  "));
    assertEquals(Byte.valueOf((byte) -1), byteConverter.convert("  -1  "));
    assertEquals(Byte.valueOf((byte) -128), byteConverter.convert("  -128  "));
    assertEquals(Byte.valueOf((byte) (300 - 256)), byteConverter.convert(Integer.valueOf(300)));

    try {
      assertEquals(Byte.valueOf((byte) 1), byteConverter.convert("1.5"));
      fail();
    } catch (TypeConversionException ignore) {
    }

    try {
      byteConverter.convert("a");
      fail();
    } catch (TypeConversionException ignore) {
    }

    try {
      byteConverter.convert("128");
      fail();
    } catch (TypeConversionException ignore) {
    }
    try {
      byteConverter.convert("-129");
      fail();
    } catch (TypeConversionException ignore) {
    }
  }
View Full Code Here

    LongConverter longConverter = new LongConverter();
    register(Long.class, longConverter);
    register(long.class, longConverter);
    register(MutableLong.class, new MutableLongConverter(this));

    ByteConverter byteConverter = new ByteConverter();
    register(Byte.class, byteConverter);
    register(byte.class, byteConverter);
    register(MutableByte.class, new MutableByteConverter(this));

    FloatConverter floatConverter = new FloatConverter();
View Full Code Here

TOP

Related Classes of jodd.typeconverter.impl.ByteConverter

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.