Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#12983 closed enhancement (fixed)

use layer manager in Command — at Version 7

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();
    }

Change History (7)

comment:1 by bastiK, 10 years ago

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

comment:2 by Don-vip, 10 years ago

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

comment:3 by Don-vip, 10 years ago

Cc: michael2402 added
Keywords: gsoc-core added

comment:4 by michael2402, 10 years ago

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 by Don-vip, 10 years ago

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 by Don-vip, 10 years ago

Milestone: 16.06
Type: defectenhancement

comment:7 by Don-vip, 10 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.