1   /*
2    * Copyright 2007-2008 Naoki NOSE.
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, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package jp.liq.container;
17  
18  import static org.junit.Assert.*;
19  
20  import java.util.HashSet;
21  import java.util.Map;
22  import java.util.Set;
23  
24  import org.junit.Before;
25  import org.junit.Test;
26  
27  import jp.liq.container.reflect.MethodWrapper;
28  import jp.liq.container.vocabulary.Factory;
29  
30  public class MethodFinderTest implements ContainerVocabulary {
31      private Set<String> methodNames;
32  
33      @Before
34      public void setUp() {
35          methodNames = new HashSet<String>();
36      }
37      public class Foo {
38          
39          public String createString() {
40              return null;
41          }
42  
43          @Factory
44          public Map<String, String> createMap() {
45              return null;
46          }
47  
48          public void hoge() {
49              
50          }
51      }
52  
53      @Test
54      public void findWithPrefix() {
55          methodNames.add("createString");
56          methodNames.add("createMap");
57          for(MethodWrapper m: methods.of(Foo.class).withPrefix("create")) {
58              assertTrue(methodNames.contains(m.name()));
59              methodNames.remove(m.name());
60          }
61          assertEquals(0, methodNames.size());
62      }
63  
64      
65  }