1   /*
2    * Copyright 2005-2010 the original author or authors.
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  
17  package org.springframework.ws.test.support;
18  
19  import org.springframework.beans.factory.BeanInitializationException;
20  import org.springframework.context.support.StaticApplicationContext;
21  
22  import org.junit.Test;
23  
24  import static org.junit.Assert.assertNotNull;
25  import static org.junit.Assert.assertNull;
26  
27  public class MockStrategiesHelperTest {
28  
29      @Test
30      public void none() {
31          StaticApplicationContext applicationContext = new StaticApplicationContext();
32  
33          MockStrategiesHelper helper = new MockStrategiesHelper(applicationContext);
34          assertNull(helper.getStrategy(IMyBean.class));
35      }
36  
37      @Test
38      public void one() {
39          StaticApplicationContext applicationContext = new StaticApplicationContext();
40          applicationContext.registerSingleton("myBean", MyBean.class);
41  
42          MockStrategiesHelper helper = new MockStrategiesHelper(applicationContext);
43          assertNotNull(helper.getStrategy(IMyBean.class));
44      }
45  
46      @Test(expected = BeanInitializationException.class)
47      public void many() {
48          StaticApplicationContext applicationContext = new StaticApplicationContext();
49          applicationContext.registerSingleton("myBean1", MyBean.class);
50          applicationContext.registerSingleton("myBean2", MyBean.class);
51  
52          MockStrategiesHelper helper = new MockStrategiesHelper(applicationContext);
53          helper.getStrategy(IMyBean.class);
54      }
55      
56      @Test
57      public void noneWithDefault() {
58          StaticApplicationContext applicationContext = new StaticApplicationContext();
59  
60  
61          MockStrategiesHelper helper = new MockStrategiesHelper(applicationContext);
62          assertNotNull(helper.getStrategy(IMyBean.class, MyBean.class));
63      }
64  
65  
66      public interface IMyBean {
67  
68      }
69  
70      public static class MyBean implements IMyBean {
71  
72      }
73  
74  }