1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.binding.method.impl;
17
18 import java.lang.reflect.Method;
19 import java.util.Arrays;
20 import java.util.List;
21
22 import junitx.framework.ArrayAssert;
23
24 import org.eclipse.jface.viewers.StructuredSelection;
25 import org.seasar.uruma.exception.UIllegalArgumentException;
26
27
28
29
30
31
32 public class StructuredSelectionArgumentsFilterTest extends
33 AbstractArgumentFilterTest<StructuredSelectionArgumentsFilter> {
34
35
36
37
38 public void testFilter1() {
39 StructuredSelectionArgumentsFilter filter = createFilter("targetMethod1");
40
41 assertNull("1", filter.filter(null));
42
43 StructuredSelection selection = new StructuredSelection("arg");
44 assertNull("2", filter.filter(new Object[] { selection }));
45 }
46
47
48
49
50 public void testFilter2() {
51 StructuredSelectionArgumentsFilter filter = createFilter(
52 "targetMethod2", String.class);
53
54 StructuredSelection selection = new StructuredSelection("arg");
55
56 Object[] expected = new Object[] { "arg" };
57 Object[] actual = filter.filter(new Object[] { selection });
58 ArrayAssert.assertEquals(expected, actual);
59 }
60
61
62
63
64 public void testFilter3() {
65 StructuredSelectionArgumentsFilter filter = createFilter(
66 "targetMethod3", String[].class);
67
68 String[] args = new String[] { "arg1", "arg2", "arg3" };
69 StructuredSelection selection = new StructuredSelection(args);
70
71 Object[] expected = new Object[] { args };
72 Object[] actual = filter.filter(new Object[] { selection });
73 assertEquals(1, actual.length);
74 ArrayAssert.assertEquals((Object[]) expected[0], (Object[]) actual[0]);
75 }
76
77
78
79
80 public void testFilter4() {
81 StructuredSelectionArgumentsFilter filter = createFilter(
82 "targetMethod4", List.class);
83
84 String[] args = new String[] { "arg1", "arg2", "arg3" };
85 StructuredSelection selection = new StructuredSelection(args);
86
87 Object[] expected = new Object[] { Arrays.<String> asList(args) };
88 Object[] actual = filter.filter(new Object[] { selection });
89 ArrayAssert.assertEquals(expected, actual);
90 }
91
92
93
94
95 public void testFilter5() {
96 try {
97 Method method = desc.getMethod("targetMethod5", new Class[] {
98 String.class, String.class });
99 new StructuredSelectionArgumentsFilter(method);
100 fail();
101 } catch (UIllegalArgumentException ex) {
102 assertTrue(true);
103 }
104 }
105
106
107
108
109 public void targetMethod1() {
110
111 }
112
113
114
115
116 public void targetMethod2(final String arg) {
117
118 }
119
120
121
122
123 public void targetMethod3(final String[] arg) {
124
125 }
126
127
128
129
130 public void targetMethod4(final List<String> arg) {
131
132 }
133
134
135
136
137 public void targetMethod5(final String ng1, final String ng2) {
138
139 }
140
141
142
143
144 @Override
145 protected Class<StructuredSelectionArgumentsFilter> getFilterType() {
146 return StructuredSelectionArgumentsFilter.class;
147 }
148 }