Changeset 11978 in josm


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

improve coverage and javadoc of enum classes for package actions

Location:
trunk
Files:
3 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/MoveAction.java

    r10409 r11978  
    2828public class MoveAction extends JosmAction {
    2929
    30     public enum Direction { UP, LEFT, RIGHT, DOWN }
     30    /**
     31     * Move direction.
     32     */
     33    public enum Direction {
     34        /** Move up */
     35        UP,
     36        /** Move left */
     37        LEFT,
     38        /** Move right */
     39        RIGHT,
     40        /** Move down */
     41        DOWN
     42    }
    3143
    3244    private final Direction myDirection;
  • trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    r11921 r11978  
    495495    }
    496496
    497     private enum Direction {
     497    enum Direction {
    498498        RIGHT, UP, LEFT, DOWN;
    499499        public Direction changeBy(int directionChange) {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r11713 r11978  
    6060    private boolean drawTargetHighlight;
    6161
    62     private enum DeleteMode {
     62    enum DeleteMode {
    6363        none(/* ICON(cursor/modifier/) */ "delete"),
    6464        segment(/* ICON(cursor/modifier/) */ "delete_segment"),
     
    7575        }
    7676
     77        /**
     78         * Returns the mode cursor.
     79         * @return the mode cursor
     80         */
    7781        public Cursor cursor() {
    7882            return c;
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java

    r11913 r11978  
    5959    private static final String CROSSHAIR = "crosshair";
    6060
    61     private enum State {
     61    enum State {
    6262        SELECTING, IMPROVING
    6363    }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java

    r11713 r11978  
    120120    // @formatter:on
    121121
    122     private enum Mode {
     122    enum Mode {
    123123        DRAGGING, NORMAL
    124124    }
     
    615615    }
    616616
    617     private enum Modifier {
     617    enum Modifier {
    618618        CTRL('c'),
    619619        ALT('a'),
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r11913 r11978  
    8686
    8787    // contains all possible cases the cursor can be in the SelectAction
    88     private enum SelectActionCursor {
     88    enum SelectActionCursor {
    8989
    9090        rect(NORMAL, "selection"),
     
    114114        }
    115115
     116        /**
     117         * Returns the action cursor.
     118         * @return the cursor
     119         */
    116120        public Cursor cursor() {
    117121            return c;
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r11464 r11978  
    6767    private static final String SEARCH_EXPRESSION = "searchExpression";
    6868
     69    /**
     70     * Search mode.
     71     */
    6972    public enum SearchMode {
    7073        /** replace selection */
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r11613 r11978  
    746746    public static class ExactKeyValue extends TaggedMatch {
    747747
    748         private enum Mode {
     748        enum Mode {
    749749            ANY, ANY_KEY, ANY_VALUE, EXACT, NONE, MISSING_KEY,
    750750            ANY_KEY_REGEXP, ANY_VALUE_REGEXP, EXACT_REGEXP, MISSING_KEY_REGEXP;
     
    757757        private final Mode mode;
    758758
     759        /**
     760         * Constructs a new {@code ExactKeyValue}.
     761         * @param regexp regular expression
     762         * @param key key
     763         * @param value value
     764         * @throws ParseError if a parse error occurs
     765         */
    759766        public ExactKeyValue(boolean regexp, String key, String value) throws ParseError {
    760767            if ("".equals(key))
  • 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}
  • trunk/test/unit/org/openstreetmap/josm/actions/ExtensionFileFilterTest.java

    r10956 r11978  
    55
    66import org.junit.Test;
     7import org.openstreetmap.josm.TestUtils;
     8import org.openstreetmap.josm.actions.ExtensionFileFilter.AddArchiveExtension;
    79
    810import nl.jqno.equalsverifier.EqualsVerifier;
     
    4749            .verify();
    4850    }
     51
     52    /**
     53     * Unit test of {@link AddArchiveExtension} enum.
     54     */
     55    @Test
     56    public void testEnumAddArchiveExtension() {
     57        TestUtils.superficialEnumCodeCoverage(AddArchiveExtension.class);
     58    }
    4959}
  • trunk/test/unit/org/openstreetmap/josm/actions/OrthogonalizeActionTest.java

    r11921 r11978  
    1111import org.junit.Test;
    1212import org.openstreetmap.josm.TestUtils;
     13import org.openstreetmap.josm.actions.OrthogonalizeAction.Direction;
    1314import org.openstreetmap.josm.actions.search.SearchCompiler;
    1415import org.openstreetmap.josm.data.coor.LatLon;
     
    1617import org.openstreetmap.josm.data.osm.Node;
    1718import org.openstreetmap.josm.data.osm.Way;
    18 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1919import org.openstreetmap.josm.io.OsmReader;
    2020import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    2626
    2727/**
    28  * Unit tests for class {@link OsmDataLayer}.
     28 * Unit tests for class {@link OrthogonalizeAction}.
    2929 */
    3030public class OrthogonalizeActionTest {
     
    111111        }
    112112    }
     113
     114    /**
     115     * Unit test of {@link Direction} enum.
     116     */
     117    @Test
     118    public void testEnumDirection() {
     119        TestUtils.superficialEnumCodeCoverage(Direction.class);
     120    }
    113121}
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/DeleteActionTest.java

    r11713 r11978  
    88import org.junit.Test;
    99import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.TestUtils;
     11import org.openstreetmap.josm.actions.mapmode.DeleteAction.DeleteMode;
    1012import org.openstreetmap.josm.data.osm.DataSet;
    1113import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    4345        }
    4446    }
     47
     48    /**
     49     * Unit test of {@link DeleteMode} enum.
     50     */
     51    @Test
     52    public void testEnumDeleteMode() {
     53        TestUtils.superficialEnumCodeCoverage(DeleteMode.class);
     54    }
    4555}
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/ExtrudeActionTest.java

    r11713 r11978  
    88import org.junit.Test;
    99import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.TestUtils;
     11import org.openstreetmap.josm.actions.mapmode.ExtrudeAction.Mode;
    1012import org.openstreetmap.josm.data.osm.DataSet;
    1113import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    4345        }
    4446    }
     47
     48    /**
     49     * Unit test of {@link Mode} enum.
     50     */
     51    @Test
     52    public void testEnumMode() {
     53        TestUtils.superficialEnumCodeCoverage(Mode.class);
     54    }
    4555}
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyActionTest.java

    r11713 r11978  
    88import org.junit.Test;
    99import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.TestUtils;
     11import org.openstreetmap.josm.actions.mapmode.ImproveWayAccuracyAction.State;
    1012import org.openstreetmap.josm.data.osm.DataSet;
    1113import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    4345        }
    4446    }
     47
     48    /**
     49     * Unit test of {@link State} enum.
     50     */
     51    @Test
     52    public void testEnumState() {
     53        TestUtils.superficialEnumCodeCoverage(State.class);
     54    }
    4555}
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/ParallelWayActionTest.java

    r10945 r11978  
    88import org.junit.Test;
    99import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.TestUtils;
     11import org.openstreetmap.josm.actions.mapmode.ParallelWayAction.Mode;
     12import org.openstreetmap.josm.actions.mapmode.ParallelWayAction.Modifier;
    1013import org.openstreetmap.josm.data.osm.DataSet;
    1114import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    4346        }
    4447    }
     48
     49    /**
     50     * Unit test of {@link Mode} enum.
     51     */
     52    @Test
     53    public void testEnumMode() {
     54        TestUtils.superficialEnumCodeCoverage(Mode.class);
     55    }
     56
     57    /**
     58     * Unit test of {@link Modifier} enum.
     59     */
     60    @Test
     61    public void testEnumModifier() {
     62        TestUtils.superficialEnumCodeCoverage(Modifier.class);
     63    }
    4564}
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java

    r10945 r11978  
    1515import org.junit.Test;
    1616import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.TestUtils;
     18import org.openstreetmap.josm.actions.mapmode.SelectAction.Mode;
     19import org.openstreetmap.josm.actions.mapmode.SelectAction.SelectActionCursor;
    1720import org.openstreetmap.josm.data.coor.EastNorth;
    1821import org.openstreetmap.josm.data.osm.DataSet;
     
    142145        }
    143146    }
     147
     148    /**
     149     * Unit test of {@link Mode} enum.
     150     */
     151    @Test
     152    public void testEnumMode() {
     153        TestUtils.superficialEnumCodeCoverage(Mode.class);
     154    }
     155
     156    /**
     157     * Unit test of {@link SelectActionCursor} enum.
     158     */
     159    @Test
     160    public void testEnumSelectActionCursor() {
     161        TestUtils.superficialEnumCodeCoverage(SelectActionCursor.class);
     162    }
    144163}
  • trunk/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java

    r11447 r11978  
    1616import org.openstreetmap.josm.TestUtils;
    1717import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
     18import org.openstreetmap.josm.actions.search.SearchCompiler.ExactKeyValue;
    1819import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
    1920import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
     
    482483                Paths.get(TestUtils.getRegressionDataFile(14217, "filter.txt"))), StandardCharsets.UTF_8)));
    483484    }
     485
     486    /**
     487     * Unit test of {@link SearchCompiler.ExactKeyValue.Mode} enum.
     488     */
     489    @Test
     490    public void testEnumExactKeyValueMode() {
     491        TestUtils.superficialEnumCodeCoverage(ExactKeyValue.Mode.class);
     492    }
    484493}
Note: See TracChangeset for help on using the changeset viewer.