Ticket #22263: 22263.2.patch

File 22263.2.patch, 51.2 KB (added by taylor.smock, 2 years ago)

Move unit tests from JUnit 4 to JUnit 5

  • .classpath

     
    1010        <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
    1111        <classpathentry combineaccessrules="false" kind="src" path="/JOSM-GeoTools"/>
    1212        <classpathentry combineaccessrules="false" kind="src" path="/JOSM-jts"/>
    13         <classpathentry combineaccessrules="false" kind="src" path="/JOSM-log4j"/>
    14         <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
     13        <classpathentry combineaccessrules="false" kind="src" path="/JOSM-ejml"/>
     14        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
    1515        <classpathentry kind="output" path="bin"/>
    1616</classpath>
  • build.xml

     
    1111    <property name="plugin.description" value="Plugin for importing spatial referenced images"/>
    1212    <property name="plugin.icon" value="images/layericon.png"/>
    1313    <property name="plugin.link" value="https://wiki.openstreetmap.org/wiki/JOSM/Plugins/ImportImagePlugin"/>
    14     <property name="plugin.requires" value="log4j;jts;ejml;geotools"/>
     14    <property name="plugin.requires" value="jts;ejml;geotools"/>
    1515   
    1616    <!-- ** include targets that all plugins have in common ** -->
    1717    <import file="../build-common.xml"/>
    1818
    1919    <fileset id="plugin.requires.jars" dir="${plugin.dist.dir}">
    20         <include name="log4j.jar"/>
    2120        <include name="jts.jar"/>
    2221        <include name="ejml.jar"/>
    2322        <include name="geotools.jar"/>
  • src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayer.java

     
    1818import javax.swing.Icon;
    1919import javax.swing.ImageIcon;
    2020
    21 import org.apache.log4j.Logger;
    2221import org.geotools.coverage.grid.GridCoverage2D;
    2322import org.geotools.geometry.Envelope2D;
    2423import org.geotools.image.ImageWorker;
     
    4847 */
    4948public class ImageLayer extends Layer {
    5049
    51     private Logger logger = Logger.getLogger(ImageLayer.class);
    52 
    5350    private File imageFile;
    5451
    5552    private BufferedImage image = null;
     
    9895            coverage = PluginOperations.reprojectCoverage(coverage, CRS.decode(ProjectionRegistry.getProjection().toCode()));
    9996
    10097        } catch (FactoryException e) {
    101             logger.error("Error while creating GridCoverage:", e);
     98            Logging.error("ImportImagePlugin ImageLayer: Error while creating GridCoverage: {0}", e);
     99            Logging.error(e);
    102100            throw new IOException(e.getMessage());
    103101        } catch (Exception e) {
    104102            if (e.getMessage().contains("No projection file found")) {
     
    114112                    // CHECKSTYLE.ON: LineLength
    115113                    val = ex.showDialog().getValue();
    116114                    if (val == 3) {
    117                         logger.debug("No projection and user declined un-projected use");
     115                        Logging.debug("ImportImagePlugin ImageLayer: No projection and user declined un-projected use");
    118116                        throw new LayerCreationCanceledException();
    119117                    }
    120118                }
     
    123121                    if (val == 1) {
    124122                        src = PluginOperations.defaultSourceCRS;
    125123                    } else {
    126                         logger.debug("Passing through image un-projected.");
     124                        Logging.debug("ImportImagePlugin ImageLayer: Passing through image un-projected.");
    127125                        src = CRS.decode(ProjectionRegistry.getProjection().toCode());
    128126                    }
    129127                    // create a grid coverage from the image
     
    133131                        coverage = PluginOperations.reprojectCoverage(coverage, CRS.decode(ProjectionRegistry.getProjection().toCode()));
    134132                    }
    135133                } catch (Exception e1) {
    136                     logger.error("Error while creating GridCoverage:", e1);
     134                    Logging.error("ImportImagePlugin ImageLayer: Error while creating GridCoverage:");
     135                    Logging.error(e1);
    137136                    throw new IOException(e1);
    138137                }
    139138            } else {
    140                 logger.error("Error while creating GridCoverage:", e);
     139                Logging.error("ImportImagePlugin ImageLayer: Error while creating GridCoverage:");
     140                Logging.error(e);
    141141                throw new IOException(e);
    142142            }
    143143
    144144        }
    145         logger.debug("Coverage created: " + coverage);
     145        Logging.debug("ImportImagePlugin ImageLayer: Coverage created: {0}", coverage);
    146146
    147147        upperLeft = new EastNorth(coverage.getEnvelope2D().x,
    148148                coverage.getEnvelope2D().y + coverage.getEnvelope2D().height);
     
    212212            double scaley = pixels4bbox_height / image.getHeight();
    213213
    214214            if ((scalex > 10) || (scaley > 10)) {
    215                 logger.warn("Not drawing image - scale too big");
     215                Logging.warn("ImportImagePlugin ImageLayer: Not drawing image - scale too big");
    216216                return;
    217217            }
    218218            g.scale(scalex, scaley);
     
    226226            }
    227227
    228228        } else {
    229             logger.error("Error while dawing image: image == null or Graphics == null");
     229            Logging.error("ImportImagePlugin ImageLayer: Error while drawing image: image == null or Graphics == null");
    230230        }
    231231    }
    232232
     
    295295     * calculated by the new reference system.
    296296     */
    297297    void resample(CoordinateReferenceSystem refSys) throws IOException, NoSuchAuthorityCodeException, FactoryException {
    298         logger.debug("resample");
     298        Logging.debug("ImportImagePlugin ImageLayer: resample");
    299299        GridCoverage2D coverage = PluginOperations.createGridFromFile(this.imageFile, refSys, true);
    300300        coverage = PluginOperations.reprojectCoverage(coverage, CRS.decode(ProjectionRegistry.getProjection().toCode()));
    301301        this.bbox = coverage.getEnvelope2D();
  • src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImageFileImporter.java

     
    99
    1010import javax.swing.JOptionPane;
    1111
    12 import org.apache.log4j.Logger;
    1312import org.openstreetmap.josm.actions.ExtensionFileFilter;
    1413import org.openstreetmap.josm.gui.MainApplication;
    1514import org.openstreetmap.josm.gui.io.importexport.FileImporter;
     
    2423 */
    2524public class ImportImageFileImporter extends FileImporter {
    2625   
    27     private Logger logger = Logger.getLogger(LoadImageAction.class);
    28 
    2926    public ImportImageFileImporter() {
    3027        super(new ExtensionFileFilter("tiff,tif,jpg,jpeg,bmp,png", "jpg",
    3128                "Georeferenced image file [by ImportImage plugin] (*.jpg, *.jpeg, *.tif, *.tiff, *.png, *.bmp)"));
     
    4744
    4845        for (File file: files) {
    4946            if (file.isDirectory()) continue;
    50             ImageLayer layer = null;
    51             logger.info("File choosen:" + file);
     47            ImageLayer layer;
     48            Logging.info("ImportImageFileImporter: File chosen: {0}", file);
    5249            try {
    5350                layer = new ImageLayer(file);
    5451            } catch (LayerCreationCanceledException e) {
     52                Logging.trace(e);
    5553                // if user decides that layer should not be created just return.
    5654                continue;
    5755            } catch (Exception e) {
     56                Logging.error("ImportImageFileImporter: Error while creating image layer: \n{0}", e.getMessage());
    5857                Logging.error(e);
    59                 logger.error("Error while creating image layer: \n" + e.getMessage());
    6058                GuiHelper.runInEDT(() ->
    6159                    JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Error while creating image layer: {0}", e.getCause())));
    6260                continue;
  • src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImagePlugin.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.ImportImagePlugin;
    33
    4 import java.io.File;
    5 import java.io.FileWriter;
    6 import java.io.IOException;
    7 import java.net.URL;
    8 import java.util.Properties;
    9 
    10 import javax.swing.JMenu;
    11 
    12 import org.apache.log4j.Logger;
    13 import org.apache.log4j.PropertyConfigurator;
    144import org.openstreetmap.josm.actions.ExtensionFileFilter;
    155import org.openstreetmap.josm.actions.JosmAction;
    166import org.openstreetmap.josm.data.Preferences;
     
    188import org.openstreetmap.josm.gui.MainMenu;
    199import org.openstreetmap.josm.plugins.Plugin;
    2010import org.openstreetmap.josm.plugins.PluginInformation;
     11import org.openstreetmap.josm.tools.JosmRuntimeException;
     12import org.openstreetmap.josm.tools.Logging;
    2113import org.openstreetmap.josm.tools.Utils;
    2214
     15import java.io.BufferedWriter;
     16import java.io.File;
     17import java.io.IOException;
     18import java.io.InputStream;
     19import java.net.URL;
     20import java.nio.file.Files;
     21import java.nio.file.Paths;
     22import java.util.Properties;
     23
    2324/**
    2425 * Plugin class.
    2526 * Provides basic routines for plugin installation and provides the plugin properties.
    2627 *
    27  *
    2828 * @author Christoph Beekmans, Fabian Kowitz, Anna Robaszkiewicz, Oliver Kuhn, Martin Ulitzny
    2929 *
    3030 */
    3131public class ImportImagePlugin extends Plugin {
    3232
    33     private static Logger logger;
     33    JosmAction loadFileAction;
    3434
    35     JMenu mainmenu = null;
    36     JosmAction loadFileAction = null;
    37 
    3835    // plugin properties
    3936    static Properties pluginProps;
    4037
     
    4340    static final String PLUGINPROPERTIES_FILENAME = "pluginProperties.properties";
    4441    static final String PLUGINPROPERTIES_PATH = PLUGIN_DIR + PLUGINPROPERTIES_FILENAME;
    4542    static final String PLUGINLIBRARIES_DIR = PLUGIN_DIR + "lib/";
    46     static final String LOGGING_PROPERTIES_FILEPATH = PLUGIN_DIR + "log4j.properties/";
    4743
    4844    /**
    4945     * Returns Import image plugin properties.
     
    6359        super(info);
    6460
    6561        try {
    66             // Initialize logger
    67             initializeLogger();
    68 
    6962            // Check whether plugin has already been installed. Otherwise install
    7063            checkInstallation();
    7164
    7265            // If resources are available load properties from plugin directory
    73             if (pluginProps == null || pluginProps.isEmpty()) {
    74                 pluginProps = new Properties();
    75                 pluginProps.load(new File(PLUGINPROPERTIES_PATH).toURI().toURL().openStream());
    76                 logger.debug("Plugin properties loaded");
    77             }
     66            loadPluginProps();
    7867
    7968            // load information about supported reference systems
    8069            PluginOperations.loadCRSData(pluginProps);
     
    8776            ExtensionFileFilter.addImporter(new ImportImageFileImporter());
    8877
    8978        } catch (IOException e) {
    90             logger.fatal("Error while loading plugin", e);
    91             throw e;
     79            throw new JosmRuntimeException(e);
    9280        }
    9381    }
    9482
     83    private static void loadPluginProps() throws IOException {
     84        if (pluginProps == null || pluginProps.isEmpty()) {
     85            pluginProps = new Properties();
     86            try (InputStream stream = Files.newInputStream(Paths.get(PLUGINPROPERTIES_PATH))) {
     87                pluginProps.load(stream);
     88            }
     89            Logging.debug("ImportImagePlugin: Plugin properties loaded");
     90        }
     91    }
     92
     93    private static void writePluginPropsToFileAndLoad() throws IOException {
     94        if (pluginProps == null || pluginProps.isEmpty()) {
     95            try (BufferedWriter fw = Files.newBufferedWriter(Paths.get(PLUGINPROPERTIES_PATH))) {
     96                URL propertiesURL = ImportImagePlugin.class.getResource("resources/" + PLUGINPROPERTIES_FILENAME);
     97                if (propertiesURL != null) {
     98                    pluginProps = new Properties();
     99                    try (InputStream stream = propertiesURL.openStream()) {
     100                        pluginProps.load(stream);
     101                    }
     102                    pluginProps.store(fw, null);
     103                }
     104
     105            }
     106            Logging.debug("ImportImagePlugin: Plugin properties loaded");
     107        }
     108    }
     109
    95110    /**
    96111     * Checks whether plugin resources are available.
    97112     * If not, start install procedure.
    98113     */
    99     private void checkInstallation() throws IOException {
     114    private static void checkInstallation() throws IOException {
    100115        // check plugin resource state
    101         boolean isInstalled = true;
    102         if (!new File(PLUGINPROPERTIES_PATH).exists()
    103                 || !new File(PLUGIN_DIR).exists()
    104                 || !new File(PLUGINLIBRARIES_DIR).exists())
    105             isInstalled = false;
     116        boolean isInstalled = new File(PLUGINPROPERTIES_PATH).exists()
     117                && new File(PLUGIN_DIR).exists()
     118                && new File(PLUGINLIBRARIES_DIR).exists();
    106119
    107120
    108121        // if properties file doesn't exist, install plugin
     
    123136            }
    124137
    125138            // create local properties file
    126             if (pluginProps == null || pluginProps.isEmpty()) {
    127                 try (FileWriter fw = new FileWriter(new File(PLUGINPROPERTIES_PATH))) {
    128                     URL propertiesURL = getClass().getResource("resources/" + PLUGINPROPERTIES_FILENAME);
    129                     if (propertiesURL != null) {
    130                         pluginProps = new Properties();
    131                         pluginProps.load(propertiesURL.openStream());
    132                         pluginProps.store(fw, null);
    133                     }
    134                 }
    135                 logger.debug("Plugin properties loaded");
    136             }
     139            writePluginPropsToFileAndLoad();
    137140
    138             if (!new File(LOGGING_PROPERTIES_FILEPATH).exists()) {
    139                 try (FileWriter fw = new FileWriter(new File(LOGGING_PROPERTIES_FILEPATH))) {
    140                     URL propertiesURL = getClass().getResource("resources/log4j.properties");
    141                     if (propertiesURL != null) {
    142                         Properties loggingProps = new Properties();
    143                         loggingProps.load(propertiesURL.openStream());
    144                         loggingProps.store(fw, null);
    145                     }
    146                 }
    147                 logger.debug("Logging properties created");
    148             }
    149 
    150             logger.debug("Plugin successfully installed");
     141            Logging.debug("ImportImagePlugin: Plugin successfully installed");
    151142        }
    152143    }
    153 
    154     /**
    155      * Initialize logger.
    156      */
    157     private void initializeLogger() {
    158 
    159         Properties props = new Properties();
    160         try {
    161             props.load(new File(LOGGING_PROPERTIES_FILEPATH).toURI().toURL().openStream());
    162 
    163             // Set file for logging here:
    164             props.setProperty("log4j.appender.MyRoFiAppender.file",
    165                     (Preferences.main().getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/" + "log.log"));
    166 
    167             PropertyConfigurator.configure(props);
    168 
    169             logger = Logger.getLogger(ImportImagePlugin.class);
    170 
    171             logger.info("Logger successfully initialized.");
    172 
    173             return;
    174 
    175         } catch (IOException e) {
    176             System.out.println("Logging properties file not found. Using standard settings.");
    177         }
    178 
    179         // if no log4j.properties file can be found, initialize manually:
    180 
    181         props.setProperty("log4j.rootLogger", "INFO, A");
    182         props.setProperty("log4j.appender.A", "org.apache.log4j.FileAppender");
    183 
    184         props.setProperty("log4j.appender.A.layout",
    185                 "org.apache.log4j.PatternLayout ");
    186         props.setProperty("log4j.appender.A.layout.ConversionPattern",
    187                 "%d{ISO8601} %-5p [%t] %c: %m%n");
    188 
    189         // Set file for logging here:
    190         props.setProperty("log4j.appender.A.file",
    191                 (Preferences.main().getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/" + "log.log"));
    192 
    193         PropertyConfigurator.configure(props);
    194         logger = Logger.getLogger(ImportImagePlugin.class);
    195     }
    196144}
  • src/org/openstreetmap/josm/plugins/ImportImagePlugin/LayerPropertiesDialog.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.ImportImagePlugin;
    33
    4 import java.awt.Cursor;
    5 import java.awt.Dimension;
    6 import java.awt.Font;
    7 import java.awt.GridBagConstraints;
    8 import java.awt.GridBagLayout;
    9 import java.awt.Rectangle;
    10 import java.awt.event.KeyAdapter;
    11 import java.awt.event.KeyEvent;
    12 import java.io.File;
    13 import java.io.FileWriter;
    14 import java.io.IOException;
    15 import java.util.Iterator;
    16 import java.util.Vector;
     4import org.geotools.referencing.CRS;
     5import org.opengis.referencing.FactoryException;
     6import org.opengis.referencing.crs.CoordinateReferenceSystem;
     7import org.openstreetmap.josm.tools.Logging;
    178
    189import javax.swing.JButton;
    1910import javax.swing.JCheckBox;
     
    2819import javax.swing.SwingConstants;
    2920import javax.swing.event.ListSelectionEvent;
    3021import javax.swing.event.ListSelectionListener;
     22import java.awt.Cursor;
     23import java.awt.Dimension;
     24import java.awt.Font;
     25import java.awt.GridBagConstraints;
     26import java.awt.GridBagLayout;
     27import java.awt.Rectangle;
     28import java.awt.event.KeyAdapter;
     29import java.awt.event.KeyEvent;
     30import java.io.BufferedWriter;
     31import java.io.IOException;
     32import java.nio.file.Files;
     33import java.nio.file.Paths;
     34import java.util.List;
    3135
    32 import org.geotools.referencing.CRS;
    33 import org.opengis.referencing.FactoryException;
    34 import org.opengis.referencing.crs.CoordinateReferenceSystem;
    35 import org.openstreetmap.josm.tools.Logging;
    36 
    3736/**
    3837 * UI-Dialog which provides:
    3938 * - general and spatial information about the georeferenced image
    40  * - a possiblitly to change the source reference system of the image
     39 * - a possibility to change the source reference system of the image
    4140 *
    42  *
    4341 * @author Christoph Beekmans, Fabian Kowitz, Anna Robaszkiewicz, Oliver Kuhn, Martin Ulitzny
    4442 *
    4543 */
    4644public class LayerPropertiesDialog extends JFrame {
    4745
    48     private Vector<String> supportedCRS;
     46    private final List<String> supportedCRS;
    4947    private ImageLayer imageLayer;
    5048
    51     private JPanel mainPanel = null;
    52     private JPanel jPanel = null;
    53     private JPanel buttonPanel = null;
    54     private JTabbedPane jTabbedPane = null;
    55     private JPanel infoPanel = null;
    56     private JPanel crsPanel = null;
    57     private JButton okButton = null;
    58     private JLabel layerNameLabel = null;
    59     private JLabel layerNameValueLabel = null;
    60     private JLabel imageFileLabel = null;
    61     private JLabel imageFileValueLabel = null;
    62     private JLabel sizeLabel = null;
    63     private JLabel sizeValueLabel = null;
    64     private JLabel crsLabel = null;
    65     private JLabel crsValueLabel = null;
    66     private JLabel extentLabel = null;
    67     private JLabel defaultCRSDescriptorLabel = null;
    68     private JLabel defaultCRSLabel = null;
    69     private JTextField searchField = null;
    70     private JScrollPane crsListScrollPane = null;
    71     private JList<String> crsJList = null;
    72     private JButton useDefaultCRSButton = null;
    73     private JButton applySelectedCRSButton = null;
    74     private JButton setSelectedCRSAsDefaultButton = null;
    75     private JLabel searchFieldLabel = null;
    76     private JCheckBox eastingFirstCheckBox = null;
    77     private JLabel eastingFirstLabel = null;
    78     private JLabel tabDescriptionLabel = null;
    79     private JLabel upperLeftLabel = null;
    80     private JLabel lowerLeftLabel = null;
    81     private JLabel upperRightLabel = null;
    82     private JLabel lowerRightLabel = null;
    83     private JLabel upperLeftValueLabel = null;
    84     private JLabel upperRightValueLabel = null;
    85     private JLabel lowerLeftValueLabel = null;
    86     private JLabel lowerRightValueLabel = null;
    87     private JLabel currentCRSLabel = null;
    88     private JLabel currentCRSValueLabel = null;
     49    private JPanel mainPanel;
     50    private JPanel jPanel;
     51    private JPanel buttonPanel;
     52    private JTabbedPane jTabbedPane;
     53    private JPanel infoPanel;
     54    private JPanel crsPanel;
     55    private JButton okButton;
     56    private JLabel defaultCRSLabel;
     57    private JTextField searchField;
     58    private JScrollPane crsListScrollPane;
     59    private JList<String> crsJList;
     60    private JButton useDefaultCRSButton;
     61    private JButton applySelectedCRSButton;
     62    private JButton setSelectedCRSAsDefaultButton;
     63    private JCheckBox eastingFirstCheckBox;
    8964
    9065    /**
    9166     * This method initializes
    9267     *
    9368     */
    94     public LayerPropertiesDialog(ImageLayer imageLayer, Vector<String> supportedCRS) {
     69    public LayerPropertiesDialog(ImageLayer imageLayer, List<String> supportedCRS) {
    9570        super(imageLayer.getName());
    9671        this.supportedCRS = supportedCRS;
    9772        this.imageLayer = imageLayer;
     
    10277     * This method initializes
    10378     *
    10479     */
    105     public LayerPropertiesDialog(Vector<String> supportedCRS) {
     80    public LayerPropertiesDialog(List<String> supportedCRS) {
    10681        super();
    10782        this.supportedCRS = supportedCRS;
    10883        initialize();
     
    190165     */
    191166    private JPanel getInfoPanel() {
    192167        if (infoPanel == null) {
    193             lowerRightValueLabel = new JLabel();
     168            JLabel lowerRightValueLabel = new JLabel();
    194169            lowerRightValueLabel.setBounds(new Rectangle(210, 315, 134, 16));
    195170            lowerRightValueLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    196171            lowerRightValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float) imageLayer.getBbox().getMaxY());
    197             lowerLeftValueLabel = new JLabel();
     172            JLabel lowerLeftValueLabel = new JLabel();
    198173            lowerLeftValueLabel.setBounds(new Rectangle(30, 315, 133, 16));
    199174            lowerLeftValueLabel.setHorizontalAlignment(SwingConstants.LEFT);
    200175            lowerLeftValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float) imageLayer.getBbox().getMinY());
    201             upperRightValueLabel = new JLabel();
     176            JLabel upperRightValueLabel = new JLabel();
    202177            upperRightValueLabel.setBounds(new Rectangle(210, 255, 138, 16));
    203178            upperRightValueLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    204179            upperRightValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float) imageLayer.getBbox().getMaxY());
    205             upperLeftValueLabel = new JLabel();
     180            JLabel upperLeftValueLabel = new JLabel();
    206181            upperLeftValueLabel.setBounds(new Rectangle(30, 255, 133, 16));
    207182            upperLeftValueLabel.setHorizontalAlignment(SwingConstants.LEFT);
    208183            upperLeftValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float) imageLayer.getBbox().getMinY());
    209             lowerRightLabel = new JLabel();
     184            JLabel lowerRightLabel = new JLabel();
    210185            lowerRightLabel.setBounds(new Rectangle(287, 344, 74, 16));
    211186            lowerRightLabel.setText("Lower Right");
    212             upperRightLabel = new JLabel();
     187            JLabel upperRightLabel = new JLabel();
    213188            upperRightLabel.setBounds(new Rectangle(285, 225, 91, 16));
    214189            upperRightLabel.setText("Upper Right");
    215             lowerLeftLabel = new JLabel();
     190            JLabel lowerLeftLabel = new JLabel();
    216191            lowerLeftLabel.setBounds(new Rectangle(15, 345, 92, 16));
    217192            lowerLeftLabel.setText("Lower Left");
    218             upperLeftLabel = new JLabel();
     193            JLabel upperLeftLabel = new JLabel();
    219194            upperLeftLabel.setBounds(new Rectangle(15, 224, 91, 16));
    220195            upperLeftLabel.setText("Upper Left");
    221             extentLabel = new JLabel();
     196            JLabel extentLabel = new JLabel();
    222197            extentLabel.setBounds(new Rectangle(120, 195, 136, 16));
    223198            extentLabel.setEnabled(false);
    224199            extentLabel.setHorizontalAlignment(SwingConstants.CENTER);
    225200            extentLabel.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
    226201            extentLabel.setText("Extent");
    227             crsValueLabel = new JLabel();
     202            JLabel crsValueLabel = new JLabel();
    228203            crsValueLabel.setBounds(new Rectangle(150, 150, 226, 16));
    229204
    230205            String crsDescription = "";
     
    235210            }
    236211            crsValueLabel.setText(crsDescription + "(" + imageLayer.getBbox().getCoordinateReferenceSystem().getName().toString() + ")");
    237212
    238             crsLabel = new JLabel();
     213            JLabel crsLabel = new JLabel();
    239214            crsLabel.setBounds(new Rectangle(15, 150, 118, 16));
    240215            crsLabel.setText("Reference System");
    241             sizeValueLabel = new JLabel();
     216            JLabel sizeValueLabel = new JLabel();
    242217            sizeValueLabel.setBounds(new Rectangle(150, 105, 226, 16));
    243218            sizeValueLabel.setText(imageLayer.getImage().getHeight() + " x " + imageLayer.getImage().getWidth());
    244             sizeLabel = new JLabel();
     219            JLabel sizeLabel = new JLabel();
    245220            sizeLabel.setBounds(new Rectangle(15, 105, 121, 16));
    246221            sizeLabel.setText("Image size");
    247             imageFileValueLabel = new JLabel();
     222            JLabel imageFileValueLabel = new JLabel();
    248223            imageFileValueLabel.setBounds(new Rectangle(150, 60, 226, 16));
    249224            imageFileValueLabel.setText(imageLayer.getImageFile().getAbsolutePath());
    250225            imageFileValueLabel.setToolTipText(imageLayer.getImageFile().getAbsolutePath());
    251             imageFileLabel = new JLabel();
     226            JLabel imageFileLabel = new JLabel();
    252227            imageFileLabel.setBounds(new Rectangle(15, 60, 121, 16));
    253228            imageFileLabel.setText("Image file");
    254             layerNameValueLabel = new JLabel();
     229            JLabel layerNameValueLabel = new JLabel();
    255230            layerNameValueLabel.setBounds(new Rectangle(150, 15, 226, 16));
    256231            layerNameValueLabel.setText(imageLayer.getName());
    257             layerNameLabel = new JLabel();
     232            JLabel layerNameLabel = new JLabel();
    258233            layerNameLabel.setBounds(new Rectangle(15, 15, 121, 16));
    259234            layerNameLabel.setText("Layer name");
    260235            infoPanel = new JPanel();
     
    288263     */
    289264    private JPanel getCrsPanel() {
    290265        if (crsPanel == null) {
    291             currentCRSValueLabel = new JLabel();
     266            JLabel currentCRSValueLabel = new JLabel();
    292267            currentCRSValueLabel.setBounds(new Rectangle(78, 33, 297, 16));
    293268            String crsDescription = "unknown";
    294269            try {
     
    298273            }
    299274            currentCRSValueLabel.setText(crsDescription);
    300275
    301             currentCRSLabel = new JLabel();
     276            JLabel currentCRSLabel = new JLabel();
    302277            currentCRSLabel.setBounds(new Rectangle(15, 33, 52, 16));
    303278            currentCRSLabel.setText("Current:");
    304             tabDescriptionLabel = new JLabel();
     279            JLabel tabDescriptionLabel = new JLabel();
    305280            tabDescriptionLabel.setBounds(new Rectangle(15, 9, 361, 16));
    306281            tabDescriptionLabel.setText("Set here the source reference system of the image");
    307             eastingFirstLabel = new JLabel();
     282            JLabel eastingFirstLabel = new JLabel();
    308283            eastingFirstLabel.setBounds(new Rectangle(315, 210, 76, 46));
    309284            eastingFirstLabel.setHorizontalTextPosition(SwingConstants.TRAILING);
    310285            eastingFirstLabel.setHorizontalAlignment(SwingConstants.CENTER);
    311286            eastingFirstLabel.setText("<html>Easting<br>first</html>");
    312             searchFieldLabel = new JLabel();
     287            JLabel searchFieldLabel = new JLabel();
    313288            searchFieldLabel.setBounds(new Rectangle(298, 114, 84, 16));
    314289            searchFieldLabel.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
    315290            searchFieldLabel.setHorizontalTextPosition(SwingConstants.TRAILING);
     
    318293            defaultCRSLabel = new JLabel();
    319294            defaultCRSLabel.setBounds(new Rectangle(15, 89, 361, 16));
    320295            defaultCRSLabel.setText(PluginOperations.defaultSourceCRSDescription);
    321             defaultCRSDescriptorLabel = new JLabel();
     296            JLabel defaultCRSDescriptorLabel = new JLabel();
    322297            defaultCRSDescriptorLabel.setBounds(new Rectangle(15, 63, 226, 16));
    323298            defaultCRSDescriptorLabel.setText("Default Reference System:");
    324299            crsPanel = new JPanel();
     
    372347                @Override
    373348                public void keyTyped(KeyEvent e) {
    374349
    375                     for (Iterator<String> iterator = supportedCRS.iterator(); iterator.hasNext();) {
    376                         String type = iterator.next();
     350                    for (String type : supportedCRS) {
    377351                        if (type.contains(searchField.getText())) {
    378352                            crsJList.setSelectedIndex(supportedCRS.indexOf(type));
    379353                            crsJList.ensureIndexIsVisible(supportedCRS.indexOf(type));
     
    408382     */
    409383    private JList<String> getCrsJList() {
    410384        if (crsJList == null) {
    411             crsJList = new JList<>(supportedCRS);
     385            crsJList = new JList<>(supportedCRS.toArray(new String[0]));
    412386            crsJList.addListSelectionListener(new ListSelectionHandler());
    413387        }
    414388        return crsJList;
     
    496470                                ImportImagePlugin.pluginProps.setProperty("default_crs_eastingfirst",
    497471                                        "" + eastingFirstCheckBox.isSelected());
    498472                                ImportImagePlugin.pluginProps.setProperty("default_crs_srid", code);
    499                                 try (FileWriter fileWriter = new FileWriter(new File(ImportImagePlugin.PLUGINPROPERTIES_PATH))) {
     473                                try (BufferedWriter fileWriter = Files.newBufferedWriter(Paths.get(ImportImagePlugin.PLUGINPROPERTIES_PATH))) {
    500474                                    ImportImagePlugin.pluginProps.store(fileWriter, null);
    501475                                }
    502476
  • src/org/openstreetmap/josm/plugins/ImportImagePlugin/LoadImageAction.java

     
    99import javax.swing.JFileChooser;
    1010import javax.swing.JOptionPane;
    1111
    12 import org.apache.log4j.Logger;
    1312import org.openstreetmap.josm.actions.JosmAction;
    1413import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    1514import org.openstreetmap.josm.gui.MainApplication;
    1615import org.openstreetmap.josm.plugins.ImportImagePlugin.ImageLayer.LayerCreationCanceledException;
    1716import org.openstreetmap.josm.spi.preferences.Config;
     17import org.openstreetmap.josm.tools.Logging;
    1818
    1919/**
    2020 * Class extends JosmAction and creates a new image layer.
     
    2424 */
    2525public class LoadImageAction extends JosmAction {
    2626
    27     private Logger logger = Logger.getLogger(LoadImageAction.class);
    28 
    2927    /**
    3028     * Constructor...
    3129     */
     
    4139        fc.setAcceptAllFileFilterUsed(false);
    4240        int result = fc.showOpenDialog(MainApplication.getMainFrame());
    4341
    44         ImageLayer layer = null;
     42        ImageLayer layer;
    4543        if (result == JFileChooser.APPROVE_OPTION) {
    4644            Config.getPref().put("plugins.importimage.importpath", fc.getCurrentDirectory().getAbsolutePath());
    47             logger.info("File chosen:" + fc.getSelectedFile());
     45            Logging.info("ImportImagePlugin LoadImageAction: File chosen: {0}", fc.getSelectedFile());
    4846            try {
    4947                layer = new ImageLayer(fc.getSelectedFile());
    5048            } catch (LayerCreationCanceledException e) {
     49                Logging.trace(e);
    5150                // if user decides that layer should not be created just return.
    5251                return;
    5352            } catch (Exception e) {
    54                 logger.error("Error while creating image layer: \n" + e.getMessage());
     53                Logging.error("ImportImagePlugin LoadImageAction: Error while creating image layer: \n{0}", e.getMessage());
    5554                JOptionPane.showMessageDialog(null, marktr("Error while creating image layer: " + e.getCause()));
    5655                return;
    5756            }
  • src/org/openstreetmap/josm/plugins/ImportImagePlugin/PluginOperations.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.ImportImagePlugin;
    33
    4 import java.awt.geom.Rectangle2D;
    5 import java.awt.image.BufferedImage;
    6 import java.io.BufferedReader;
    7 import java.io.File;
    8 import java.io.FileNotFoundException;
    9 import java.io.FileReader;
    10 import java.io.IOException;
    11 import java.util.Arrays;
    12 import java.util.Iterator;
    13 import java.util.Properties;
    14 import java.util.Set;
    15 import java.util.Vector;
    16 
    17 import javax.imageio.ImageIO;
    18 
    19 import org.apache.log4j.Logger;
    204import org.geotools.coverage.grid.GridCoverage2D;
    215import org.geotools.coverage.grid.GridCoverageFactory;
    226import org.geotools.coverage.processing.CoverageProcessor;
     
    2812import org.geotools.util.factory.Hints;
    2913import org.opengis.parameter.ParameterValueGroup;
    3014import org.opengis.referencing.FactoryException;
    31 import org.opengis.referencing.NoSuchAuthorityCodeException;
    3215import org.opengis.referencing.crs.CRSAuthorityFactory;
    3316import org.opengis.referencing.crs.CoordinateReferenceSystem;
    3417import org.opengis.util.InternationalString;
     18import org.openstreetmap.josm.tools.Logging;
    3519
     20import javax.imageio.ImageIO;
     21import java.awt.geom.Rectangle2D;
     22import java.awt.image.BufferedImage;
     23import java.io.BufferedReader;
     24import java.io.File;
     25import java.io.FileNotFoundException;
     26import java.io.IOException;
     27import java.nio.file.Files;
     28import java.util.Arrays;
     29import java.util.List;
     30import java.util.Properties;
     31import java.util.Set;
     32import java.util.Vector;
     33
    3634/**
    3735 * Class provides methods for resampling operations, IO and stores important data.
    3836 *
     
    4139 */
    4240public final class PluginOperations {
    4341
    44     private static final Logger logger = Logger.getLogger(PluginOperations.class);
    45 
    4642    // contains descriptions of all available CRS
    47     static Vector<String> crsDescriptions;
     43    static List<String> crsDescriptions;
    4844
    4945    // the standard native CRS of user images
    5046    static CoordinateReferenceSystem defaultSourceCRS;
     
    6763     * Reprojects a GridCoverage to a given CRS.
    6864     */
    6965    public static GridCoverage2D reprojectCoverage(GridCoverage2D coverage,
    70             CoordinateReferenceSystem targetCrs) throws NoSuchAuthorityCodeException, FactoryException {
     66            CoordinateReferenceSystem targetCrs) {
    7167
    7268        // TODO: add category for NO_DATA values in coverage (transparency in image)
    7369
    74         GridCoverage2D destination = null;
     70        GridCoverage2D destination;
    7571
    7672        CoverageProcessor processor = new CoverageProcessor();
    7773        ParameterValueGroup resampleParams = processor.getOperation("Resample").getParameters();
     
    8783    }
    8884
    8985    /**
    90      * Creates a org.geotools.coverage.grid.GridCoverage2D from a given file.
     86     * Creates a {@link GridCoverage2D} from a given file.
     87     * @param file The file to read from
     88     * @param refSys The reference system to use
     89     * @param failIfNoPrjFile {@code true} if we need to fail if no projection file is found
     90     * @throws IOException if the file could not be read
     91     * @return The 2d grid coverage of the file
    9192     */
    9293    public static GridCoverage2D createGridFromFile(File file, CoordinateReferenceSystem refSys, boolean failIfNoPrjFile) throws IOException {
    9394
    94         GridCoverage2D coverage = null;
     95        GridCoverage2D coverage;
    9596
    9697        if (!file.exists()) throw new FileNotFoundException("File not found.");
    9798
    98         String extension = null;
    99         String fileNameWithoutExt = null;
     99        String extension;
     100        String fileNameWithoutExt;
    100101        int dotPos = file.getAbsolutePath().lastIndexOf(".");
    101102        extension = file.getAbsolutePath().substring(dotPos);
    102103        fileNameWithoutExt = file.getAbsolutePath().substring(0, dotPos);
    103104
    104105        /*------- switch for file type -----------*/
    105         if (extension.equalsIgnoreCase(".tif") || extension.equalsIgnoreCase(".tiff")) {
     106        if (".tif".equalsIgnoreCase(extension) || ".tiff".equalsIgnoreCase(extension)) {
    106107
    107108            // try to read GeoTIFF:
    108109            try {
     
    110111                return coverage;
    111112            } catch (DataSourceException dse) {
    112113                if (!dse.getMessage().contains("Coordinate Reference System is not available")) {
    113                     dse.printStackTrace();
     114                    Logging.error(dse);
     115                } else {
     116                    Logging.trace(dse);
    114117                }
    115             } catch (FactoryException facte) {
    116                 logger.fatal("Error while reading from GeoTIFF:", facte);
    117                 throw new IOException(facte);
    118118            }
    119119
    120120            // file is no GeoTiff, searching for Worldfile and projection file:
     
    121121            String[] postfixes = {"wld", "tfw", "tifw"};
    122122            // try to read Worldfile:
    123123            WorldFileReader tfwReader = null;
    124             for (int i = 0; i < postfixes.length; i++) {
    125                 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]);
     124            for (String postfix : postfixes) {
     125                File prjFile = new File(fileNameWithoutExt + "." + postfix);
    126126                if (prjFile.exists()) {
    127127                    tfwReader = new WorldFileReader(prjFile);
    128128                }
     
    137137                refSys = readPrjFile(file);
    138138                if (refSys == null) {
    139139                    if (failIfNoPrjFile) throw new IOException("No projection file found.");
    140                     logger.debug("no projection given, no projection file found; using unprojected file.");
     140                    Logging.debug("no projection given, no projection file found; using unprojected file.");
    141141                }
    142142            }
    143143
     
    154154            Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height));
    155155            coverage = createGridCoverage(img, bbox, refSys);
    156156
    157         } else if (extension.equalsIgnoreCase(".jpg")
    158                 || extension.equalsIgnoreCase(".jpeg")) {
     157        } else if (".jpg".equalsIgnoreCase(extension)
     158                || ".jpeg".equalsIgnoreCase(extension)) {
    159159            String[] postfixes = {"wld", "jgw", "jpgw"};
    160160            // try to read Worldfile:
    161161            WorldFileReader tfwReader = null;
    162             for (int i = 0; i < postfixes.length; i++) {
    163                 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]);
     162            for (String postfix : postfixes) {
     163                File prjFile = new File(fileNameWithoutExt + "." + postfix);
    164164                if (prjFile.exists()) {
    165165                    tfwReader = new WorldFileReader(prjFile);
    166166                }
     
    172172                refSys = readPrjFile(file);
    173173                if (refSys == null) {
    174174                    if (failIfNoPrjFile) throw new IOException("No projection file found.");
    175                     logger.debug("no projection given, no projection file found; using unprojected file.");
     175                    Logging.debug("no projection given, no projection file found; using unprojected file.");
    176176                }
    177177            }
    178178
     
    186186            Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height));
    187187            coverage = createGridCoverage(img, bbox, refSys);
    188188
    189         } else if (extension.equalsIgnoreCase(".bmp")) {
     189        } else if (".bmp".equalsIgnoreCase(extension)) {
    190190            String[] postfixes = {"wld", "bmpw", "bpw"};
    191191            // try to read Worldfile:
    192192            WorldFileReader tfwReader = null;
    193             for (int i = 0; i < postfixes.length; i++) {
    194                 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]);
     193            for (String postfix : postfixes) {
     194                File prjFile = new File(fileNameWithoutExt + "." + postfix);
    195195                if (prjFile.exists()) {
    196196                    tfwReader = new WorldFileReader(prjFile);
    197197                }
     
    203203                refSys = readPrjFile(file);
    204204                if (refSys == null) {
    205205                    if (failIfNoPrjFile) throw new IOException("No projection file found.");
    206                     logger.debug("no projection given, no projection file found; using unprojected file.");
     206                    Logging.debug("no projection given, no projection file found; using unprojected file.");
    207207                }
    208208            }
    209209
     
    217217            Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height));
    218218            coverage = createGridCoverage(img, bbox, refSys);
    219219
    220         } else if (extension.equalsIgnoreCase(".png")) {
     220        } else if (".png".equalsIgnoreCase(extension)) {
    221221
    222222            String[] postfixes = {"wld", "pgw", "pngw"};
    223223            // try to read Worldfile:
    224224            WorldFileReader tfwReader = null;
    225             for (int i = 0; i < postfixes.length; i++) {
    226                 File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]);
     225            for (String postfix : postfixes) {
     226                File prjFile = new File(fileNameWithoutExt + "." + postfix);
    227227                if (prjFile.exists()) {
    228228                    tfwReader = new WorldFileReader(prjFile);
    229229                }
     
    235235                refSys = readPrjFile(file);
    236236                if (refSys == null) {
    237237                    if (failIfNoPrjFile) throw new IOException("No projection file found.");
    238                     logger.debug("no projection given, no projection file found; using unprojected file.");
     238                    Logging.debug("no projection given, no projection file found; using unprojected file.");
    239239                }
    240240            }
    241241
     
    264264     * @param file image file, not the real world file (will be searched)
    265265     */
    266266    public static CoordinateReferenceSystem readPrjFile(File file) throws IOException {
    267         CoordinateReferenceSystem refSys = null;
     267        CoordinateReferenceSystem refSys;
    268268
    269         String prjFilename = null;
     269        String prjFilename;
    270270        int dotPos = file.getAbsolutePath().lastIndexOf(".");
    271271        prjFilename = file.getAbsolutePath().substring(0, dotPos) + ".prj";
    272272
    273273        File prjFile = new File(prjFilename);
    274274        if (!prjFile.exists()) return null;
    275         logger.debug("Loading .prj file: " + prjFile.getAbsolutePath());
     275        Logging.debug("Loading .prj file: " + prjFile.getAbsolutePath());
    276276
    277         try (BufferedReader br = new BufferedReader(new FileReader(prjFile))) {
     277        try (BufferedReader br = Files.newBufferedReader(prjFile.toPath())) {
    278278            StringBuilder sb = new StringBuilder();
    279             String content = null;
     279            String content;
    280280            while ((content = br.readLine()) != null) {
    281281                sb.append(content);
    282282            }
    283283            refSys = CRS.parseWKT(sb.toString().trim());
    284284        } catch (FactoryException e) {
    285             throw new IOException("Unable to parse prj-file: '" + prjFile.getName() + "'");
     285            throw new IOException("Unable to parse prj-file: '" + prjFile.getName() + "'", e);
    286286        }
    287287
    288288        return refSys;
     
    301301     *
    302302     * @param refSys if delivered, the coverage will be forced to use this crs
    303303     */
    304     public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem refSys) throws IOException, FactoryException {
    305         GridCoverage2D coverage = null;
     304    public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem refSys) throws IOException {
     305        GridCoverage2D coverage;
    306306        Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true);
    307307        if (refSys != null) {
    308308            hints.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, refSys);
     
    327327        Set<String> supportedCodes = CRS.getSupportedCodes("EPSG");
    328328        CRSAuthorityFactory fac = CRS.getAuthorityFactory(false);
    329329
    330         for (Iterator<String> iterator = supportedCodes.iterator(); iterator.hasNext();) {
    331             String string = iterator.next();
     330        for (String string : supportedCodes) {
    332331            try {
    333332                if ("WGS84(DD)".equals(string)) {
    334333                    continue;
     
    337336                String description = desc.toString() + " [-EPSG:" + string + "-]";
    338337                crsDescriptions.add(description);
    339338                if (defaultcrsString != null && defaultcrsString.equalsIgnoreCase("EPSG:" + string)) {
    340                     boolean isEastingFirst = Boolean.valueOf(pluginProps.getProperty("default_crs_eastingfirst"));
     339                    boolean isEastingFirst = Boolean.parseBoolean(pluginProps.getProperty("default_crs_eastingfirst"));
    341340                    defaultSourceCRS = CRS.decode("EPSG:" + string, isEastingFirst);
    342341                    defaultSourceCRSDescription = description;
    343342                }
    344343
    345344            } catch (FactoryException e) {
    346                 logger.error("Error while loading EPSG data: " + e.getMessage());
     345                Logging.error("Error while loading EPSG data: " + e.getMessage());
     346                Logging.error(e);
    347347            }
    348348        }
    349349    }
  • test/unit/org/openstreetmap/josm/plugins/ImportImagePlugin/GeoTiffReaderTest.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.ImportImagePlugin;
    33
    4 import static org.junit.Assert.assertNotNull;
    5 
    64import java.io.File;
    75import java.io.IOException;
    86import java.nio.file.DirectoryIteratorException;
     
    1412import java.util.Collection;
    1513
    1614import org.geotools.coverage.grid.GridCoverage2D;
    17 import org.junit.Rule;
    18 import org.junit.Test;
     15import org.junit.jupiter.api.Test;
     16import org.junit.jupiter.api.Timeout;
    1917import org.openstreetmap.josm.TestUtils;
    20 import org.openstreetmap.josm.testutils.JOSMTestRules;
     18import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    2119import org.openstreetmap.josm.tools.Logging;
    2220
     21import static org.junit.jupiter.api.Assertions.assertNotNull;
     22
    2323/**
    2424 * Test that some geotiff sample files can be read.
    2525 * Data downloaded from <a href="ftp://ftp.remotesensing.org/pub/geotiff/samples">remotesensing.org</a>.
    2626 */
    27 public class GeoTiffReaderTest {
    28 
    29     /**
    30      * Setup test.
    31      */
    32     @Rule
    33     public JOSMTestRules rules = new JOSMTestRules().preferences().timeout(20000);
    34 
     27@BasicPreferences
     28@Timeout(20)
     29class GeoTiffReaderTest {
    3530    @Test
    36     public void testReadGeoTiffFiles() throws IOException {
     31    void testReadGeoTiffFiles() throws IOException {
    3732        for (Path p : listDataFiles("tif")) {
    3833            File file = p.toFile();
    3934            Logging.info("Testing reading file "+file.getPath());
     
    4540    /**
    4641     * Lists all datasets files matching given extension.
    4742     * @param ext file extension to search for
    48      * @returns List of all datasets files matching given extension
     43     * @return List of all datasets files matching given extension
    4944     * @throws IOException in case of I/O error
    5045     */
    5146    public static Collection<Path> listDataFiles(String ext) throws IOException {
  • test/unit/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayerTest.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.ImportImagePlugin;
    33
    4 import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertTrue;
    6 
    74import java.io.File;
    85import java.io.InputStream;
    96
    10 import org.junit.Rule;
    11 import org.junit.Test;
     7import org.junit.jupiter.api.Test;
     8import org.junit.jupiter.api.extension.RegisterExtension;
    129import org.openstreetmap.josm.TestUtils;
    1310import org.openstreetmap.josm.gui.MainApplication;
    1411import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1512import org.openstreetmap.josm.io.OsmReader;
    1613import org.openstreetmap.josm.testutils.JOSMTestRules;
     14import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    1715
     16import static org.junit.jupiter.api.Assertions.assertEquals;
     17import static org.junit.jupiter.api.Assertions.assertTrue;
     18
    1819/**
    1920 * Test that some geotiff sample files can be read.
    2021 * Data downloaded from <a href="ftp://ftp.remotesensing.org/pub/geotiff/samples">remotesensing.org</a>.
    2122 */
    22 public class ImageLayerTest {
     23@BasicPreferences
     24class ImageLayerTest {
    2325
    2426    /**
    2527     * Setup test.
    2628     */
    27     @Rule
    28     public JOSMTestRules rules = new JOSMTestRules().preferences().projection();
     29    @RegisterExtension
     30    static JOSMTestRules rules = new JOSMTestRules().projection();
    2931
    3032    /**
    3133     * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/14894">#14894</a>
     
    3234     * @throws Exception if an error occurs during reading
    3335     */
    3436    @Test
    35     public void testTicket14894() throws Exception {
     37    void testTicket14894() throws Exception {
    3638        assertTrue(MainApplication.getLayerManager().getLayers().isEmpty());
    3739        // Step 1: add .osm layer
    3840        try (InputStream in = TestUtils.getRegressionDataStream(14894, "14894.osm")) {