Changeset 11974 in josm


Ignore:
Timestamp:
2017-04-22T17:57:11+02:00 (7 years ago)
Author:
Don-vip
Message:

add unit tests, javadoc

Location:
trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r11946 r11974  
    144144    }
    145145
     146    static final class PluginInformationAction extends AbstractAction {
     147        private final PluginInformation info;
     148
     149        PluginInformationAction(PluginInformation info) {
     150            super(tr("Information"));
     151            this.info = info;
     152        }
     153
     154        /**
     155         * Returns plugin information text.
     156         * @return plugin information text
     157         */
     158        public String getText() {
     159            StringBuilder b = new StringBuilder();
     160            for (Entry<String, String> e : info.attr.entrySet()) {
     161                b.append(e.getKey());
     162                b.append(": ");
     163                b.append(e.getValue());
     164                b.append('\n');
     165            }
     166            return b.toString();
     167        }
     168
     169        @Override
     170        public void actionPerformed(ActionEvent event) {
     171            String text = getText();
     172            JosmTextArea a = new JosmTextArea(10, 40);
     173            a.setEditable(false);
     174            a.setText(text);
     175            a.setCaretPosition(0);
     176            if (!GraphicsEnvironment.isHeadless()) {
     177                JOptionPane.showMessageDialog(Main.parent, new JScrollPane(a), tr("Plugin information"),
     178                        JOptionPane.INFORMATION_MESSAGE);
     179            }
     180        }
     181    }
     182
    146183    /**
    147184     * Description of a deprecated plugin
     
    14081445            pluginTab.add(new JLabel(name), GBC.std());
    14091446            pluginTab.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
    1410             pluginTab.add(new JButton(new AbstractAction(tr("Information")) {
    1411                 @Override
    1412                 public void actionPerformed(ActionEvent event) {
    1413                     StringBuilder b = new StringBuilder();
    1414                     for (Entry<String, String> e : info.attr.entrySet()) {
    1415                         b.append(e.getKey());
    1416                         b.append(": ");
    1417                         b.append(e.getValue());
    1418                         b.append('\n');
    1419                     }
    1420                     JosmTextArea a = new JosmTextArea(10, 40);
    1421                     a.setEditable(false);
    1422                     a.setText(b.toString());
    1423                     a.setCaretPosition(0);
    1424                     JOptionPane.showMessageDialog(Main.parent, new JScrollPane(a), tr("Plugin information"),
    1425                             JOptionPane.INFORMATION_MESSAGE);
    1426                 }
    1427             }), GBC.eol());
     1447            pluginTab.add(new JButton(new PluginInformationAction(info)), GBC.eol());
    14281448
    14291449            JosmTextArea description = new JosmTextArea(info.description == null ? tr("no description available")
  • trunk/src/org/openstreetmap/josm/tools/template_engine/ContextSwitchTemplate.java

    r11809 r11974  
    2121import org.openstreetmap.josm.data.osm.Way;
    2222
     23/**
     24 * The context switch offers possibility to use tags of referenced primitive when constructing primitive name.
     25 * @author jttt
     26 * @since 4546
     27 */
    2328public class ContextSwitchTemplate implements TemplateEntry {
    2429
     
    244249    }
    245250
     251    /**
     252     * Constructs a new {@code ContextSwitchTemplate}.
     253     * @param match match
     254     * @param template template
     255     * @param searchExpressionPosition search expression position
     256     * @throws ParseError if a parse error occurs, or if the match transformation returns the same primitive
     257     */
    246258    public ContextSwitchTemplate(Match match, TemplateEntry template, int searchExpressionPosition) throws ParseError {
    247259        Match m = transform(match, searchExpressionPosition);
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferenceTest.java

    r10378 r11974  
    1717import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1818import org.openstreetmap.josm.plugins.PluginDownloadTask;
     19import org.openstreetmap.josm.plugins.PluginException;
    1920import org.openstreetmap.josm.plugins.PluginInformation;
    2021
     
    4142
    4243    /**
     44     * Returns a dummy plugin information.
     45     * @return a dummy plugin information
     46     * @throws PluginException if an error occurs
     47     */
     48    public static PluginInformation getDummyPluginInformation() throws PluginException {
     49        return new PluginInformation(
     50                new File(TestUtils.getTestDataRoot() + "plugin/dummy_plugin.jar"), "dummy_plugin");
     51    }
     52
     53    /**
    4354     * Unit test of {@link PluginPreference#buildDownloadSummary}.
    4455     * @throws Exception if an error occurs
     
    4657    @Test
    4758    public void testBuildDownloadSummary() throws Exception {
    48         final PluginInformation dummy = new PluginInformation(
    49                 new File(TestUtils.getTestDataRoot() + "plugin/dummy_plugin.jar"), "dummy_plugin");
     59        final PluginInformation dummy = getDummyPluginInformation();
    5060        assertEquals("", PluginPreference.buildDownloadSummary(
    5161                new PluginDownloadTask(NullProgressMonitor.INSTANCE, Collections.<PluginInformation>emptyList(), "")));
  • trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTest.java

    r10758 r11974  
    1515import org.openstreetmap.josm.JOSMFixture;
    1616import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.gui.preferences.plugin.PluginPreferenceTest;
    1718import org.openstreetmap.josm.plugins.PluginHandler.DeprecatedPlugin;
     19import org.openstreetmap.josm.plugins.PluginHandler.PluginInformationAction;
    1820import org.openstreetmap.josm.tools.Utils;
    1921
     
    8486        assertFalse(plugins.contains("gpsbabelgui"));
    8587    }
     88
     89    /**
     90     * Unit test of {@link PluginInformationAction} class.
     91     * @throws PluginException if an error occurs
     92     */
     93    @Test
     94    public void testPluginInformationAction() throws PluginException {
     95        PluginInformationAction action = new PluginInformationAction(PluginPreferenceTest.getDummyPluginInformation());
     96        assertEquals(
     97                "Ant-Version: Apache Ant 1.9.6\n" +
     98                "Author: Don-vip\n" +
     99                "Created-By: 1.7.0_91-b02 (Oracle Corporation)\n" +
     100                "Manifest-Version: 1.0\n" +
     101                "Plugin-Canloadatruntime: true\n" +
     102                "Plugin-Class: org.openstreetmap.josm.plugins.fr.epci.EpciPlugin\n" +
     103                "Plugin-Date: 2015-11-19T08:21:07.645033Z\n" +
     104                "Plugin-Description: Handling of French EPCIs (boundary=local_authority)\n" +
     105                "Plugin-Early: true\n" +
     106                "Plugin-Link: http://wiki.openstreetmap.org/wiki/FR:JOSM/Fr:Plugin/EPCI-fr\n" +
     107                "Plugin-Mainversion: 7001\n" +
     108                "Plugin-Version: 31772\n", action.getText());
     109        action.actionPerformed(null);
     110    }
    86111}
  • trunk/test/unit/org/openstreetmap/josm/tools/template_engine/TemplateParserTest.java

    r11057 r11974  
    237237
    238238    @Test
     239    public void testSetAnd() throws ParseError {
     240        TemplateParser parser = new TemplateParser("!{(parent(type=child) type=parent) & (parent type=child subtype=parent) '{name}'}");
     241        DatasetFactory ds = new DatasetFactory();
     242        Relation parent1 = ds.addRelation(1);
     243        parent1.put("type", "parent");
     244        parent1.put("subtype", "parent");
     245        parent1.put("name", "name_parent1");
     246        Node child = ds.addNode(1);
     247        child.put("type", "child");
     248        parent1.addMember(new RelationMember("", child));
     249
     250        StringBuilder sb = new StringBuilder();
     251        TemplateEntry entry = parser.parse();
     252        entry.appendText(sb, child);
     253
     254        Assert.assertEquals("name_parent1", sb.toString());
     255    }
     256
     257    @Test
    239258    public void testSetOr() throws ParseError {
    240259        TemplateParser parser = new TemplateParser("!{(parent(type=type1) type=parent1) | (parent type=type2 type=parent2) '{name}'}");
Note: See TracChangeset for help on using the changeset viewer.