001package org.apache.commons.beanutils2.testbeans; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020/** 021 * Utility test class that is used to evaluate if exceptions are thrown correctly. 022 */ 023public class ThrowingExceptionBean 024{ 025 026 public ThrowingExceptionBean() 027 { 028 // default constructor 029 } 030 031 /** 032 * Rethrows the exception that is passed in. 033 * 034 * @param e The exception to throw 035 */ 036 public ThrowingExceptionBean( RuntimeException e ) 037 { 038 throw e; 039 } 040 041 @SuppressWarnings( "unused" ) 042 private ThrowingExceptionBean( Integer i ) 043 { 044 // used in illegal access test cases 045 } 046 047 protected ThrowingExceptionBean( Short s ) 048 { 049 // used in illegal access test cases 050 } 051 052 ThrowingExceptionBean( Byte b ) 053 { 054 // used in illegal access test cases 055 } 056 057 public String getExceptionProperty() 058 { 059 throw new RuntimeException(); 060 } 061 062 public void setExceptionProperty( String string ) 063 { 064 throw new RuntimeException(); 065 } 066 067 @SuppressWarnings( "unused" ) 068 // used in IllegalAccessException test cases via reflection 069 private String getPrivateProperty() 070 { 071 return ""; 072 } 073 074 @SuppressWarnings( "unused" ) 075 // used in IllegalAccessException test cases via reflection 076 private void setPrivateProperty() 077 { 078 // do nothing 079 } 080 081 protected String getProtectedProperty() 082 { 083 return ""; 084 } 085 086 protected void setProtectedProperty() 087 { 088 // do nothing 089 } 090 091 String getDefaultProperty() 092 { 093 return ""; 094 } 095 096 void setDefaultProperty() 097 { 098 // do nothing 099 } 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}