mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-05-23 00:00:05 -04:00
TMC-LANG: Code clean-up, added tests and fixed issues.
This commit is contained in:
+59
-1
@@ -1,10 +1,14 @@
|
||||
package com.twelvemonkeys.util.convert;
|
||||
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* DefaultConverterTestCase
|
||||
* <p/>
|
||||
@@ -56,7 +60,61 @@ public class DefaultConverterTestCase extends PropertyConverterAbstractTestCase
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Test boolean -> Boolean conversion
|
||||
@Test
|
||||
public void testConvertBooleanPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertTrue((Boolean) converter.toObject("true", boolean.class, null));
|
||||
assertFalse((Boolean) converter.toObject("FalsE", Boolean.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertShortPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1, (short) (Short) converter.toObject("1", short.class, null));
|
||||
assertEquals(-2, (short) (Short) converter.toObject("-2", Short.TYPE, null));
|
||||
}
|
||||
@Test
|
||||
public void testConvertIntPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1, (int) (Integer) converter.toObject("1", int.class, null));
|
||||
assertEquals(-2, (int) (Integer) converter.toObject("-2", Integer.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(Long.MAX_VALUE, (long) (Long) converter.toObject("9223372036854775807", long.class, null));
|
||||
assertEquals(-2, (long) (Long) converter.toObject("-2", Long.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertBytePrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1, (byte) (Byte) converter.toObject("1", byte.class, null));
|
||||
assertEquals(-2, (byte) (Byte) converter.toObject("-2", Byte.TYPE, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFloatPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1f, (Float) converter.toObject("1.0", float.class, null), 0);
|
||||
assertEquals(-2.3456f, (Float) converter.toObject("-2.3456", Float.TYPE, null), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertDoublePrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals(1d, (Double) converter.toObject("1.0", double.class, null), 0);
|
||||
assertEquals(-2.3456, (Double) converter.toObject("-2.3456", Double.TYPE, null), 0);
|
||||
}
|
||||
|
||||
@Ignore("Known issue. Why would anyone do something like this?")
|
||||
@Test
|
||||
public void testConvertCharPrimitive() {
|
||||
PropertyConverter converter = makePropertyConverter();
|
||||
assertEquals('A', (char) (Character) converter.toObject("A", char.class, null));
|
||||
assertEquals('Z', (char) (Character) converter.toObject("Z", Character.TYPE, null));
|
||||
}
|
||||
|
||||
public static class FooBar {
|
||||
private final String bar;
|
||||
|
||||
Reference in New Issue
Block a user