Changeset 7030 in josm for trunk/test/functional/org


Ignore:
Timestamp:
2014-04-29T18:06:29+02:00 (11 years ago)
Author:
Don-vip
Message:

see #8465 - use of try-with-resource

Location:
trunk/test/functional/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/functional/org/openstreetmap/josm/gui/history/HistoryBrowserTest.java

    r7025 r7030  
    3838        // load properties
    3939        //
    40         try {
    41             InputStream is = HistoryBrowserTest.class.getResourceAsStream("/test-functional-env.properties");
    42             try {
    43                 testProperties.load(is);
    44             } finally {
    45                 is.close();
    46             }
     40        try (InputStream is = HistoryBrowserTest.class.getResourceAsStream("/test-functional-env.properties");) {
     41            testProperties.load(is);
    4742        } catch(IOException e){
    4843            logger.log(Level.SEVERE, MessageFormat.format("failed to load property file ''{0}''", "test-functional-env.properties"));
  • trunk/test/functional/org/openstreetmap/josm/io/MultiFetchServerObjectReaderTest.java

    r7025 r7030  
    134134
    135135    @BeforeClass
    136     public static void  init() throws OsmTransferException {
     136    public static void init() throws OsmTransferException {
    137137        logger.info("initializing ...");
    138138        testProperties = new Properties();
     
    140140        // load properties
    141141        //
    142         try {
    143             InputStream is = MultiFetchServerObjectReaderTest.class.getResourceAsStream("/test-functional-env.properties");
    144             try {
    145                 testProperties.load(is);
    146             } finally {
    147                 is.close();
    148             }
     142        try (InputStream is = MultiFetchServerObjectReaderTest.class.getResourceAsStream("/test-functional-env.properties")) {
     143            testProperties.load(is);
    149144        } catch(IOException e){
    150145            logger.log(Level.SEVERE, MessageFormat.format("failed to load property file ''{0}''", "test-functional-env.properties"));
     
    211206        createDataSetOnServer(testDataSet);
    212207
    213         try {
     208        try (
    214209            PrintWriter pw = new PrintWriter(
    215210                    new OutputStreamWriter(new FileOutputStream(dataSetCacheOutputFile), Utils.UTF_8)
    216             );
     211        )) {
    217212            logger.info(MessageFormat.format("caching test data set in ''{0}'' ...", dataSetCacheOutputFile.toString()));
    218             OsmWriter w = new OsmWriter(pw, false, testDataSet.getVersion());
    219             w.header();
    220             w.writeDataSources(testDataSet);
    221             w.writeContent(testDataSet);
    222             w.footer();
    223             w.close();
    224             pw.close();
     213            try (OsmWriter w = new OsmWriter(pw, false, testDataSet.getVersion())) {
     214                w.header();
     215                w.writeDataSources(testDataSet);
     216                w.writeContent(testDataSet);
     217                w.footer();
     218            }
    225219        } catch(IOException e) {
    226220            fail(MessageFormat.format("failed to open file ''{0}'' for writing", dataSetCacheOutputFile.toString()));
     
    238232        logger.info(MessageFormat.format("reading cached dataset ''{0}''", f.toString()));
    239233        ds = new DataSet();
    240         FileInputStream fis = new FileInputStream(f);
    241         ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
    242         fis.close();
     234        try (FileInputStream fis = new FileInputStream(f)) {
     235            ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     236        }
    243237    }
    244238
  • trunk/test/functional/org/openstreetmap/josm/io/OsmServerBackreferenceReaderTest.java

    r7025 r7030  
    147147        // load properties
    148148        //
    149         try {
    150             InputStream is = MultiFetchServerObjectReaderTest.class.getResourceAsStream("/test-functional-env.properties");
    151             try {
    152                 testProperties.load(is);
    153             } finally {
    154                 is.close();
    155             }
     149        try (InputStream is = MultiFetchServerObjectReaderTest.class.getResourceAsStream("/test-functional-env.properties")) {
     150            testProperties.load(is);
    156151        } catch(IOException e){
    157152            logger.log(Level.SEVERE, MessageFormat.format("failed to load property file ''{0}''", "test-functional-env.properties"));
     
    218213        createDataSetOnServer(testDataSet);
    219214
    220         try {
     215        try (
    221216            PrintWriter pw = new PrintWriter(
    222217                    new OutputStreamWriter(new FileOutputStream(dataSetCacheOutputFile), Utils.UTF_8)
    223             );
     218        )) {
    224219            logger.info(MessageFormat.format("caching test data set in ''{0}'' ...", dataSetCacheOutputFile.toString()));
    225             OsmWriter w = new OsmWriter(pw, false, testDataSet.getVersion());
    226             w.header();
    227             w.writeDataSources(testDataSet);
    228             w.writeContent(testDataSet);
    229             w.footer();
    230             w.close();
    231             pw.close();
     220            try (OsmWriter w = new OsmWriter(pw, false, testDataSet.getVersion())) {
     221                w.header();
     222                w.writeDataSources(testDataSet);
     223                w.writeContent(testDataSet);
     224                w.footer();
     225            }
    232226        } catch(IOException e) {
    233227            fail(MessageFormat.format("failed to open file ''{0}'' for writing", dataSetCacheOutputFile.toString()));
     
    245239        logger.info(MessageFormat.format("reading cached dataset ''{0}''", f.toString()));
    246240        ds = new DataSet();
    247         FileInputStream fis = new FileInputStream(f);
    248         ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
    249         fis.close();
     241        try (FileInputStream fis = new FileInputStream(f)) {
     242            ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE);
     243        }
    250244    }
    251245
Note: See TracChangeset for help on using the changeset viewer.