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.cubby.controller.impl;
17  
18  import static org.seasar.cubby.TestUtils.getPrivateField;
19  
20  import java.util.Map;
21  
22  import junit.framework.TestCase;
23  
24  import org.seasar.cubby.dxo.FormDxo;
25  
26  public class ActionContextImplTest extends TestCase {
27  
28      public void testConstructor() throws Throwable {
29          ActionContextImpl actionContextImpl = new ActionContextImpl();
30          assertFalse("actionContextImpl.isInitialized()", actionContextImpl.isInitialized());
31      }
32      
33      public void testInitialize() throws Throwable {
34          ActionContextImpl actionContextImpl = new ActionContextImpl();
35          actionContextImpl.initialize(null);
36          assertFalse("actionContextImpl.isInitialized()", actionContextImpl.isInitialized());
37      }
38      
39      public void testIsInitialized() throws Throwable {
40          boolean result = new ActionContextImpl().isInitialized();
41          assertFalse("result", result);
42      }
43      
44      public void testSetParameterBinder() throws Throwable {
45          FormDxo formDxo = new FormDxo() {
46  			public void convert(Map<String, Object[]> src, Object dest) {
47  			}
48  			public void convert(Object src, Map<String, String[]> dest) {
49  			}
50          };
51          ActionContextImpl actionContextImpl = new ActionContextImpl();
52          actionContextImpl.setFormDxo(formDxo);
53          assertSame("actionContextImpl.getParameterBinder()", formDxo, actionContextImpl.getFormDxo());
54      }
55      
56      public void testGetActionThrowsNullPointerException() throws Throwable {
57          ActionContextImpl actionContextImpl = new ActionContextImpl();
58          try {
59              actionContextImpl.getAction();
60              fail("Expected NullPointerException to be thrown");
61          } catch (NullPointerException ex) {
62              assertNull("ex.getMessage()", ex.getMessage());
63              assertNull("actionContextImpl.action", getPrivateField(actionContextImpl, "action"));
64              assertFalse("actionContextImpl.isInitialized()", actionContextImpl.isInitialized());
65          }
66      }
67      
68      public void testGetComponentDefThrowsNullPointerException() throws Throwable {
69          ActionContextImpl actionContextImpl = new ActionContextImpl();
70          try {
71              actionContextImpl.getComponentDef();
72              fail("Expected NullPointerException to be thrown");
73          } catch (NullPointerException ex) {
74              assertNull("ex.getMessage()", ex.getMessage());
75              assertFalse("actionContextImpl.isInitialized()", actionContextImpl.isInitialized());
76          }
77      }
78      
79      public void testGetFormBeanThrowsNullPointerException() throws Throwable {
80          ActionContextImpl actionContextImpl = new ActionContextImpl();
81          try {
82              actionContextImpl.getFormBean();
83              fail("Expected NullPointerException to be thrown");
84          } catch (NullPointerException ex) {
85              assertNull("ex.getMessage()", ex.getMessage());
86              assertFalse("actionContextImpl.isInitialized()", actionContextImpl.isInitialized());
87              assertNull("actionContextImpl.action", getPrivateField(actionContextImpl, "action"));
88          }
89      }
90      
91      public void testGetMethodThrowsNullPointerException() throws Throwable {
92          ActionContextImpl actionContextImpl = new ActionContextImpl();
93          try {
94              actionContextImpl.getMethod();
95              fail("Expected NullPointerException to be thrown");
96          } catch (NullPointerException ex) {
97              assertNull("ex.getMessage()", ex.getMessage());
98              assertFalse("actionContextImpl.isInitialized()", actionContextImpl.isInitialized());
99          }
100     }
101     
102     public void testGetValidationThrowsNullPointerException() throws Throwable {
103         ActionContextImpl actionContextImpl = new ActionContextImpl();
104         try {
105             actionContextImpl.getValidation();
106             fail("Expected NullPointerException to be thrown");
107         } catch (NullPointerException ex) {
108             assertNull("ex.getMessage()", ex.getMessage());
109             assertFalse("actionContextImpl.isInitialized()", actionContextImpl.isInitialized());
110         }
111     }
112     
113     public void testInvokeThrowsNullPointerException() throws Throwable {
114         ActionContextImpl actionContextImpl = new ActionContextImpl();
115         try {
116             actionContextImpl.invoke();
117             fail("Expected NullPointerException to be thrown");
118         } catch (NullPointerException ex) {
119             assertNull("ex.getMessage()", ex.getMessage());
120             assertFalse("actionContextImpl.isInitialized()", actionContextImpl.isInitialized());
121             assertNull("actionContextImpl.action", getPrivateField(actionContextImpl, "action"));
122         }
123     }
124 }
125