1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.desc.impl;
17
18 import junit.framework.TestCase;
19
20 import org.seasar.uruma.annotation.InitializeMethod;
21 import org.seasar.uruma.desc.PartActionDesc;
22 import org.seasar.uruma.exception.IllegalMethodException;
23 import org.seasar.uruma.exception.InitializeMethodException;
24
25
26
27
28
29
30 public class PartActionDescImplTest extends TestCase {
31 public void testSetupInitializeMethod() throws Exception {
32 PartActionDesc target01 = new PartActionDescImpl(Target01.class);
33 assertEquals("1", Target01.class
34 .getMethod("initialize", (Class[]) null), target01
35 .getInitializeMethod());
36
37 try {
38 new PartActionDescImpl(Target02.class);
39 fail("2");
40 } catch (IllegalMethodException ex) {
41 assertTrue(true);
42 }
43
44 try {
45 new PartActionDescImpl(Target03.class);
46 fail("3");
47 } catch (IllegalMethodException ex) {
48 assertTrue(true);
49 }
50 }
51
52 public void testInvokeInitializeMethod() {
53 Target01 target01 = new Target01();
54 PartActionDesc target01Desc = new PartActionDescImpl(target01
55 .getClass());
56 target01Desc.invokeInitializeMethod(target01);
57 assertTrue(target01.invoked);
58 }
59
60 public void testInvokeInitializeMethodFail() {
61 Target04 target04 = new Target04();
62 PartActionDesc target04Desc = new PartActionDescImpl(target04
63 .getClass());
64 try {
65 target04Desc.invokeInitializeMethod(target04);
66 fail();
67 } catch (InitializeMethodException ex) {
68 assertTrue(true);
69 }
70 }
71
72 static class Target01 {
73 private boolean invoked;
74
75 @InitializeMethod
76 public void initialize() {
77 invoked = true;
78 }
79 }
80
81 static class Target02 {
82 @InitializeMethod
83 public void initialize1() {
84 }
85
86 @InitializeMethod
87 public void initialize2() {
88 }
89 }
90
91 static class Target03 {
92 @InitializeMethod
93 public int initialize(final int value) {
94 return value;
95 }
96 }
97
98 static class Target04 {
99 @InitializeMethod
100 public void initialize() {
101 throw new IllegalArgumentException();
102 }
103 }
104 }