01: package org.strecks.lifecycle.impl;
02:
03: import static org.easymock.EasyMock.createMock;
04: import static org.easymock.EasyMock.isA;
05: import static org.easymock.EasyMock.replay;
06: import static org.easymock.EasyMock.verify;
07: import static org.testng.Assert.*;
08:
09: import java.lang.reflect.Method;
10:
11: import org.strecks.exceptions.ApplicationConfigurationException;
12: import org.strecks.lifecycle.LifecycleMethodAware;
13: import org.strecks.lifecycle.impl.LifecycleMethodReader;
14: import org.testng.annotations.BeforeMethod;
15: import org.testng.annotations.Test;
16:
17: public class TestInitMethodReader {
18:
19: private LifecycleMethodReader reader;
20:
21: @BeforeMethod
22: public void setUp() {
23: reader = new LifecycleMethodReader();
24: }
25:
26: @Test
27: public void testInitMethodReader() {
28: final boolean readAnnotations = reader
29: .readAnnotations(ActionWithLifecycleMethods.class);
30: assert readAnnotations;
31:
32: final LifecycleMethodAware initMethodAware = createMock(LifecycleMethodAware.class);
33: initMethodAware.setInitMethod(isA(Method.class));
34: initMethodAware.setCloseMethod(isA(Method.class));
35:
36: replay(initMethodAware);
37: reader.populateController(initMethodAware);
38: verify(initMethodAware);
39: }
40:
41: @Test
42: public void testWithArgs() {
43: try {
44: reader.readAnnotations(ActionWithInitMethodWithArgs.class);
45: fail();
46: } catch (ApplicationConfigurationException e) {
47: assertEquals(
48: e.getMessage(),
49: "InitMethod annotation used with method public void org.strecks.lifecycle.impl.ActionWithInitMethodWithArgs.initMethod(java.lang.String) cannot have parameters");
50: }
51: }
52:
53: @Test
54: public void testWithMultiMethods() {
55: try {
56: reader.readAnnotations(ActionWithMultiInitMethods.class);
57: fail();
58: } catch (ApplicationConfigurationException e) {
59: assertEquals(
60: e.getMessage(),
61: "InitMethod annotation used with method public void org.strecks.lifecycle.impl.ActionWithMultiInitMethods.initMethod1(java.lang.String) cannot have parameters");
62: }
63: }
64:
65: @Test
66: public void testWithReturnType() {
67: try {
68: reader
69: .readAnnotations(ActionWithInitMethodWithReturnType.class);
70: fail();
71: } catch (ApplicationConfigurationException e) {
72: assertEquals(
73: e.getMessage(),
74: "InitMethod annotation used with method public java.lang.String org.strecks.lifecycle.impl.ActionWithInitMethodWithReturnType.initMethod() cannot have a return type");
75: }
76: }
77:
78: }
|