View Javadoc
1   package org.apache.commons.beanutils2.testbeans;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  /**
21   * Utility test class that is used to evaluate if exceptions are thrown correctly.
22   */
23  public class ThrowingExceptionBean
24  {
25  
26      public ThrowingExceptionBean()
27      {
28          // default constructor
29      }
30  
31      /**
32       * Rethrows the exception that is passed in.
33       *
34       * @param e The exception to throw
35       */
36      public ThrowingExceptionBean( RuntimeException e )
37      {
38          throw e;
39      }
40  
41      @SuppressWarnings( "unused" )
42      private ThrowingExceptionBean( Integer i )
43      {
44          // used in illegal access test cases
45      }
46  
47      protected ThrowingExceptionBean( Short s )
48      {
49          // used in illegal access test cases
50      }
51  
52      ThrowingExceptionBean( Byte b )
53      {
54          // used in illegal access test cases
55      }
56  
57      public String getExceptionProperty()
58      {
59          throw new RuntimeException();
60      }
61  
62      public void setExceptionProperty( String string )
63      {
64          throw new RuntimeException();
65      }
66  
67      @SuppressWarnings( "unused" )
68      // used in IllegalAccessException test cases via reflection
69      private String getPrivateProperty()
70      {
71          return "";
72      }
73  
74      @SuppressWarnings( "unused" )
75      // used in IllegalAccessException test cases via reflection
76      private void setPrivateProperty()
77      {
78          // do nothing
79      }
80  
81      protected String getProtectedProperty()
82      {
83          return "";
84      }
85  
86      protected void setProtectedProperty()
87      {
88          // do nothing
89      }
90  
91      String getDefaultProperty()
92      {
93          return "";
94      }
95  
96      void setDefaultProperty()
97      {
98          // do nothing
99      }
100 
101     public int getExceptionIndexed( int index )
102     {
103         throw new RuntimeException( "Get indexed always throws an exception!" );
104     }
105 
106     public void setExceptionIndexed( int index, RuntimeException e )
107     {
108         throw e;
109     }
110 
111     @SuppressWarnings( "unused" ) // used in IllegalAccessException test cases
112     private int getPrivateIndexed( int index )
113     {
114         return 1;
115     }
116 
117     @SuppressWarnings( "unused" ) // used in IllegalAccessException test cases
118     private void setPrivateIndexed( int index, int value )
119     {
120         // do nothing
121     }
122 
123     protected int getProtectedIndexed( int index )
124     {
125         return 1;
126     }
127 
128     protected void setProtectedIndexed( int index, int value )
129     {
130         // do nothing
131     }
132 
133     int getDefaultIndexed( int index )
134     {
135         return 1;
136     }
137 
138     void setDefaultIndexed( int index, int value )
139     {
140         // do nothing
141     }
142 
143     public RuntimeException getExceptionMapped( String key)
144     {
145         throw new RuntimeException( "Get indexed always throws an exception!" );
146     }
147 
148     public void setExceptionMapped( String key, RuntimeException e )
149     {
150         throw e;
151     }
152 
153     @SuppressWarnings( "unused" ) // used in IllegalAccessException test cases
154     private String getPrivateMapped( String key )
155     {
156         return "A Value";
157     }
158 
159     @SuppressWarnings( "unused" ) // used in IllegalAccessException test cases
160     private void setPrivateMapped( String key, Object value )
161     {
162         // do nothing
163     }
164 
165     protected String getProtectedMapped( String key )
166     {
167         return "A Value";
168     }
169 
170     protected void setProtectedMapped( String key, String value)
171     {
172         // do nothing
173     }
174 
175     String getDefaultMapped( String key )
176     {
177         return "A Value";
178     }
179 
180     void setDefaultMapped( String key, String value )
181     {
182         // do nothing
183     }
184 
185     public static void staticException( String message )
186     {
187         throw new RuntimeException( message );
188     }
189 
190 }