01: package org.vraptor.converter.basic;
02:
03: import java.util.Arrays;
04:
05: import org.vraptor.AbstractTest;
06: import org.vraptor.LogicRequest;
07: import org.vraptor.converter.ConversionException;
08:
09: /**
10: * Testunit for its converter.
11: *
12: * @author Guilherme Silveira
13: */
14: public class SimpleIntegerConverterTest extends AbstractTest {
15:
16: public void testCanConvert() {
17: assert Arrays.deepEquals(new SimpleIntegerConverter()
18: .getSupportedTypes(), new Class[] { Integer.class });
19: }
20:
21: public void testConvert() throws ConversionException {
22: LogicRequest context = createLogicRequest();
23: assertEquals(500, new SimpleIntegerConverter().convert("500",
24: Integer.class, context));
25: }
26:
27: public void testConvertsNegative() throws ConversionException {
28: LogicRequest context = createLogicRequest();
29: assertEquals(-500, new SimpleIntegerConverter().convert("-500",
30: Integer.class, context));
31: }
32:
33: public void testConvertsZero() throws ConversionException {
34: LogicRequest context = createLogicRequest();
35: assertEquals(0, new SimpleIntegerConverter().convert("0",
36: Integer.class, context));
37: }
38:
39: public void testConvertionError() {
40: LogicRequest context = createLogicRequest();
41: try {
42: new SimpleIntegerConverter().convert("500.1",
43: Integer.class, context);
44: fail();
45: } catch (ConversionException e) {
46: // ok
47: }
48: }
49:
50: public void testConvertsNull() throws ConversionException {
51: LogicRequest context = createLogicRequest();
52: assertNull(new SimpleIntegerConverter().convert(null,
53: Integer.class, context));
54: }
55:
56: public void testConvertsEmpty() throws ConversionException {
57: LogicRequest context = createLogicRequest();
58: assertNull(new SimpleIntegerConverter().convert("",
59: Integer.class, context));
60: }
61: }
|