Changeset 9829 in josm


Ignore:
Timestamp:
2016-02-19T02:34:18+01:00 (9 years ago)
Author:
Don-vip
Message:

fix warnings, add unit test

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r9827 r9829  
    14181418     */
    14191419    public String toXML(Collection<Entry<String, Setting<?>>> settings, boolean nopass, boolean defaults) {
    1420         StringWriter sw = new StringWriter();
    1421         PrintWriter pw = new PrintWriter(sw);
    1422         PreferencesWriter prefWriter = new PreferencesWriter(pw, nopass, defaults);
    1423         prefWriter.write(settings);
    1424         sw.flush();
    1425         StringBuffer sb = sw.getBuffer();
    1426         return sb.toString();
     1420        try (
     1421            StringWriter sw = new StringWriter();
     1422            PreferencesWriter prefWriter = new PreferencesWriter(new PrintWriter(sw), nopass, defaults);
     1423        ) {
     1424            prefWriter.write(settings);
     1425            sw.flush();
     1426            return sw.toString();
     1427        } catch (IOException e) {
     1428            Main.error(e);
     1429            return null;
     1430        }
    14271431    }
    14281432
  • trunk/test/unit/org/openstreetmap/josm/data/PreferencesTest.groovy

    r7938 r9829  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.data
    23
     
    2728        assert Main.pref.getDefaultColor("foo").alpha == 0x12
    2829    }
     30
     31    void testToXml() {
     32        assert Main.pref.toXML(true) == String.format(
     33            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n" +
     34            "<preferences xmlns='http://josm.openstreetmap.de/preferences-1.0' version='%d'>%n" +
     35            "  <tag key='expert' value='true'/>%n" +
     36            "  <tag key='jdk.Arrays.useLegacyMergeSort' value='false'/>%n" +
     37            "  <tag key='language' value='en'/>%n" +
     38            "  <tag key='osm-server.url' value='http://api06.dev.openstreetmap.org/api'/>%n" +
     39            "  <tag key='osm-server.username' value='josm_test'/>%n" +
     40            "</preferences>%n", Version.getInstance().getVersion())
     41    }
    2942}
Note: See TracChangeset for help on using the changeset viewer.