Modify

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#12983 closed enhancement (fixed)

use layer manager in Command

Reported by: anonymous Owned by: team
Priority: normal Milestone: 16.06
Component: Core Version: latest
Keywords: gsoc-core Cc: michael2402

Description (last modified by Don-vip)

The Command class should get the active layer from the layer manager. otherwise it does not seem possible to use the command in a test with JOSMTestRules, because "Main.main" is null.

package org.openstreetmap.josm.command:

    /**
     * Creates a new command in the context of the current edit layer, if any
     */
    public Command() {
        this.layer = Main.main == null ? null : Main.main.getEditLayer();
    }

Attachments (0)

Change History (7)

comment:1 Changed 3 years ago by bastiK

Could you give a bit more context, what is JOSMTestRules?

comment:2 Changed 3 years ago by Don-vip

new class in unit tests to speed up/replace JOSMFixtures (part of Michael's work)

comment:3 Changed 3 years ago by Don-vip

Cc: michael2402 added
Keywords: gsoc-core added

comment:4 Changed 3 years ago by michael2402

JOSMTestRules sets up the test environment more fine-graned than JOSMFixture does.

The main Idea is that you do not need a whole JOSM instance to get a simple unit test running. This is only possible if we reduce dependencies, e.g. that Command depends on Main.

I would like to deprecate all Main.*Layer*() methods except for getLayerManager() and replace them in the existing source.

You can replace this line:

this.layer = Main.main == null ? null : Main.main.getEditLayer();

With this one:

this.layer = Main.getLayerManager().getEditLayer();

The MainLayerManager will handle the case of an empty layer list automatically.

comment:5 Changed 3 years ago by Don-vip

Resolution: fixed
Status: newclosed

In 10413/josm:

fix #12983 - replace calls to Main.main.get[Active|Edit]Layer() by Main.getLayerManager().get[Active|Edit]Layer() - gsoc-core

comment:6 Changed 3 years ago by Don-vip

Milestone: 16.06
Type: defectenhancement

comment:7 Changed 3 years ago by Don-vip

Description: modified (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.