Changeset 14410 in josm for trunk/test/unit/org/openstreetmap/josm/TestUtils.java
- Timestamp:
- 2018-11-03T22:09:03+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r14318 r14410 204 204 205 205 /** 206 * Sets a private field value. 207 * @param obj object 208 * @param fieldName private field name 209 * @param value replacement value 210 * @throws ReflectiveOperationException if a reflection operation error occurs 211 */ 212 public static void setPrivateField( 213 final Object obj, 214 final String fieldName, 215 final Object value 216 ) throws ReflectiveOperationException { 217 setPrivateField(obj.getClass(), obj, fieldName, value); 218 } 219 220 /** 221 * Sets a private field value. 222 * @param cls object class 223 * @param obj object 224 * @param fieldName private field name 225 * @param value replacement value 226 * @throws ReflectiveOperationException if a reflection operation error occurs 227 */ 228 public static void setPrivateField( 229 final Class<?> cls, 230 final Object obj, 231 final String fieldName, 232 final Object value 233 ) throws ReflectiveOperationException { 234 Field f = cls.getDeclaredField(fieldName); 235 AccessController.doPrivileged((PrivilegedAction<Void>) () -> { 236 f.setAccessible(true); 237 return null; 238 }); 239 f.set(obj, value); 240 } 241 242 /** 206 243 * Returns a private static field value. 207 244 * @param cls object class
Note:
See TracChangeset
for help on using the changeset viewer.