Package jodd.typeconverter

Source Code of jodd.typeconverter.ShortConverterTest

// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.typeconverter;

import jodd.typeconverter.impl.ShortConverter;
import org.junit.Test;

import static org.junit.Assert.*;

public class ShortConverterTest {

  @Test
  public void testConversion() {
    ShortConverter shortConverter = new ShortConverter();

    assertNull(shortConverter.convert(null));

    assertEquals(Short.valueOf((short) 1), shortConverter.convert(Short.valueOf((short) 1)));
    assertEquals(Short.valueOf((short) 1), shortConverter.convert(Integer.valueOf(1)));
    assertEquals(Short.valueOf((short) 1), shortConverter.convert(Double.valueOf(1.0D)));
    assertEquals(Short.valueOf((short) 1), shortConverter.convert("1"));
    assertEquals(Short.valueOf((short) 1), shortConverter.convert(" 1 "));

    assertEquals(Short.valueOf((short) 1), shortConverter.convert(" +1 "));
    assertEquals(Short.valueOf((short) -1), shortConverter.convert(" -1 "));
    assertEquals(Short.valueOf((short) 32767), shortConverter.convert(" +32767 "));
    assertEquals(Short.valueOf((short) -32768), shortConverter.convert(" -32768 "));

    try {
      shortConverter.convert("a");
      fail();
    } catch (TypeConversionException ignore) {
    }
    try {
      shortConverter.convert("+32768");
      fail();
    } catch (TypeConversionException ignore) {
    }
    try {
      shortConverter.convert("-32769");
      fail();
    } catch (TypeConversionException ignore) {
    }
  }
}
TOP

Related Classes of jodd.typeconverter.ShortConverterTest

TOP
Copyright © 2018 www.massapi.com. 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.