01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.bind.handler;
16:
17: import static org.easymock.EasyMock.expect;
18: import static org.easymock.classextension.EasyMock.createStrictMock;
19: import static org.easymock.classextension.EasyMock.replay;
20: import static org.easymock.classextension.EasyMock.reset;
21: import static org.easymock.classextension.EasyMock.verify;
22: import static org.testng.Assert.*;
23:
24: import org.strecks.bind.handler.impl.TargetBean;
25: import org.strecks.converter.handler.ConversionHandler;
26: import org.strecks.exceptions.ApplicationRuntimeException;
27: import org.strecks.injection.factory.impl.IntToIntConverter;
28: import org.testng.annotations.Test;
29:
30: /**
31: * @author Phil Zoio
32: */
33: public class TestAbstractBindHandler {
34:
35: @Test
36: public void testInvalidOutwardConversion() {
37:
38: ConversionHandler conversionHandler = createStrictMock(ConversionHandler.class);
39:
40: IntToIntConverter converter = new IntToIntConverter();
41: BindSimpleHandler handler = new BindSimpleHandler();
42: TargetBean bean = new TargetBean();
43: bean.setStringProperty("2");
44: ApplicationRuntimeException exception = new ApplicationRuntimeException();
45:
46: handler.setConversionHandler(conversionHandler);
47:
48: expect(
49: handler.getAndConvertOutwards(bean, "stringProperty",
50: converter)).andThrow(exception);
51: replay(conversionHandler);
52:
53: try {
54: handler.getAndConvertOutwards(bean, "stringProperty",
55: converter);
56: fail();
57: } catch (ApplicationRuntimeException e) {
58: }
59:
60: verify(conversionHandler);
61: reset(conversionHandler);
62:
63: expect(
64: handler.getAndConvertInwards(bean, "stringProperty",
65: converter)).andThrow(exception);
66: replay(conversionHandler);
67:
68: try {
69: handler.getAndConvertInwards(bean, "stringProperty",
70: converter);
71: fail();
72: } catch (ApplicationRuntimeException e) {
73: }
74:
75: verify(conversionHandler);
76: }
77:
78: }
|