Changeset 8959 in josm


Ignore:
Timestamp:
2015-10-27T20:02:56+01:00 (8 years ago)
Author:
Don-vip
Message:

improve unit test detecting invalid presets

Location:
trunk
Files:
3 edited

Legend:

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

    r8870 r8959  
    265265
    266266    /**
     267     * Clears the list of last error and warning messages.
     268     * @since 8959
     269     */
     270    public static void clearLastErrorAndWarnings() {
     271        ERRORS_AND_WARNINGS.clear();
     272    }
     273
     274    /**
    267275     * Prints an error message if logging is on.
    268276     * @param msg The message to print.
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r8958 r8959  
    196196                    });
    197197                } else {
    198                     Main.warn(PRESET_ICON_ERROR_MSG_PREFIX + iconName);
     198                    Main.warn(TaggingPreset.this + ": " + PRESET_ICON_ERROR_MSG_PREFIX + iconName);
    199199                }
    200200            }
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreferenceTest.java

    r8954 r8959  
    44import static org.junit.Assert.assertFalse;
    55import static org.junit.Assert.assertTrue;
    6 import static org.junit.Assert.fail;
    76
    87import java.io.IOException;
     
    4746            System.out.println(source.url);
    4847            try {
    49                 Collection<TaggingPreset> presets = TaggingPresetReader.readAll(source.url, true);
    50                 assertFalse(presets.isEmpty());
    51                 System.out.println(" => OK");
    52                 allMessages.addAll(Main.getLastErrorAndWarnings());
    53             } catch (SAXException | IOException e) {
     48                testPresets(allMessages, source);
     49            } catch (IOException e) {
     50                try {
     51                    Main.warn(e);
     52                    // try again in case of temporary network error
     53                    testPresets(allMessages, source);
     54                } catch (SAXException | IOException e1) {
     55                    e.printStackTrace();
     56                    allErrors.add(e1);
     57                    System.out.println(" => KO");
     58                }
     59            } catch (SAXException e) {
    5460                e.printStackTrace();
    5561                allErrors.add(e);
     
    5864        }
    5965        assertTrue(allErrors.isEmpty());
    60         for (String message : allMessages) {
     66        assertTrue(allMessages.isEmpty());
     67    }
     68
     69    private static void testPresets(Set<String> allMessages, ExtendedSourceEntry source) throws SAXException, IOException {
     70        Collection<TaggingPreset> presets = TaggingPresetReader.readAll(source.url, true);
     71        assertFalse(presets.isEmpty());
     72        Collection<String> errorsAndWarnings = Main.getLastErrorAndWarnings();
     73        boolean error = false;
     74        for (String message : errorsAndWarnings) {
    6175            if (message.contains(TaggingPreset.PRESET_ICON_ERROR_MSG_PREFIX)) {
    62                 fail(message);
     76                error = true;
     77                allMessages.add(message);
    6378            }
     79        }
     80        System.out.println(error ? " => KO" : " => OK");
     81        if (error) {
     82            Main.clearLastErrorAndWarnings();
    6483        }
    6584    }
Note: See TracChangeset for help on using the changeset viewer.