11package org .owasp .esapi .reference .accesscontrol .policyloader ;
22
3+ import static org .junit .Assert .assertEquals ;
34import static org .mockito .ArgumentMatchers .eq ;
45
56import java .math .BigDecimal ;
89import java .util .Random ;
910
1011import org .apache .commons .configuration .XMLConfiguration ;
12+ import org .junit .Assert ;
1113import org .junit .Before ;
1214import org .junit .Test ;
1315import org .mockito .Mockito ;
1416
17+
1518public class ACRParameterLoaderHelperTest {
1619
1720
@@ -37,196 +40,223 @@ public void testUnsupportedTypeThrowsException() throws Exception {
3740 @ Test
3841 public void testStringParam_lowercaseType () throws Exception {
3942 Mockito .doReturn ("unused" ).when (config ).getString (eq (randomTestKey ));
40- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "string" .toLowerCase ());
43+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "string" .toLowerCase ());
4144
4245 // I don't really care what the response is here;
4346 // I care that the delegate class was called as expected with the generated string key.
4447 Mockito .verify (config , Mockito .times (1 )).getString (randomTestKey );
48+ Assert .assertEquals (String .class , response .getClass ());
49+ Assert .assertEquals ("unused" , response );
4550 }
4651
4752 @ Test
4853 public void testStringArrayParam_lowercaseType () throws Exception {
4954 Mockito .doReturn (new String [0 ]).when (config ).getStringArray (eq (randomTestKey ));
5055 // Mockito.when(config.getStringArray(eq(randomTestKey))).thenReturn();
51- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "stringarray" .toLowerCase ());
56+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "stringarray" .toLowerCase ());
5257 Mockito .verify (config , Mockito .times (1 )).getStringArray (randomTestKey );
58+ Assert .assertEquals (String [].class , response .getClass ());
5359 }
5460
5561 @ Test
5662 public void testBooleanParam_lowercaseType () throws Exception {
5763 Mockito .doReturn (Boolean .TRUE ).when (config ).getBoolean (eq (randomTestKey ));
5864 // Mockito.when(config.getBoolean(eq(randomTestKey))).thenReturn(Boolean.TRUE);
59- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "boolean" .toLowerCase ());
65+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "boolean" .toLowerCase ());
6066 Mockito .verify (config , Mockito .times (1 )).getBoolean (randomTestKey );
67+ Assert .assertEquals (Boolean .class , response .getClass ());
6168 }
6269
6370 @ Test
6471 public void testByteParam_lowercaseType () throws Exception {
6572 Mockito .doReturn ( (byte )0 ).when (config ).getByte ( eq (randomTestKey ) );
66- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "byte" .toLowerCase ());
73+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "byte" .toLowerCase ());
6774 Mockito .verify (config , Mockito .times (1 )).getByte (randomTestKey );
75+ Assert .assertEquals (Byte .class , response .getClass ());
6876 }
6977
7078 @ Test
7179 public void testIntParam_lowercaseType () throws Exception {
7280 Mockito .doReturn (0 ).when (config ).getInt (eq (randomTestKey ));
7381 // Mockito.when(config.getInt(eq(randomTestKey))).thenReturn(0);
74- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "int" .toLowerCase ());
82+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "int" .toLowerCase ());
7583 Mockito .verify (config , Mockito .times (1 )).getInt (randomTestKey );
84+ Assert .assertEquals (Integer .class , response .getClass ());
7685 }
7786
7887 @ Test
7988 public void testLongParam_lowercaseType () throws Exception {
8089 Mockito .doReturn (0L ).when (config ).getLong (eq (randomTestKey ));
8190 // Mockito.when(config.getLong(eq(randomTestKey))).thenReturn(0L);
82- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "long" .toLowerCase ());
91+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "long" .toLowerCase ());
8392 Mockito .verify (config , Mockito .times (1 )).getLong (randomTestKey );
93+ Assert .assertEquals (Long .class , response .getClass ());
8494 }
8595
8696 @ Test
8797 public void testFloatParam_lowercaseType () throws Exception {
8898 Mockito .doReturn ((float ) 0 ).when (config ).getFloat (eq (randomTestKey ));
89- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "float" .toLowerCase ());
99+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "float" .toLowerCase ());
90100 Mockito .verify (config , Mockito .times (1 )).getFloat (randomTestKey );
101+ Assert .assertEquals (Float .class , response .getClass ());
91102 }
92103
93104 @ Test
94105 public void testDoubleParam_lowercaseType () throws Exception {
95106 Mockito .doReturn (0d ).when (config ).getDouble (eq (randomTestKey ));
96107 // Mockito.when(config.getDouble(eq(randomTestKey))).thenReturn(0d);
97- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "double" .toLowerCase ());
108+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "double" .toLowerCase ());
98109 Mockito .verify (config , Mockito .times (1 )).getDouble (randomTestKey );
110+ Assert .assertEquals (Double .class , response .getClass ());
99111 }
100112
101113
102114 @ Test
103115 public void testBigDecimalParam_lowercaseType () throws Exception {
104116 Mockito .doReturn (new BigDecimal (0 )).when (config ).getBigDecimal (eq (randomTestKey ));
105117 // Mockito.when(config.getBigDecimal(eq(randomTestKey))).thenReturn();
106- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "bigdecimal" .toLowerCase ());
118+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "bigdecimal" .toLowerCase ());
107119 Mockito .verify (config , Mockito .times (1 )).getBigDecimal (randomTestKey );
120+ Assert .assertEquals (BigDecimal .class , response .getClass ());
108121 }
109122
110123 @ Test
111124 public void testBigIntegerParam_lowercaseType () throws Exception {
112125 Mockito .doReturn (new BigInteger ("0" )).when (config ).getBigInteger (eq (randomTestKey ));
113126 // Mockito.when(config.getBigInteger(eq(randomTestKey))).thenReturn();
114- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "biginteger" .toLowerCase ());
127+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "biginteger" .toLowerCase ());
115128 Mockito .verify (config , Mockito .times (1 )).getBigInteger (randomTestKey );
129+ Assert .assertEquals (BigInteger .class , response .getClass ());
116130 }
117131
118132 @ Test
119133 public void testDateParam_lowercaseType () throws Exception {
120134 String adate = java .text .DateFormat .getDateInstance ().format (new Date ());
121135 Mockito .doReturn (adate ).when (config ).getString (eq (randomTestKey ));
122- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "date" .toLowerCase ());
136+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "date" .toLowerCase ());
123137 Mockito .verify (config , Mockito .times (1 )).getString (randomTestKey );
138+ Assert .assertEquals (Date .class , response .getClass ());
124139 }
125140
126141 @ Test
127142 public void testTimeParam_lowercaseType () throws Exception {
128143 String atime = new java .text .SimpleDateFormat (ACRParameterLoaderHelper .TIME_FORMAT ).format (new Date ());
129144 Mockito .doReturn (atime ).when (config ).getString (eq (randomTestKey ));
130- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "time" .toLowerCase ());
145+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "time" .toLowerCase ());
131146 Mockito .verify (config , Mockito .times (1 )).getString (randomTestKey );
147+ Assert .assertEquals (Date .class , response .getClass ());
132148 }
133149
134150
151+
135152 @ Test
136153 public void testStringParam_uppercaseType () throws Exception {
137154 Mockito .doReturn ("unused" ).when (config ).getString (eq (randomTestKey ));
138- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "string" .toUpperCase ());
155+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "string" .toUpperCase ());
139156
140157 // I don't really care what the response is here;
141158 // I care that the delegate class was called as expected with the generated string key.
142159 Mockito .verify (config , Mockito .times (1 )).getString (randomTestKey );
160+ Assert .assertEquals (String .class , response .getClass ());
161+ Assert .assertEquals ("unused" , response );
143162 }
144163
145164 @ Test
146165 public void testStringArrayParam_uppercaseType () throws Exception {
147166 Mockito .doReturn (new String [0 ]).when (config ).getStringArray (eq (randomTestKey ));
148167 // Mockito.when(config.getStringArray(eq(randomTestKey))).thenReturn();
149- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "stringarray" .toUpperCase ());
168+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "stringarray" .toUpperCase ());
150169 Mockito .verify (config , Mockito .times (1 )).getStringArray (randomTestKey );
170+ Assert .assertEquals (String [].class , response .getClass ());
151171 }
152172
153173 @ Test
154174 public void testBooleanParam_uppercaseType () throws Exception {
155175 Mockito .doReturn (Boolean .TRUE ).when (config ).getBoolean (eq (randomTestKey ));
156176 // Mockito.when(config.getBoolean(eq(randomTestKey))).thenReturn(Boolean.TRUE);
157- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "boolean" .toUpperCase ());
177+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "boolean" .toUpperCase ());
158178 Mockito .verify (config , Mockito .times (1 )).getBoolean (randomTestKey );
179+ Assert .assertEquals (Boolean .class , response .getClass ());
159180 }
160181
161182 @ Test
162183 public void testByteParam_uppercaseType () throws Exception {
163184 Mockito .doReturn ( (byte )0 ).when (config ).getByte ( eq (randomTestKey ) );
164- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "byte" .toUpperCase ());
185+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "byte" .toUpperCase ());
165186 Mockito .verify (config , Mockito .times (1 )).getByte (randomTestKey );
187+ Assert .assertEquals (Byte .class , response .getClass ());
166188 }
167189
168190 @ Test
169191 public void testIntParam_uppercaseType () throws Exception {
170192 Mockito .doReturn (0 ).when (config ).getInt (eq (randomTestKey ));
171193 // Mockito.when(config.getInt(eq(randomTestKey))).thenReturn(0);
172- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "int" .toUpperCase ());
194+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "int" .toUpperCase ());
173195 Mockito .verify (config , Mockito .times (1 )).getInt (randomTestKey );
196+ Assert .assertEquals (Integer .class , response .getClass ());
174197 }
175198
176199 @ Test
177200 public void testLongParam_uppercaseType () throws Exception {
178201 Mockito .doReturn (0L ).when (config ).getLong (eq (randomTestKey ));
179202 // Mockito.when(config.getLong(eq(randomTestKey))).thenReturn(0L);
180- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "long" .toUpperCase ());
203+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "long" .toUpperCase ());
181204 Mockito .verify (config , Mockito .times (1 )).getLong (randomTestKey );
205+ Assert .assertEquals (Long .class , response .getClass ());
182206 }
183207
184208 @ Test
185209 public void testFloatParam_uppercaseType () throws Exception {
186210 Mockito .doReturn ((float ) 0 ).when (config ).getFloat (eq (randomTestKey ));
187- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "float" .toUpperCase ());
211+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "float" .toUpperCase ());
188212 Mockito .verify (config , Mockito .times (1 )).getFloat (randomTestKey );
213+ Assert .assertEquals (Float .class , response .getClass ());
189214 }
190215
191216 @ Test
192217 public void testDoubleParam_uppercaseType () throws Exception {
193218 Mockito .doReturn (0d ).when (config ).getDouble (eq (randomTestKey ));
194219 // Mockito.when(config.getDouble(eq(randomTestKey))).thenReturn(0d);
195- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "double" .toUpperCase ());
220+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "double" .toUpperCase ());
196221 Mockito .verify (config , Mockito .times (1 )).getDouble (randomTestKey );
222+ Assert .assertEquals (Double .class , response .getClass ());
197223 }
198224
199225
200226 @ Test
201227 public void testBigDecimalParam_uppercaseType () throws Exception {
202228 Mockito .doReturn (new BigDecimal (0 )).when (config ).getBigDecimal (eq (randomTestKey ));
203229 // Mockito.when(config.getBigDecimal(eq(randomTestKey))).thenReturn();
204- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "bigdecimal" .toUpperCase ());
230+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "bigdecimal" .toUpperCase ());
205231 Mockito .verify (config , Mockito .times (1 )).getBigDecimal (randomTestKey );
232+ Assert .assertEquals (BigDecimal .class , response .getClass ());
206233 }
207234
208235 @ Test
209236 public void testBigIntegerParam_uppercaseType () throws Exception {
210237 Mockito .doReturn (new BigInteger ("0" )).when (config ).getBigInteger (eq (randomTestKey ));
211238 // Mockito.when(config.getBigInteger(eq(randomTestKey))).thenReturn();
212- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "biginteger" .toUpperCase ());
239+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "biginteger" .toUpperCase ());
213240 Mockito .verify (config , Mockito .times (1 )).getBigInteger (randomTestKey );
241+ Assert .assertEquals (BigInteger .class , response .getClass ());
214242 }
215243
216244 @ Test
217245 public void testDateParam_uppercaseType () throws Exception {
218246 String adate = java .text .DateFormat .getDateInstance ().format (new Date ());
219247 Mockito .doReturn (adate ).when (config ).getString (eq (randomTestKey ));
220- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "date" .toUpperCase ());
248+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "date" .toUpperCase ());
221249 Mockito .verify (config , Mockito .times (1 )).getString (randomTestKey );
250+ Assert .assertEquals (Date .class , response .getClass ());
222251 }
223252
224253 @ Test
225254 public void testTimeParam_uppercaseType () throws Exception {
226255 String atime = new java .text .SimpleDateFormat (ACRParameterLoaderHelper .TIME_FORMAT ).format (new Date ());
227256 Mockito .doReturn (atime ).when (config ).getString (eq (randomTestKey ));
228- ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "time" .toUpperCase ());
257+ Object response = ACRParameterLoaderHelper .getParameterValue (config , randomRuleIndex , randomParameterIndex , "time" .toUpperCase ());
229258 Mockito .verify (config , Mockito .times (1 )).getString (randomTestKey );
259+ Assert .assertEquals (Date .class , response .getClass ());
230260 }
231261
232262}
0 commit comments