Changeset 9841 in josm


Ignore:
Timestamp:
2016-02-20T01:34:07+01:00 (8 years ago)
Author:
Don-vip
Message:

add unit test

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/UploadStrategySelectionPanel.java

    r9575 r9841  
    240240
    241241    public void setUploadStrategySpecification(UploadStrategySpecification strategy) {
    242         if (strategy == null) return;
     242        if (strategy == null)
     243            return;
    243244        rbStrategy.get(strategy.getStrategy()).setSelected(true);
    244245        tfChunkSize.setEnabled(strategy.getStrategy() == UploadStrategy.CHUNKED_DATASET_STRATEGY);
     
    256257        int chunkSize = getChunkSize();
    257258        UploadStrategySpecification spec = new UploadStrategySpecification();
    258         switch(strategy) {
    259         case INDIVIDUAL_OBJECTS_STRATEGY:
    260         case SINGLE_REQUEST_STRATEGY:
    261             spec.setStrategy(strategy);
    262             break;
    263         case CHUNKED_DATASET_STRATEGY:
    264             spec.setStrategy(strategy).setChunkSize(chunkSize);
    265             break;
     259        if (strategy != null) {
     260            switch(strategy) {
     261            case INDIVIDUAL_OBJECTS_STRATEGY:
     262            case SINGLE_REQUEST_STRATEGY:
     263                spec.setStrategy(strategy);
     264                break;
     265            case CHUNKED_DATASET_STRATEGY:
     266                spec.setStrategy(strategy).setChunkSize(chunkSize);
     267                break;
     268            }
    266269        }
    267270        if (pnlMultiChangesetPolicyPanel.isVisible()) {
  • trunk/src/org/openstreetmap/josm/gui/io/UploadStrategySpecification.java

    r9371 r9841  
    3535
    3636    /**
    37      * Clones another upload strategy. If other is null,assumes default
    38      * values.
     37     * Clones another upload strategy. If other is null, assumes default values.
    3938     *
    4039     * @param other the other upload strategy
    4140     */
    4241    public UploadStrategySpecification(UploadStrategySpecification other) {
    43         if (other == null) return;
    44         this.strategy = other.strategy;
    45         this.chunkSize = other.chunkSize;
    46         this.policy = other.policy;
    47         this.closeChangesetAfterUpload = other.closeChangesetAfterUpload;
     42        if (other != null) {
     43            this.strategy = other.strategy;
     44            this.chunkSize = other.chunkSize;
     45            this.policy = other.policy;
     46            this.closeChangesetAfterUpload = other.closeChangesetAfterUpload;
     47        }
    4848    }
    4949
     
    9393
    9494    public int getNumRequests(int numObjects) {
    95         if (numObjects <= 0) return 0;
     95        if (numObjects <= 0)
     96            return 0;
    9697        switch(strategy) {
    9798        case INDIVIDUAL_OBJECTS_STRATEGY: return numObjects;
     
    114115    @Override
    115116    public boolean equals(Object obj) {
    116         if (this == obj) return true;
    117         if (obj == null || getClass() != obj.getClass()) return false;
     117        if (this == obj)
     118            return true;
     119        if (obj == null || getClass() != obj.getClass())
     120            return false;
    118121        UploadStrategySpecification that = (UploadStrategySpecification) obj;
    119122        return chunkSize == that.chunkSize &&
  • trunk/test/unit/org/openstreetmap/josm/gui/io/UploadStrategySelectionPanelTest.java

    r9669 r9841  
    22package org.openstreetmap.josm.gui.io;
    33
    4 import static org.junit.Assert.assertNotNull;
     4import static org.junit.Assert.assertEquals;
    55
    66import org.junit.BeforeClass;
    77import org.junit.Test;
    88import org.openstreetmap.josm.JOSMFixture;
     9import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.io.OsmApi;
     11import org.openstreetmap.josm.io.OsmApiInitializationException;
     12import org.openstreetmap.josm.io.OsmTransferCanceledException;
    913
    1014/**
     
    1923    public static void setUpBeforeClass() {
    2024        JOSMFixture.createUnitTestFixture().init();
     25        try {
     26            OsmApi.getOsmApi().initialize(null);
     27        } catch (OsmTransferCanceledException | OsmApiInitializationException e) {
     28            Main.error(e);
     29        }
    2130    }
    2231
     
    2635    @Test
    2736    public void testUploadStrategySelectionPanel() {
    28         assertNotNull(new UploadStrategySelectionPanel());
     37        UploadStrategySelectionPanel p = new UploadStrategySelectionPanel();
     38        p.setNumUploadedObjects(Integer.MAX_VALUE);
     39        p.rememberUserInput();
     40        p.initFromPreferences();
     41        p.initEditingOfChunkSize();
     42    }
     43
     44    /**
     45     * Test of {@link UploadStrategySelectionPanel#setUploadStrategySpecification}
     46     *       / {@link UploadStrategySelectionPanel#getUploadStrategySpecification}.
     47     */
     48    @Test
     49    public void testUploadStrategySpecification() {
     50        UploadStrategySelectionPanel p = new UploadStrategySelectionPanel();
     51
     52        UploadStrategySpecification def = new UploadStrategySpecification();
     53        assertEquals(def, p.getUploadStrategySpecification());
     54        p.setUploadStrategySpecification(null);
     55        assertEquals(def, p.getUploadStrategySpecification());
     56
     57        UploadStrategySpecification strat = new UploadStrategySpecification().setStrategy(UploadStrategy.INDIVIDUAL_OBJECTS_STRATEGY);
     58        p.setUploadStrategySpecification(strat);
     59        assertEquals(strat, p.getUploadStrategySpecification());
    2960    }
    3061}
Note: See TracChangeset for help on using the changeset viewer.