Ticket #15742: v1-0001-TestUtils-add-setPrivateStaticField-method.patch

File v1-0001-TestUtils-add-setPrivateStaticField-method.patch, 1.4 KB (added by ris, 7 years ago)
  • test/unit/org/openstreetmap/josm/TestUtils.java

    From 1be49fdd8a795a0636734f5a845cbe74c937f099 Mon Sep 17 00:00:00 2001
    From: Robert Scott <code@humanleg.org.uk>
    Date: Sun, 7 Jan 2018 22:01:57 +0000
    Subject: [PATCH v1 1/4] TestUtils: add setPrivateStaticField method
    
    ---
     test/unit/org/openstreetmap/josm/TestUtils.java | 16 ++++++++++++++++
     1 file changed, 16 insertions(+)
    
    diff --git a/test/unit/org/openstreetmap/josm/TestUtils.java b/test/unit/org/openstreetmap/josm/TestUtils.java
    index 050d7de2b..28282cf49 100644
    a b public final class TestUtils {  
    187187    }
    188188
    189189    /**
     190     * Sets a private static field value.
     191     * @param cls object class
     192     * @param fieldName private field name
     193     * @param value replacement value
     194     * @throws ReflectiveOperationException if a reflection operation error occurs
     195     */
     196    public static void setPrivateStaticField(Class<?> cls, String fieldName, final Object value) throws ReflectiveOperationException {
     197        Field f = cls.getDeclaredField(fieldName);
     198        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
     199            f.setAccessible(true);
     200            return null;
     201        });
     202        f.set(null, value);
     203    }
     204
     205    /**
    190206     * Returns an instance of {@link AbstractProgressMonitor} which keeps track of the monitor state,
    191207     * but does not show the progress.
    192208     * @return a progress monitor