01: package org.strecks.converter.handler;
02:
03: import org.strecks.bind.handler.impl.TargetBean;
04: import org.strecks.converter.handler.impl.IntToIntConverter;
05: import org.strecks.converter.handler.impl.StringToStringConverter;
06: import org.strecks.exceptions.ApplicationRuntimeException;
07: import org.testng.Assert;
08: import org.testng.annotations.Test;
09:
10: /**
11: * @author Phil Zoio
12: */
13: public class TestDefaultConversionHandler {
14:
15: @Test
16: public void testOutwardConversion() {
17: DefaultConversionHandler handler = new DefaultConversionHandler();
18: TargetBean bean = new TargetBean();
19: bean.setStringProperty("2");
20: Assert.assertEquals(handler.getAndConvertOutwards(bean,
21: "stringProperty", new StringToStringConverter()), "2");
22: }
23:
24: @Test
25: public void testInwardConversion() {
26: DefaultConversionHandler handler = new DefaultConversionHandler();
27: TargetBean bean = new TargetBean();
28: bean.setStringProperty("2");
29: Assert.assertEquals(handler.getAndConvertInwards(bean,
30: "stringProperty", new StringToStringConverter()), "2");
31: }
32:
33: @Test
34: public void testInvalidOutwardConversion() {
35: try {
36: DefaultConversionHandler handler = new DefaultConversionHandler();
37: TargetBean bean = new TargetBean();
38: bean.setStringProperty("2");
39: handler.getAndConvertOutwards(bean, "stringProperty",
40: new IntToIntConverter());
41: Assert.fail();
42: } catch (ApplicationRuntimeException e) {
43: Assert
44: .assertEquals(
45: e.getMessage(),
46: "Mismatch between parameterization type of converter: org.strecks.converter.handler.impl.IntToIntConverter((class java.lang.Integer, class java.lang.Integer))), and source type of property being converted: org.strecks.bind.handler.impl.TargetBean, property stringProperty (class java.lang.String)");
47: }
48: }
49:
50: @Test
51: public void testInvalidInwardConversion() {
52: try {
53: DefaultConversionHandler handler = new DefaultConversionHandler();
54: TargetBean bean = new TargetBean();
55: bean.setStringProperty("2");
56: handler.getAndConvertInwards(bean, "stringProperty",
57: new IntToIntConverter());
58: Assert.fail();
59: } catch (ApplicationRuntimeException e) {
60: Assert
61: .assertEquals(
62: e.getMessage(),
63: "Mismatch between parameterization type of converter: org.strecks.converter.handler.impl.IntToIntConverter((class java.lang.Integer, class java.lang.Integer))), and source type of property being converted: org.strecks.bind.handler.impl.TargetBean, property stringProperty (class java.lang.String)");
64: }
65: }
66: }
|