Ignore:
Timestamp:
2017-04-22T21:14:24+02:00 (9 years ago)
Author:
Don-vip
Message:

improve coverage and javadoc of enum classes for package actions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r11324 r11978  
    22package org.openstreetmap.josm;
    33
     4import static org.junit.Assert.assertEquals;
    45import static org.junit.Assert.fail;
    56
     
    1011import java.io.InputStream;
    1112import java.lang.reflect.Field;
     13import java.lang.reflect.Method;
    1214import java.security.AccessController;
    1315import java.security.PrivilegedAction;
     
    2931import org.openstreetmap.josm.io.Compression;
    3032import org.openstreetmap.josm.testutils.FakeGraphics;
     33import org.openstreetmap.josm.tools.JosmRuntimeException;
     34import org.openstreetmap.josm.tools.Utils;
    3135
    3236import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    286290        };
    287291    }
     292
     293    /**
     294     * Ensures 100% code coverage for enums.
     295     * @param enumClass enum class to cover
     296     */
     297    public static void superficialEnumCodeCoverage(Class<? extends Enum<?>> enumClass) {
     298        try {
     299            Method values = enumClass.getMethod("values");
     300            Method valueOf = enumClass.getMethod("valueOf", String.class);
     301            Utils.setObjectsAccessible(values, valueOf);
     302            for (Object o : (Object[]) values.invoke(null)) {
     303                assertEquals(o, valueOf.invoke(null, ((Enum<?>) o).name()));
     304            }
     305        } catch (IllegalArgumentException | ReflectiveOperationException | SecurityException e) {
     306            throw new JosmRuntimeException(e);
     307        }
     308    }
    288309}
Note: See TracChangeset for help on using the changeset viewer.