1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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   * {@link StructuredSelectionArgumentsFilter} のためのテストクラスです。<br />
29   * 
30   * @author y-komori
31   */
32  public class StructuredSelectionArgumentsFilterTest extends
33          AbstractArgumentFilterTest<StructuredSelectionArgumentsFilter> {
34  
35      /**
36       * {@link StructuredSelectionArgumentsFilter#filter(Object[])} メソッドのテストです。<br />
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       * {@link StructuredSelectionArgumentsFilter#filter(Object[])} メソッドのテストです。<br />
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       * {@link StructuredSelectionArgumentsFilter#filter(Object[])} メソッドのテストです。<br />
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       * {@link StructuredSelectionArgumentsFilter#filter(Object[])} メソッドのテストです。<br />
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       * {@link StructuredSelectionArgumentsFilter#filter(Object[])} メソッドのテストです。<br />
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      * @see org.seasar.uruma.binding.method.impl.AbstractArgumentFilterTest#getFilterType()
143      */
144     @Override
145     protected Class<StructuredSelectionArgumentsFilter> getFilterType() {
146         return StructuredSelectionArgumentsFilter.class;
147     }
148 }